Gross national expenditure (current US$)

Source: worldbank.org, 03.09.2025

Year: 2024

Flag Country Value Value change, % Rank
Angola Angola 69,567,822,364 -3.95% 68
Argentina Argentina 626,026,233,120 -4.73% 20
Armenia Armenia 25,643,726,479 +5.61% 94
Australia Australia 1,714,836,604,992 +3.77% 11
Austria Austria 505,915,117,196 +0.777% 25
Azerbaijan Azerbaijan 67,541,823,529 +9.01% 70
Belgium Belgium 664,651,421,353 +2.49% 19
Benin Benin 22,118,255,147 +7.43% 100
Burkina Faso Burkina Faso 24,750,712,116 +13.7% 95
Bangladesh Bangladesh 480,472,385,072 +4.42% 26
Bulgaria Bulgaria 109,602,478,535 +11.6% 56
Bahamas Bahamas 16,468,700,000 +8.52% 110
Bosnia & Herzegovina Bosnia & Herzegovina 33,835,144,426 +7.77% 89
Belarus Belarus 77,206,585,439 +10.4% 65
Bermuda Bermuda 6,097,300,000 +4.47% 121
Brazil Brazil 2,168,555,563,558 +1.27% 8
Brunei Brunei 12,354,756,233 +2.19% 116
Botswana Botswana 22,039,463,910 +10.8% 101
Central African Republic Central African Republic 3,294,499,039 -0.409% 123
Canada Canada 2,246,311,069,072 +3.43% 7
Switzerland Switzerland 840,821,666,798 +6.04% 18
Chile Chile 318,421,164,894 -4.24% 40
Côte d’Ivoire Côte d’Ivoire 86,080,375,177 +4.46% 61
Cameroon Cameroon 54,617,731,956 +6.58% 73
Congo - Kinshasa Congo - Kinshasa 73,756,985,961 +7.13% 67
Congo - Brazzaville Congo - Brazzaville 13,775,240,513 +9.09% 114
Colombia Colombia 439,230,805,223 +14.5% 28
Comoros Comoros 1,925,669,138 +6.62% 128
Cape Verde Cape Verde 3,082,558,451 +2.94% 125
Costa Rica Costa Rica 89,884,389,291 +9.8% 60
Cyprus Cyprus 35,030,916,668 +4.47% 87
Czechia Czechia 322,390,822,751 -1.12% 39
Germany Germany 4,480,248,767,176 +3.13% 2
Djibouti Djibouti 3,595,988,714 +8.65% 122
Denmark Denmark 383,028,977,439 +2.44% 36
Dominican Republic Dominican Republic 132,046,977,290 +2.26% 51
Ecuador Ecuador 120,494,362,000 -0.405% 55
Egypt Egypt 415,703,215,403 +2.7% 30
Spain Spain 1,649,003,396,999 +5.94% 12
Estonia Estonia 42,992,552,700 +2.24% 82
Finland Finland 296,678,321,723 +0.465% 42
France France 3,185,314,102,066 +2.33% 5
Gabon Gabon 13,340,548,967 +6.15% 115
United Kingdom United Kingdom 3,680,432,433,110 +8.19% 4
Georgia Georgia 36,345,135,617 +8.72% 86
Ghana Ghana 81,871,888,909 +0.792% 62
Guinea Guinea 28,378,891,398 +17.7% 91
Gambia Gambia 3,275,714,989 +13.4% 124
Guinea-Bissau Guinea-Bissau 2,452,892,644 +3.33% 127
Equatorial Guinea Equatorial Guinea 11,516,384,116 +5.79% 117
Greece Greece 270,922,067,526 +6.23% 44
Guatemala Guatemala 130,811,689,496 +8.91% 52
Hong Kong SAR China Hong Kong SAR China 390,595,108,839 +3.11% 35
Honduras Honduras 46,000,456,787 +7.93% 78
Croatia Croatia 95,410,774,533 +11% 58
Haiti Haiti 29,120,362,599 +22% 90
Hungary Hungary 210,533,188,098 +3.07% 47
Indonesia Indonesia 1,319,887,337,223 +4.38% 13
India India 4,078,669,980,687 +7.94% 3
Ireland Ireland 337,671,836,759 -8.22% 38
Iran Iran 451,828,261,304 +9.47% 27
Iraq Iraq 254,253,953,226 +16.2% 45
Iceland Iceland 33,845,747,675 +7.78% 88
Israel Israel 526,997,222,385 +5.89% 23
Italy Italy 2,318,446,841,401 +2.06% 6
Kenya Kenya 129,209,329,266 +13.7% 53
Cambodia Cambodia 45,324,272,475 +7.38% 80
Libya Libya 39,302,198,912 +3.52% 84
Sri Lanka Sri Lanka 101,560,830,003 +18.8% 57
Lithuania Lithuania 80,473,354,539 +4.95% 63
Luxembourg Luxembourg 62,650,151,464 +3.79% 71
Latvia Latvia 44,635,067,226 +1.09% 81
Macao SAR China Macao SAR China 27,910,379,103 +2.77% 93
Morocco Morocco 168,616,778,599 +7.82% 48
Moldova Moldova 22,903,130,785 +10.7% 99
Madagascar Madagascar 18,765,940,308 +10.4% 105
Mexico Mexico 1,957,047,486,957 +4.02% 10
North Macedonia North Macedonia 18,874,773,204 +5.93% 104
Mali Mali 28,147,685,412 +5.99% 92
Malta Malta 20,093,898,557 +8.63% 102
Montenegro Montenegro 9,899,408,676 +10.8% 119
Mongolia Mongolia 23,758,382,435 +27.8% 97
Mozambique Mozambique 24,703,967,078 +2.46% 96
Mauritius Mauritius 15,624,024,083 +6.5% 111
Malaysia Malaysia 399,426,578,420 +5.3% 32
Namibia Namibia 16,894,736,904 +10.2% 109
Niger Niger 17,517,533,501 +5.9% 108
Nicaragua Nicaragua 23,160,067,398 +14.8% 98
Netherlands Netherlands 1,079,066,219,755 +5.23% 16
Norway Norway 416,523,489,725 +2.02% 29
Nepal Nepal 53,289,515,922 +4.76% 74
Pakistan Pakistan 397,965,373,511 +9.42% 33
Peru Peru 273,027,580,994 +5.97% 43
Philippines Philippines 527,806,952,888 +5.8% 22
Poland Poland 878,037,561,957 +14.7% 17
Puerto Rico Puerto Rico 124,556,000,000 +5.34% 54
Portugal Portugal 303,070,622,648 +5.83% 41
Paraguay Paraguay 45,537,469,755 +7.46% 79
Palestinian Territories Palestinian Territories 19,151,100,000 -25.9% 103
Romania Romania 406,114,322,373 +10.5% 31
Russia Russia 2,048,223,746,599 +4.94% 9
Rwanda Rwanda 15,370,582,755 -6.26% 112
Saudi Arabia Saudi Arabia 1,193,922,933,333 +4.58% 15
Sudan Sudan 49,947,413,108 +24.9% 76
Senegal Senegal 37,135,017,432 -3.36% 85
Singapore Singapore 351,877,928,475 +10.8% 37
Sierra Leone Sierra Leone 9,253,514,457 +29.5% 120
El Salvador El Salvador 42,133,210,000 +4.65% 83
Somalia Somalia 18,686,100,660 +11.2% 106
Serbia Serbia 94,496,091,291 +11.3% 59
Slovakia Slovakia 141,489,949,258 +7.3% 49
Slovenia Slovenia 67,710,506,373 +4.62% 69
Sweden Sweden 583,323,720,325 +3.81% 21
Seychelles Seychelles 2,558,047,317 +2.57% 126
Chad Chad 18,118,881,142 +4.44% 107
Togo Togo 11,286,342,984 +8.31% 118
Thailand Thailand 507,903,514,802 +1.96% 24
Tunisia Tunisia 57,746,676,636 +13.5% 72
Turkey Turkey 1,319,703,802,088 +15.2% 14
Tanzania Tanzania 80,238,990,068 -2.3% 64
Uganda Uganda 52,870,526,474 +4.25% 75
Ukraine Ukraine 226,853,512,504 +3.53% 46
Uruguay Uruguay 76,867,564,539 +2% 66
United States United States 30,087,941,000,000 +5.5% 1
Uzbekistan Uzbekistan 132,435,255,509 +9.76% 50
Samoa Samoa 1,406,871,805 +4.91% 129
Kosovo Kosovo 14,539,881,995 +6.29% 113
South Africa South Africa 392,340,264,331 +3.8% 34
Zimbabwe Zimbabwe 47,926,717,087 +26.4% 77

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

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

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