Gross national expenditure (constant 2015 US$)

Source: worldbank.org, 03.09.2025

Year: 2024

Flag Country Value Value change, % Rank
Angola Angola 89,214,862,134 +2.48% 54
Argentina Argentina 573,084,585,293 -6.49% 18
Armenia Armenia 16,736,000,872 +3.81% 98
Austria Austria 391,047,742,236 -1.49% 29
Belgium Belgium 520,896,105,200 +0.915% 21
Benin Benin 19,631,188,999 +6.06% 90
Burkina Faso Burkina Faso 20,661,277,885 +8.72% 88
Bangladesh Bangladesh 355,476,908,711 +5.39% 31
Bulgaria Bulgaria 67,440,067,891 +4.25% 60
Bahamas Bahamas 14,304,500,166 +6.73% 105
Bosnia & Herzegovina Bosnia & Herzegovina 25,629,771,102 +4.85% 83
Belarus Belarus 66,672,038,832 +9% 61
Bermuda Bermuda 4,870,221,460 +2.48% 113
Brazil Brazil 2,063,230,110,936 +5.27% 7
Brunei Brunei 11,946,951,952 +1.55% 107
Botswana Botswana 20,371,086,298 +6.65% 89
Central African Republic Central African Republic 3,439,880,039 +21.6% 114
Canada Canada 1,888,829,069,724 +1.6% 9
Switzerland Switzerland 699,946,982,030 +1.96% 16
Chile Chile 298,508,625,342 +1.35% 33
China China 17,475,849,911,333 +3.56% 2
Côte d’Ivoire Côte d’Ivoire 78,372,502,326 +6.97% 55
Cameroon Cameroon 45,977,408,332 +6.88% 70
Congo - Kinshasa Congo - Kinshasa 114,403,676,336 +13.2% 47
Colombia Colombia 398,757,134,151 +2.23% 28
Comoros Comoros 1,626,627,559 +4.33% 120
Cape Verde Cape Verde 2,794,082,728 +3.85% 116
Costa Rica Costa Rica 75,845,884,970 +4.73% 58
Cyprus Cyprus 29,875,602,972 +0.699% 78
Czechia Czechia 208,949,573,493 +0.388% 41
Germany Germany 3,552,506,951,284 +0.38% 4
Djibouti Djibouti 2,994,791,017 +0.23% 115
Denmark Denmark 324,950,172,901 +0.407% 32
Dominican Republic Dominican Republic 112,150,001,469 +3.95% 48
Ecuador Ecuador 108,462,957,337 -2.17% 50
Egypt Egypt 504,598,832,495 +5.99% 22
Spain Spain 1,366,566,558,262 +2.93% 12
Estonia Estonia 28,084,852,125 -0.831% 79
Ethiopia Ethiopia 135,079,048,044 +8.45% 45
Finland Finland 250,052,029,912 -0.643% 37
France France 2,700,487,651,892 +0.309% 6
Gabon Gabon 17,172,427,608 +5.54% 95
United Kingdom United Kingdom 3,315,107,228,699 +2.32% 5
Georgia Georgia 27,900,268,638 +10.7% 80
Ghana Ghana 78,313,072,052 +5.93% 56
Guinea Guinea 18,055,658,925 +14.6% 92
Gambia Gambia 2,468,352,712 +5.42% 117
Guinea-Bissau Guinea-Bissau 1,964,431,159 +6.04% 119
Equatorial Guinea Equatorial Guinea 10,085,846,851 +1.29% 110
Greece Greece 243,558,698,437 +4.1% 38
Guatemala Guatemala 98,466,237,379 +5.33% 52
Honduras Honduras 34,911,850,201 +6.26% 74
Croatia Croatia 71,069,630,880 +6.06% 59
Haiti Haiti 17,522,122,741 -6.2% 94
Hungary Hungary 148,839,594,783 +0.133% 43
Indonesia Indonesia 1,209,549,596,310 +6.02% 13
India India 3,593,771,853,146 +6.66% 3
Ireland Ireland 268,446,487,024 -11.7% 35
Iran Iran 545,254,319,565 +3.86% 20
Iraq Iraq 190,418,450,133 +8.89% 42
Iceland Iceland 23,408,820,388 +2.22% 85
Israel Israel 415,364,946,794 +2.64% 25
Italy Italy 1,982,033,110,005 +0.381% 8
Kenya Kenya 108,736,801,797 +3.48% 49
Cambodia Cambodia 38,836,187,593 +2% 73
Libya Libya 45,818,177,806 +1.72% 71
Sri Lanka Sri Lanka 92,810,926,446 +7.13% 53
Lithuania Lithuania 50,522,583,064 +3.04% 67
Luxembourg Luxembourg 48,886,000,111 +0.0705% 68
Latvia Latvia 34,430,798,384 -1.74% 75
Macao SAR China Macao SAR China 24,650,288,347 +2.25% 84
Morocco Morocco 147,111,762,985 +5.74% 44
Moldova Moldova 11,852,701,453 +0.57% 108
Madagascar Madagascar 14,862,912,710 +3.12% 102
Mexico Mexico 1,456,342,971,510 +2.78% 11
North Macedonia North Macedonia 14,413,039,513 +4.12% 104
Mali Mali 25,878,055,592 +3.43% 81
Malta Malta 16,329,472,078 +5.3% 99
Montenegro Montenegro 7,012,995,615 +7.15% 112
Mongolia Mongolia 23,054,499,935 +16.8% 87
Mozambique Mozambique 25,841,887,033 +0.439% 82
Malaysia Malaysia 403,954,662,073 +5.25% 27
Namibia Namibia 17,892,106,299 +7.26% 93
Niger Niger 16,959,775,358 +2.77% 96
Nicaragua Nicaragua 19,183,577,929 +11.7% 91
Netherlands Netherlands 821,675,091,111 +0.921% 15
Norway Norway 405,890,668,585 -0.0966% 26
Nepal Nepal 44,468,824,575 +1.54% 72
Pakistan Pakistan 474,645,689,945 +3.82% 24
Peru Peru 234,852,518,684 +3.99% 40
Philippines Philippines 492,808,551,366 +5.76% 23
Poland Poland 625,590,502,719 +4.23% 17
Portugal Portugal 242,759,683,689 +2.66% 39
Paraguay Paraguay 46,596,509,759 +6.9% 69
Palestinian Territories Palestinian Territories 15,128,800,000 -31% 101
Romania Romania 265,028,898,957 +3.56% 36
Russia Russia 1,621,213,776,751 +4.4% 10
Rwanda Rwanda 16,814,969,921 +7.92% 97
Saudi Arabia Saudi Arabia 891,531,639,166 +1.67% 14
Senegal Senegal 32,230,423,522 -3.45% 77
Singapore Singapore 289,857,357,390 +7.13% 34
Sierra Leone Sierra Leone 12,680,443,921 +6.34% 106
El Salvador El Salvador 33,161,406,418 +2.33% 76
Somalia Somalia 14,519,654,384 +6.73% 103
Serbia Serbia 61,980,936,472 +6.86% 63
Slovakia Slovakia 100,548,816,084 +3.92% 51
Slovenia Slovenia 51,581,508,491 +2.12% 66
Sweden Sweden 546,375,822,197 +0.555% 19
Seychelles Seychelles 2,374,648,818 +5.75% 118
Chad Chad 16,163,784,783 +2.97% 100
Togo Togo 9,654,791,344 +5.22% 111
Tunisia Tunisia 53,003,749,776 +3.79% 65
Tanzania Tanzania 77,826,061,953 +4.67% 57
Uganda Uganda 53,276,143,253 +3.04% 64
Ukraine Ukraine 117,508,219,296 +3.29% 46
Uruguay Uruguay 63,258,089,075 +0.0961% 62
United States United States 23,625,200,725,726 +3.09% 1
Samoa Samoa 1,235,481,160 +5.67% 121
Kosovo Kosovo 11,516,316,825 +5.19% 109
South Africa South Africa 367,843,777,415 -0.717% 30
Zimbabwe Zimbabwe 23,134,905,129 +2.75% 86

                    
# 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.KD'

# 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.KD'

# 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))