Households and NPISHs Final consumption expenditure, PPP (current international US$)

Source: worldbank.org, 03.09.2025

Year: 2024

Flag Country Value Value change, % Rank
Angola Angola 144,062,221,755 +2.9% 37
Albania Albania 37,385,716,581 +9.58% 59
Armenia Armenia 42,759,435,460 +12% 52
Australia Australia 954,077,264,878 +6.15% 13
Azerbaijan Azerbaijan 132,664,459,716 +6.12% 38
Benin Benin 38,488,724,886 +7.89% 58
Burkina Faso Burkina Faso 42,823,275,948 +6.02% 51
Bangladesh Bangladesh 1,063,516,555,900 +6.18% 9
Bulgaria Bulgaria 150,282,656,150 +11.8% 35
Bahamas Bahamas 9,198,309,992 +7.81% 79
Bosnia & Herzegovina Bosnia & Herzegovina 42,757,079,098 -2.12% 53
Belarus Belarus 171,316,902,007 +15.9% 33
Brazil Brazil 2,966,879,236,472 +7.29% 3
Brunei Brunei 10,845,728,470 +8.78% 78
Botswana Botswana 22,434,678,284 +5.42% 71
Chile Chile 362,532,092,319 +3.7% 22
Côte d’Ivoire Côte d’Ivoire 147,882,065,626 +4.38% 36
Cameroon Cameroon 111,677,889,901 +3.37% 41
Congo - Brazzaville Congo - Brazzaville 19,480,857,021 +10.1% 73
Colombia Colombia 761,208,505,737 +1.98% 16
Cape Verde Cape Verde 3,964,945,425 +8.06% 83
Costa Rica Costa Rica 90,702,251,208 +6.13% 44
Cyprus Cyprus 31,970,572,170 +9.29% 65
Djibouti Djibouti 5,812,478,235 +8.64% 81
Dominican Republic Dominican Republic 213,044,839,271 +8.48% 30
Ecuador Ecuador 179,648,686,330 +3.13% 32
Egypt Egypt 1,751,493,118,911 +21.9% 6
Ethiopia Ethiopia 384,683,528,406 +16.4% 20
Gabon Gabon 15,025,324,241 +6.86% 76
Georgia Georgia 60,971,799,176 +15.5% 47
Ghana Ghana 209,440,399,797 +9.24% 31
Guinea Guinea 40,699,914,381 +3.08% 56
Gambia Gambia 7,212,975,544 +2.39% 80
Guinea-Bissau Guinea-Bissau 4,323,438,946 -1.62% 82
Guatemala Guatemala 222,471,575,194 +8.28% 28
Hong Kong SAR China Hong Kong SAR China 366,499,643,260 +3.75% 21
Honduras Honduras 63,855,066,959 +5.95% 46
Croatia Croatia 95,867,475,384 +10.2% 43
Haiti Haiti 31,242,033,069 -3.65% 66
India India 10,229,822,872,835 +10.1% 2
Iran Iran 876,369,723,480 +7.92% 14
Kenya Kenya 285,488,740,753 +7.4% 25
Libya Libya 40,781,521,232 +5.6% 55
Sri Lanka Sri Lanka 234,797,051,344 +9.41% 26
Morocco Morocco 233,096,712,209 +6.86% 27
Moldova Moldova 33,628,984,524 +6.23% 62
Mexico Mexico 2,170,137,117,833 +4.39% 4
North Macedonia North Macedonia 28,700,264,200 +6.67% 67
Mali Mali 60,241,847,369 +6.76% 48
Malta Malta 17,172,177,377 +11.9% 74
Montenegro Montenegro 13,477,023,935 +13.1% 77
Mongolia Mongolia 35,448,971,515 +22.3% 60
Mozambique Mozambique 39,398,553,495 -6.36% 57
Mauritius Mauritius 23,921,614,462 +6.21% 69
Malaysia Malaysia 810,012,761,663 +7.64% 15
Namibia Namibia 26,531,199,665 +13.6% 68
Niger Niger 32,681,680,585 +2.18% 63
Nicaragua Nicaragua 42,720,584,023 +12.7% 54
Pakistan Pakistan 1,387,956,935,342 +17.7% 7
Peru Peru 342,945,197,673 +5.86% 23
Philippines Philippines 970,795,025,952 +7.97% 12
Poland Poland 1,011,365,171,640 +8.23% 10
Paraguay Paraguay 79,334,618,812 +7.62% 45
Palestinian Territories Palestinian Territories 16,557,188,383 -49.9% 75
Romania Romania 529,606,967,140 +10.9% 18
Rwanda Rwanda 33,713,322,668 -0.528% 61
Saudi Arabia Saudi Arabia 1,109,017,024,565 +6.2% 8
Senegal Senegal 56,187,726,558 +4.77% 50
Singapore Singapore 221,030,530,915 +8.02% 29
Sierra Leone Sierra Leone 22,568,961,791 +1.44% 70
El Salvador El Salvador 58,631,457,301 +7.24% 49
Serbia Serbia 114,969,450,752 +9.66% 40
Seychelles Seychelles 2,714,325,271 +13.8% 84
Chad Chad 32,208,653,215 -1.27% 64
Togo Togo 21,200,321,053 +8.54% 72
Thailand Thailand 988,235,448,801 +6.45% 11
Tunisia Tunisia 132,309,523,656 +3.71% 39
Turkey Turkey 2,055,892,653,006 +0.372% 5
Tanzania Tanzania 164,810,257,863 +6.2% 34
Uganda Uganda 101,319,459,129 +2.13% 42
Ukraine Ukraine 441,909,443,333 +14.2% 19
United States United States 19,825,338,000,000 +5.33% 1
Uzbekistan Uzbekistan 293,039,484,982 +12.6% 24
Samoa Samoa 1,257,481,282 +6.63% 85
South Africa South Africa 617,691,032,929 +3.76% 17

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