Gross national expenditure (% of GDP)

Source: worldbank.org, 03.09.2025

Year: 2024

Flag Country Value Value change, % Rank
Angola Angola 86.5 +1.4% 120
Argentina Argentina 98.9 -2.8% 79
Armenia Armenia 99.4 -1.35% 76
Australia Australia 97.9 +2.34% 84
Austria Austria 97 -1.15% 89
Azerbaijan Azerbaijan 90.9 +6.24% 111
Belgium Belgium 100 -0.583% 71
Benin Benin 103 -1.62% 58
Burkina Faso Burkina Faso 106 -0.601% 40
Bangladesh Bangladesh 107 +1.48% 38
Bulgaria Bulgaria 97.7 +1.85% 87
Bahamas Bahamas 104 +4.67% 53
Bosnia & Herzegovina Bosnia & Herzegovina 119 +4.92% 14
Belarus Belarus 102 +5.33% 63
Bermuda Bermuda 67.9 -0.193% 125
Brazil Brazil 99.5 +1.82% 74
Brunei Brunei 79.9 -0.241% 124
Botswana Botswana 114 +10.9% 26
Central African Republic Central African Republic 120 -7.51% 13
Canada Canada 100 +0.295% 69
Switzerland Switzerland 89.8 +1.27% 113
Chile Chile 96.4 -2.71% 94
Côte d’Ivoire Côte d’Ivoire 99.5 -3.89% 75
Cameroon Cameroon 106 +2.33% 41
Congo - Kinshasa Congo - Kinshasa 104 +1.47% 51
Congo - Brazzaville Congo - Brazzaville 87.6 +6.32% 119
Colombia Colombia 105 +0.208% 49
Comoros Comoros 125 -1.35% 8
Cape Verde Cape Verde 111 -5.56% 29
Costa Rica Costa Rica 94.3 -0.394% 106
Cyprus Cyprus 96.4 -2.56% 93
Czechia Czechia 93.4 -1.65% 108
Germany Germany 96.1 +0.156% 95
Djibouti Djibouti 88 +4.15% 116
Denmark Denmark 89.2 -2.9% 115
Dominican Republic Dominican Republic 106 -0.886% 42
Ecuador Ecuador 96.6 -3.22% 90
Egypt Egypt 107 +4.51% 37
Spain Spain 95.7 -0.368% 98
Estonia Estonia 101 -1.28% 68
Ethiopia Ethiopia 106 -1.12% 43
Finland Finland 98.9 -1.17% 78
France France 101 -1.24% 66
Gabon Gabon 63.9 +2.03% 128
United Kingdom United Kingdom 101 +0.0523% 65
Georgia Georgia 108 -0.931% 36
Ghana Ghana 98.8 -1.98% 80
Guinea Guinea 112 +4.14% 28
Gambia Gambia 131 +8.34% 4
Guinea-Bissau Guinea-Bissau 116 +1.28% 19
Equatorial Guinea Equatorial Guinea 90.2 +2.24% 112
Greece Greece 105 +0.59% 48
Guatemala Guatemala 116 +0.412% 20
Hong Kong SAR China Hong Kong SAR China 95.9 -3.49% 97
Honduras Honduras 124 -0.0344% 10
Croatia Croatia 103 +1.26% 56
Haiti Haiti 115 -3.99% 21
Hungary Hungary 94.4 -1.03% 104
Indonesia Indonesia 94.5 +2.5% 103
India India 104 +0.372% 52
Ireland Ireland 58.5 -12.3% 129
Iran Iran 103 +1.38% 55
Iraq Iraq 90.9 +11.7% 110
Iceland Iceland 101 +1.3% 64
Israel Israel 97.5 +0.364% 88
Italy Italy 97.7 -0.873% 86
Kenya Kenya 104 -1.37% 54
Cambodia Cambodia 97.8 -1.92% 85
Libya Libya 84.3 +0.104% 122
Sri Lanka Sri Lanka 103 +0.457% 59
Lithuania Lithuania 94.8 -1.33% 101
Luxembourg Luxembourg 67.2 -2.47% 126
Latvia Latvia 103 -1.11% 60
Macao SAR China Macao SAR China 55.6 -6.2% 130
Morocco Morocco 109 +0.83% 31
Moldova Moldova 126 +1.67% 7
Madagascar Madagascar 108 +0.555% 35
Mexico Mexico 106 +0.715% 47
North Macedonia North Macedonia 113 +0.0763% 27
Mali Mali 106 -1.85% 46
Malta Malta 82.6 -0.795% 123
Montenegro Montenegro 123 +3.4% 11
Mongolia Mongolia 101 +10.2% 67
Mozambique Mozambique 110 -4.23% 30
Mauritius Mauritius 104 +0.435% 50
Malaysia Malaysia 94.7 -0.256% 102
Namibia Namibia 126 +2.29% 6
Niger Niger 89.7 -9.49% 114
Nicaragua Nicaragua 118 +3.79% 18
Netherlands Netherlands 87.9 -1.04% 117
Norway Norway 86.1 +1.85% 121
Nepal Nepal 124 +0.201% 9
Pakistan Pakistan 107 -0.9% 39
Peru Peru 94.4 -2.19% 105
Philippines Philippines 114 +0.168% 24
Poland Poland 96 +1.84% 96
Puerto Rico Puerto Rico 99 -0.915% 77
Portugal Portugal 98.2 -0.677% 82
Paraguay Paraguay 102 +4.22% 61
Palestinian Territories Palestinian Territories 140 -3.56% 2
Romania Romania 106 +1.25% 44
Russia Russia 94.2 -0.00405% 107
Rwanda Rwanda 108 -5.73% 34
Saudi Arabia Saudi Arabia 96.5 +2.98% 92
Sudan Sudan 100 -0.182% 70
Senegal Senegal 115 -8.06% 23
Singapore Singapore 64.3 +2.31% 127
Sierra Leone Sierra Leone 123 +9.98% 12
El Salvador El Salvador 119 +0.183% 15
Somalia Somalia 154 +0.72% 1
Serbia Serbia 106 +1.66% 45
Slovakia Slovakia 99.8 +1.34% 72
Slovenia Slovenia 93.4 -0.196% 109
Sweden Sweden 95.6 -0.383% 99
Seychelles Seychelles 118 +3.53% 17
Chad Chad 87.8 -3.25% 118
Togo Togo 114 +0.0801% 25
Thailand Thailand 96.5 -0.0769% 91
Tunisia Tunisia 108 +2.42% 33
Turkey Turkey 99.7 -2.65% 73
Tanzania Tanzania 102 -1.95% 62
Uganda Uganda 98.5 -5.24% 81
Ukraine Ukraine 119 -1.63% 16
Uruguay Uruguay 94.9 -1.75% 100
United States United States 103 +0.212% 57
Uzbekistan Uzbekistan 115 -2% 22
Samoa Samoa 132 -7.84% 3
Kosovo Kosovo 130 -0.193% 5
South Africa South Africa 98 -1.27% 83
Zimbabwe Zimbabwe 108 +0.767% 32

                    
# 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 = 'NE.DAB.TOTL.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 <- 'NE.DAB.TOTL.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))