Goods and services expense (% of expense)

Source: worldbank.org, 03.09.2025

Year: 2023

Flag Country Value Value change, % Rank
Albania Albania 8.74 +6.33% 60
United Arab Emirates United Arab Emirates 28.9 -14% 7
Argentina Argentina 3.74 +4.72% 83
Armenia Armenia 10 -16.5% 51
Austria Austria 6.63 -0.575% 75
Burkina Faso Burkina Faso 9.69 +0.667% 53
Bulgaria Bulgaria 8.08 -0.601% 63
Bahamas Bahamas 21.6 +5.02% 18
Bosnia & Herzegovina Bosnia & Herzegovina 17 -1.67% 29
Belarus Belarus 13.9 +4.56% 40
Brazil Brazil 2.41 +13% 86
Botswana Botswana 22.4 0% 14
Canada Canada 6.78 -13% 72
Switzerland Switzerland 6.96 +0.554% 71
Chile Chile 7.88 -3.5% 67
Côte d’Ivoire Côte d’Ivoire 16.2 -8.62% 32
Colombia Colombia 8.04 -4.33% 65
Costa Rica Costa Rica 20.8 -4.92% 22
Cyprus Cyprus 8.73 -12.8% 61
Denmark Denmark 7.96 +1.14% 66
Dominican Republic Dominican Republic 18.3 +8.44% 26
Spain Spain 2.86 +11.5% 85
Estonia Estonia 9.29 -2.84% 57
Ethiopia Ethiopia 20.9 +6.25% 21
Finland Finland 7.76 -11.1% 68
Fiji Fiji 17.4 +5.81% 28
France France 6.74 +5.68% 73
United Kingdom United Kingdom 13.7 -4.57% 41
Georgia Georgia 14 +2.68% 39
Guinea-Bissau Guinea-Bissau 32.4 +18.6% 4
Greece Greece 8.07 +2.61% 64
Guatemala Guatemala 14 -12.8% 38
Croatia Croatia 10.6 -3.97% 50
Iceland Iceland 21.5 +4.11% 19
Israel Israel 13.1 -0.544% 43
Italy Italy 2.9 -0.842% 84
Jordan Jordan 9.79 -21.1% 52
Kazakhstan Kazakhstan 16.1 +1.7% 33
Kenya Kenya 21.3 +4.47% 20
Kyrgyzstan Kyrgyzstan 11.5 -2.06% 47
Cambodia Cambodia 15 -5.96% 36
Kiribati Kiribati 29.4 +9.53% 6
South Korea South Korea 12.5 +14.8% 45
Sri Lanka Sri Lanka 6.03 +26.1% 79
Lithuania Lithuania 6.41 -6.93% 77
Luxembourg Luxembourg 7.43 -6.18% 70
Latvia Latvia 10.6 -12.6% 49
Macao SAR China Macao SAR China 18 -16.5% 27
Morocco Morocco 8.97 -11.1% 58
Moldova Moldova 15.9 -1.16% 34
Madagascar Madagascar 6.56 -7.08% 76
Mexico Mexico 5.92 -10.1% 80
North Macedonia North Macedonia 5.77 -13.5% 81
Malta Malta 19.3 +3.2% 25
Mauritius Mauritius 9.56 -3.66% 54
Malaysia Malaysia 11.6 +7.14% 46
Namibia Namibia 12.6 +4.3% 44
Nicaragua Nicaragua 17 +5.39% 30
Netherlands Netherlands 6.72 +9.07% 74
Norway Norway 9.34 -0.738% 56
Philippines Philippines 22.3 +4.1% 15
Papua New Guinea Papua New Guinea 23.1 -17.2% 12
Poland Poland 7.44 -5.09% 69
Portugal Portugal 8.79 -3.73% 59
Paraguay Paraguay 15 +6.57% 37
Rwanda Rwanda 27.8 +5.17% 9
Saudi Arabia Saudi Arabia 27.4 +8.42% 10
Senegal Senegal 21.9 -0.00352% 16
Singapore Singapore 27.9 -13% 8
El Salvador El Salvador 15.6 -4.41% 35
San Marino San Marino 22.9 -27.8% 13
Somalia Somalia 19.9 +17% 23
Slovenia Slovenia 10.7 -0.17% 48
Togo Togo 16.7 -18.8% 31
Thailand Thailand 19.4 -15.7% 24
Tajikistan Tajikistan 21.7 +21% 17
Tonga Tonga 46.5 +6.11% 1
Turkey Turkey 8.59 -8.81% 62
Tanzania Tanzania 13.4 +9.48% 42
Uganda Uganda 25.6 -16.6% 11
Ukraine Ukraine 35.7 +44% 3
Uruguay Uruguay 9.47 -12.5% 55
United States United States 6.23 -7.92% 78
Uzbekistan Uzbekistan 4.95 -11.1% 82
Vanuatu Vanuatu 29.8 +1.66% 5
Samoa Samoa 44.8 +3.71% 2

                    
# Install missing packages
import sys
import subprocess

def install(package):
subprocess.check_call([sys.executable, "-m", "pip", "install", package])

