Final consumption expenditure (current US$)

Source: worldbank.org, 03.09.2025

Year: 2024

Flag Country Value Value change, % Rank
Angola Angola 49,467,324,524 -5.32% 70
Albania Albania 22,394,284,153 +15.6% 92
Argentina Argentina 526,454,876,755 -1.03% 19
Armenia Armenia 19,926,350,164 +4.04% 95
Australia Australia 1,287,454,058,881 +3.98% 12
Austria Austria 389,582,267,180 +4.72% 25
Azerbaijan Azerbaijan 51,874,235,294 +5.64% 67
Belgium Belgium 504,989,261,931 +4.12% 20
Benin Benin 14,586,078,320 +5.73% 106
Burkina Faso Burkina Faso 18,450,788,007 +7.36% 98
Bangladesh Bangladesh 342,283,513,255 +5.4% 29
Bulgaria Bulgaria 86,762,766,879 +11.3% 56
Bahamas Bahamas 12,224,500,000 +4.63% 112
Bosnia & Herzegovina Bosnia & Herzegovina 25,114,404,801 +4.07% 89
Belarus Belarus 57,581,190,515 +10.7% 65
Bermuda Bermuda 5,084,000,000 +4.28% 122
Brazil Brazil 1,800,022,918,220 +0.224% 6
Brunei Brunei 7,969,045,150 +4.62% 119
Botswana Botswana 15,017,850,086 +7.18% 104
Central African Republic Central African Republic 2,870,514,551 +6.27% 124
Canada Canada 1,724,808,964,432 +4.38% 8
Switzerland Switzerland 588,064,240,546 +4.92% 18
Chile Chile 241,668,186,285 -4.9% 37
Côte d’Ivoire Côte d’Ivoire 64,898,942,222 +5.31% 62
Cameroon Cameroon 43,644,371,763 +4.84% 75
Congo - Kinshasa Congo - Kinshasa 50,105,987,916 +5.69% 69
Congo - Brazzaville Congo - Brazzaville 9,555,268,581 +9.02% 117
Colombia Colombia 367,712,408,298 +13.7% 26
Comoros Comoros 1,744,243,107 +7.68% 129
Cape Verde Cape Verde 2,640,883,658 +5.49% 125
Costa Rica Costa Rica 74,943,908,113 +9.14% 57
Cyprus Cyprus 28,148,697,356 +6.07% 86
Czechia Czechia 232,540,929,354 +1.15% 40
Germany Germany 3,499,431,304,950 +4.04% 2
Djibouti Djibouti 3,750,430,003 +9.13% 123
Denmark Denmark 290,116,702,057 +3.25% 35
Dominican Republic Dominican Republic 98,493,198,331 +3% 53
Ecuador Ecuador 97,451,222,000 +1.55% 54
Egypt Egypt 365,138,109,596 +7.55% 27
Spain Spain 1,296,276,167,463 +6.59% 11
Estonia Estonia 31,795,634,146 +3.86% 83
Finland Finland 231,732,246,457 +1.86% 41
France France 2,491,791,588,804 +3.55% 5
Gabon Gabon 9,560,206,959 +5.63% 116
United Kingdom United Kingdom 3,028,322,909,081 +7.32% 3
Georgia Georgia 28,638,931,240 +11.3% 85
Ghana Ghana 73,625,343,082 +0.506% 60
Guinea Guinea 20,478,922,412 +8.62% 94
Gambia Gambia 2,298,153,648 +2.81% 126
Guinea-Bissau Guinea-Bissau 2,009,188,570 +1.49% 128
Equatorial Guinea Equatorial Guinea 10,373,105,844 +6.59% 115
Greece Greece 224,177,662,655 +4.61% 43
Guatemala Guatemala 111,925,909,147 +8.75% 50
Hong Kong SAR China Hong Kong SAR China 326,495,710,505 +2.89% 31
Honduras Honduras 37,657,247,496 +7.6% 78
Croatia Croatia 73,663,120,039 +11.1% 59
Haiti Haiti 26,613,242,539 +26% 87
Hungary Hungary 157,880,063,533 +6.08% 47
Indonesia Indonesia 881,500,012,930 +3.89% 14
India India 2,802,707,415,833 +9.27% 4
Ireland Ireland 237,131,073,645 +6.48% 39
Iran Iran 277,021,118,522 +8.37% 36
Iraq Iraq 172,072,391,576 +11.7% 46
Iceland Iceland 24,955,636,162 +6.73% 90
Israel Israel 400,403,943,611 +10% 23
Italy Italy 1,788,049,239,156 +2.57% 7
Kenya Kenya 108,312,136,407 +12.8% 51
Cambodia Cambodia 30,405,148,500 +8.15% 84
Libya Libya 32,382,629,225 +6.06% 82
Sri Lanka Sri Lanka 74,881,377,853 +15.3% 58
Lithuania Lithuania 63,149,483,881 +6.72% 64
Luxembourg Luxembourg 48,527,654,835 +7.51% 72
Latvia Latvia 35,430,182,252 +5.16% 79
Macao SAR China Macao SAR China 20,655,405,097 +2.86% 93
Morocco Morocco 122,418,789,969 +6.67% 48
Moldova Moldova 19,057,175,154 +9.98% 97
Madagascar Madagascar 14,827,781,205 +7.13% 105
Mexico Mexico 1,509,415,015,894 +3.96% 9
North Macedonia North Macedonia 14,132,280,399 +7.49% 108
Mali Mali 22,603,158,375 +7.3% 91
Malta Malta 15,520,453,095 +10.1% 103
Montenegro Montenegro 7,596,812,413 +10.8% 120
Mongolia Mongolia 15,587,225,856 +33.3% 102
Mozambique Mozambique 19,294,840,818 -3.26% 96
Mauritius Mauritius 12,455,672,694 +4.96% 111
Malaysia Malaysia 307,214,773,447 +6.12% 33
Namibia Namibia 13,469,611,029 +13.7% 110
Niger Niger 13,867,827,955 +7.33% 109
Nicaragua Nicaragua 18,296,824,838 +12.7% 99
Netherlands Netherlands 842,297,656,977 +5.95% 15
Norway Norway 300,354,928,267 +3.16% 34
Nepal Nepal 40,243,839,702 +5.67% 77
Pakistan Pakistan 349,704,833,107 +10.6% 28
Peru Peru 216,861,535,478 +5.05% 44
Philippines Philippines 418,474,486,303 +5.52% 22
Poland Poland 716,551,241,301 +15.1% 17
Puerto Rico Puerto Rico 105,956,800,000 +4.68% 52
Portugal Portugal 241,072,870,600 +6.18% 38
Paraguay Paraguay 35,385,138,337 +5.05% 80
Palestinian Territories Palestinian Territories 15,933,100,000 -25.1% 101
Romania Romania 313,102,122,477 +13% 32
Russia Russia 1,476,529,787,941 +6.04% 10
Rwanda Rwanda 11,677,390,834 -10.3% 113
Saudi Arabia Saudi Arabia 821,041,600,000 +4.49% 16
Sudan Sudan 48,513,499,040 +24% 73
Senegal Senegal 26,522,971,714 +3.78% 88
Singapore Singapore 230,356,681,806 +9.59% 42
Sierra Leone Sierra Leone 7,027,231,885 +19.4% 121
El Salvador El Salvador 34,938,480,000 +5.06% 81
Somalia Somalia 15,935,660,220 +11% 100
Serbia Serbia 71,722,493,528 +10.6% 61
Slovakia Slovakia 113,029,309,011 +7.3% 49
Slovenia Slovenia 52,376,885,531 +6.13% 66
Sweden Sweden 433,057,668,891 +4.01% 21
Seychelles Seychelles 2,185,947,652 +6.95% 127
Chad Chad 14,446,316,366 +4.46% 107
Togo Togo 9,073,701,104 +9.13% 118
Thailand Thailand 394,344,624,787 +3.16% 24
Tunisia Tunisia 50,614,291,824 +7.38% 68
Turkey Turkey 981,695,225,715 +21.1% 13
Tanzania Tanzania 48,912,517,066 -1.61% 71
Uganda Uganda 40,901,648,400 +3.32% 76
Ukraine Ukraine 191,293,563,849 +2.64% 45
Uruguay Uruguay 64,240,262,681 +4.14% 63
United States United States 23,742,028,000,000 +5.3% 1
Uzbekistan Uzbekistan 94,155,611,561 +10.6% 55
Samoa Samoa 1,056,709,577 +6.4% 130
Kosovo Kosovo 10,771,995,322 +6.39% 114
South Africa South Africa 336,535,101,237 +5.56% 30
Zimbabwe Zimbabwe 45,952,520,590 +42.8% 74

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