Households and NPISHs Final consumption expenditure, PPP (constant 2021 international $)

Source: worldbank.org, 03.09.2025

Year: 2024

Flag Country Value Value change, % Rank
Angola Angola 112,020,036,093 +0.31% 43
Albania Albania 28,918,131,653 +3.48% 75
Argentina Argentina 716,217,618,922 -4.24% 16
Armenia Armenia 36,123,300,713 +6.8% 63
Australia Australia 790,077,567,118 +1.11% 15
Benin Benin 35,520,298,331 +5.03% 65
Burkina Faso Burkina Faso 40,491,739,612 +5.14% 58
Bangladesh Bangladesh 965,487,037,083 +5.99% 10
Bulgaria Bulgaria 118,049,182,711 +4.22% 41
Bahamas Bahamas 7,875,702,017 +3.23% 92
Bosnia & Herzegovina Bosnia & Herzegovina 36,781,214,329 +2.06% 62
Belarus Belarus 147,398,615,648 +12.4% 37
Bermuda Bermuda 2,617,337,160 +3.09% 98
Brazil Brazil 2,542,829,700,572 +4.76% 4
Brunei Brunei 9,832,662,664 +5.95% 91
Botswana Botswana 19,571,541,570 +1.87% 82
Central African Republic Central African Republic 5,643,459,784 +19.7% 95
Chile Chile 301,434,318,074 +1.05% 24
Côte d’Ivoire Côte d’Ivoire 132,995,786,931 +6.32% 39
Cameroon Cameroon 102,227,170,869 +3.91% 44
Congo - Kinshasa Congo - Kinshasa 83,367,053,652 +3.1% 47
Congo - Brazzaville Congo - Brazzaville 17,122,529,655 +6.5% 86
Colombia Colombia 633,333,265,695 +1.58% 19
Comoros Comoros 2,581,924,033 +4.75% 99
Cape Verde Cape Verde 3,416,829,624 +5.01% 97
Costa Rica Costa Rica 78,691,996,610 +3.95% 49
Cyprus Cyprus 27,485,772,268 +3.83% 76
Djibouti Djibouti 5,912,513,607 +5.4% 94
Dominican Republic Dominican Republic 180,931,114,287 +4.56% 34
Ecuador Ecuador 153,969,246,670 -1.29% 36
Egypt Egypt 1,544,873,630,971 +8.02% 8
Ethiopia Ethiopia 290,926,327,917 +10.1% 26
Gabon Gabon 12,822,571,893 +2.56% 89
Georgia Georgia 52,029,231,753 +11% 55
Ghana Ghana 177,544,187,085 +4.6% 35
Guinea Guinea 38,565,163,526 +4.3% 60
Gambia Gambia 6,342,901,116 +4.4% 93
Guinea-Bissau Guinea-Bissau 4,038,946,016 +1.02% 96
Equatorial Guinea Equatorial Guinea 13,260,666,753 -2.03% 88
Guatemala Guatemala 191,967,805,509 +5.59% 31
Hong Kong SAR China Hong Kong SAR China 303,027,675,788 -0.572% 23
Honduras Honduras 56,105,093,029 +4.34% 53
Croatia Croatia 81,746,112,846 +5.61% 48
Haiti Haiti 29,384,488,814 -5.17% 73
Indonesia Indonesia 2,042,153,277,025 +5.11% 5
India India 9,019,567,204,230 +7.62% 2
Iran Iran 696,205,453,140 +2.55% 18
Iraq Iraq 231,993,041,081 +4% 29
Kenya Kenya 243,683,656,334 +4.07% 27
Cambodia Cambodia 67,651,246,434 +2.39% 51
Libya Libya 29,002,529,391 +2.3% 74
Sri Lanka Sri Lanka 190,910,265,994 +4.01% 33
Macao SAR China Macao SAR China 20,262,629,223 +4.9% 81
Morocco Morocco 200,257,504,751 +3.63% 30
Moldova Moldova 31,659,801,650 +5.16% 70
Madagascar Madagascar 39,209,989,540 +2.6% 59
Mexico Mexico 1,828,034,745,804 +2.83% 6
North Macedonia North Macedonia 25,573,917,928 +1.21% 77
Mali Mali 54,319,370,340 +4.12% 54
Malta Malta 14,285,653,252 +5.72% 87
Montenegro Montenegro 11,180,334,989 +8.74% 90
Mongolia Mongolia 32,270,105,289 +12.9% 69
Mozambique Mozambique 35,630,679,096 -6% 64
Mauritius Mauritius 20,639,042,900 +3.12% 80
Malaysia Malaysia 707,413,932,000 +5.11% 17
Namibia Namibia 25,342,070,732 +13.3% 78
Niger Niger 31,308,428,673 +3.1% 71
Nicaragua Nicaragua 36,801,868,359 +8.64% 61
Nepal Nepal 119,439,364,052 +1.07% 40
Pakistan Pakistan 1,278,949,186,898 +6.32% 9
Peru Peru 296,875,328,173 +2.77% 25
Philippines Philippines 843,832,758,192 +4.86% 14
Poland Poland 848,856,634,634 +3.01% 13
Paraguay Paraguay 68,477,463,438 +5.22% 50
Palestinian Territories Palestinian Territories 19,529,890,584 -32.5% 83
Romania Romania 441,000,182,866 +5.99% 21
Russia Russia 2,938,894,458,173 +5.4% 3
Rwanda Rwanda 34,508,261,578 +4.2% 66
Saudi Arabia Saudi Arabia 939,714,107,284 +2.71% 11
Sudan Sudan 66,954,058,019 -16.2% 52
Senegal Senegal 50,362,663,854 +3% 56
Singapore Singapore 191,730,244,538 +4.83% 32
Sierra Leone Sierra Leone 23,583,292,780 +4.19% 79
El Salvador El Salvador 49,881,335,416 +3.21% 57
Somalia Somalia 33,539,477,438 +5.95% 68
Serbia Serbia 93,845,705,693 +4.18% 45
Seychelles Seychelles 2,301,354,703 +11.6% 100
Chad Chad 30,251,531,973 +2.97% 72
Togo Togo 18,742,888,970 +5.4% 85
Thailand Thailand 855,304,866,613 +4.41% 12
Tunisia Tunisia 115,200,225,273 +4.08% 42
Turkey Turkey 1,824,831,170,805 +3.66% 7
Tanzania Tanzania 141,807,476,489 +3.1% 38
Uganda Uganda 88,491,486,233 +0.652% 46
Ukraine Ukraine 350,896,353,751 +6.68% 22
United States United States 17,492,831,137,535 +2.76% 1
Uzbekistan Uzbekistan 237,943,147,775 +7.46% 28
Samoa Samoa 1,087,321,945 +10.7% 101
Kosovo Kosovo 18,918,252,743 +5.7% 84
South Africa South Africa 533,100,978,745 +1.03% 20
Zimbabwe Zimbabwe 34,229,153,329 +2.98% 67

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