# Required packages
for package in ['wbdata', 'country_converter']:
try:
__import__(package)
except ImportError:
install(package)

# Import libraries
import wbdata
import country_converter as coco
from datetime import datetime

# Define World Bank indicator code
dataset_code = 'GC.XPN.GSRV.ZS'

# Download data from World Bank API
data = wbdata.get_dataframe({dataset_code: 'value'},
date=(datetime(1960, 1, 1), datetime.today()),
parse_dates=True,
keep_levels=True).reset_index()

# Extract year
data['year'] = data['date'].dt.year

# Convert country names to ISO codes using country_converter
cc = coco.CountryConverter()
data['iso2c'] = cc.convert(names=data['country'], to='ISO2', not_found=None)
data['iso3c'] = cc.convert(names=data['country'], to='ISO3', not_found=None)

# Filter out rows where ISO codes could not be matched — likely not real countries
data = data[data['iso2c'].notna() & data['iso3c'].notna()]

# Sort for calculation
data = data.sort_values(['iso3c', 'year'])

# Calculate YoY absolute and percent change
data['value_change'] = data.groupby('iso3c')['value'].diff()
data['value_change_percent'] = data.groupby('iso3c')['value'].pct_change() * 100

# Calculate ranks (higher GDP per capita = better rank)
data['rank'] = data.groupby('year')['value'].rank(ascending=False, method='dense')

# Calculate rank change from previous year
data['rank_change'] = data.groupby('iso3c')['rank'].diff()

# Select desired columns
final_df = data[['country', 'iso2c', 'iso3c', 'year', 'value',
'value_change', 'value_change_percent', 'rank', 'rank_change']].copy()

# Optional: Add labels as metadata (could be useful for export or UI)
column_labels = {
'country': 'Country name',
'iso2c': 'ISO 2-letter country code',
'iso3c': 'ISO 3-letter country code',
'year': 'Year',
'value': 'GDP per capita (current US$)',
'value_change': 'Year-over-Year change in value',
'value_change_percent': 'Year-over-Year percent change in value',
'rank': 'Country rank by GDP per capita (higher = richer)',
'rank_change': 'Change in rank from previous year'
}

# Display first few rows
print(final_df.head(10))

# Optional: Save to CSV
#final_df.to_csv("gdp_per_capita_cleaned.csv", index=False)
                    
                
                    
# Check and install required packages
required_packages <- c("WDI", "countrycode", "dplyr")

for (pkg in required_packages) {
  if (!requireNamespace(pkg, quietly = TRUE)) {
    install.packages(pkg)
  }
}

# Load the necessary libraries
library(WDI)
library(dplyr)
library(countrycode)

# Define the dataset code (World Bank indicator code)
dataset_code <- 'GC.XPN.GSRV.ZS'

# Download data using WDI package
dat <- WDI(indicator = dataset_code)

# Filter only countries using 'is_country' from countrycode
# This uses iso2c to identify whether the entry is a recognized country
dat <- dat %>%
  filter(countrycode(iso2c, origin = 'iso2c', destination = 'country.name', warn = FALSE) %in%
           countrycode::codelist$country.name.en)

# Ensure dataset is ordered by country and year
dat <- dat %>%
  arrange(iso3c, year)

# Rename the dataset_code column to "value" for easier manipulation
dat <- dat %>%
  rename(value = !!dataset_code)

# Calculate year-over-year (YoY) change and percentage change
dat <- dat %>%
  group_by(iso3c) %>%
  mutate(
    value_change = value - lag(value),                              # Absolute change from previous year
    value_change_percent = 100 * (value - lag(value)) / lag(value) # Percent change from previous year
  ) %>%
  ungroup()

# Calculate rank by year (higher value => higher rank)
dat <- dat %>%
  group_by(year) %>%
  mutate(rank = dense_rank(desc(value))) %>% # Rank countries by descending value
  ungroup()

# Calculate rank change (positive = moved up, negative = moved down)
dat <- dat %>%
  group_by(iso3c) %>%
  mutate(rank_change = rank - lag(rank)) %>% # Change in rank compared to previous year
  ungroup()

# Select and reorder final columns
final_data <- dat %>%
  select(
    country,
    iso2c,
    iso3c,
    year,
    value,
    value_change,
    value_change_percent,
    rank,
    rank_change
  )

# Add labels (variable descriptions)
attr(final_data$country, "label") <- "Country name"
attr(final_data$iso2c, "label") <- "ISO 2-letter country code"
attr(final_data$iso3c, "label") <- "ISO 3-letter country code"
attr(final_data$year, "label") <- "Year"
attr(final_data$value, "label") <- "GDP per capita (current US$)"
attr(final_data$value_change, "label") <- "Year-over-Year change in value"
attr(final_data$value_change_percent, "label") <- "Year-over-Year percent change in value"
attr(final_data$rank, "label") <- "Country rank by GDP per capita (higher = richer)"
attr(final_data$rank_change, "label") <- "Change in rank from previous year"

# Print the first few rows of the final dataset
print(head(final_data, 10))