Households and NPISHs Final consumption expenditure (constant 2015 US$)

Source: worldbank.org, 03.09.2025

Year: 2024

Flag Country Value Value change, % Rank
Angola Angola 49,508,573,270 +0.31% 37
Albania Albania 11,002,376,686 +3.48% 73
Argentina Argentina 378,162,898,663 -4.24% 12
Armenia Armenia 11,279,953,269 +6.8% 70
Australia Australia 911,537,616,409 +1.11% 6
Benin Benin 12,335,344,555 +5.03% 66
Burkina Faso Burkina Faso 11,960,086,106 +5.14% 67
Bangladesh Bangladesh 229,438,994,126 +5.99% 20
Bulgaria Bulgaria 43,003,439,591 +4.22% 41
Bahamas Bahamas 8,409,561,708 +3.23% 84
Bosnia & Herzegovina Bosnia & Herzegovina 14,901,703,041 +2.06% 62
Belarus Belarus 43,012,183,802 +12.4% 40
Bermuda Bermuda 3,172,521,951 +3.09% 93
Brazil Brazil 1,314,021,145,373 +4.76% 3
Brunei Brunei 4,684,691,556 +5.95% 92
Botswana Botswana 8,181,994,739 +1.87% 85
Central African Republic Central African Republic 2,876,874,400 +19.7% 95
Chile Chile 182,952,523,420 +1.05% 22
Côte d’Ivoire Côte d’Ivoire 46,815,856,216 +6.32% 39
Cameroon Cameroon 32,515,020,938 +3.91% 48
Congo - Kinshasa Congo - Kinshasa 36,990,309,305 +3.1% 44
Congo - Brazzaville Congo - Brazzaville 5,364,123,717 +6.5% 90
Colombia Colombia 275,590,142,386 +1.58% 16
Comoros Comoros 1,323,415,492 +4.75% 100
Cape Verde Cape Verde 1,777,924,215 +5.01% 96
Costa Rica Costa Rica 46,992,490,233 +3.95% 38
Cyprus Cyprus 19,422,486,787 +3.83% 55
Djibouti Djibouti 2,981,418,571 +5.4% 94
Dominican Republic Dominican Republic 72,253,305,492 +4.56% 33
Ecuador Ecuador 70,970,048,953 -1.29% 34
Egypt Egypt 406,123,890,256 +8.02% 10
Ethiopia Ethiopia 88,961,656,042 +10.1% 28
Gabon Gabon 5,669,104,583 +2.56% 89
Georgia Georgia 18,795,310,573 +11% 56
Ghana Ghana 59,574,599,038 +4.6% 36
Guinea Guinea 10,381,088,413 +4.3% 77
Gambia Gambia 1,528,870,395 +4.4% 97
Guinea-Bissau Guinea-Bissau 1,417,899,362 +1.02% 99
Equatorial Guinea Equatorial Guinea 5,828,848,483 -2.03% 88
Guatemala Guatemala 74,987,470,348 +5.59% 31
Hong Kong SAR China Hong Kong SAR China 226,487,217,147 -0.572% 21
Honduras Honduras 24,497,011,124 +4.34% 52
Croatia Croatia 41,279,241,268 +5.61% 42
Haiti Haiti 14,915,970,169 -5.17% 61
Indonesia Indonesia 693,074,753,055 +5.11% 8
India India 2,073,858,200,165 +7.62% 2
Iran Iran 262,583,292,926 +2.55% 17
Iraq Iraq 106,392,603,006 +4% 26
Kenya Kenya 76,018,084,951 +4.07% 30
Cambodia Cambodia 23,547,121,923 +2.39% 53
Libya Libya 18,572,995,981 +2.3% 57
Sri Lanka Sri Lanka 60,454,403,606 +4.01% 35
Macao SAR China Macao SAR China 13,451,119,682 +4.9% 64
Morocco Morocco 78,342,642,932 +3.63% 29
Moldova Moldova 8,487,851,770 +5.16% 83
Madagascar Madagascar 10,497,465,729 +2.6% 75
Mexico Mexico 978,098,078,230 +2.83% 4
North Macedonia North Macedonia 8,943,374,999 +1.21% 82
Mali Mali 16,429,641,017 +4.12% 59
Malta Malta 9,385,795,683 +5.72% 81
Montenegro Montenegro 4,774,546,649 +8.74% 91
Mongolia Mongolia 11,614,038,773 +12.9% 68
Mozambique Mozambique 14,481,881,051 -6% 63
Mauritius Mauritius 9,518,952,137 +3.12% 80
Malaysia Malaysia 256,175,698,644 +5.11% 18
Namibia Namibia 11,251,267,377 +13.3% 71
Niger Niger 10,295,135,760 +3.1% 78
Nicaragua Nicaragua 12,498,908,268 +8.64% 65
Nepal Nepal 29,842,780,904 +1.07% 50
Pakistan Pakistan 394,142,529,738 +6.32% 11
Peru Peru 152,863,669,149 +2.77% 24
Philippines Philippines 324,527,488,378 +4.86% 14
Poland Poland 376,144,608,038 +3.01% 13
Paraguay Paraguay 30,269,103,949 +5.22% 49
Palestinian Territories Palestinian Territories 10,000,400,000 -32.5% 79
Romania Romania 173,554,068,230 +5.99% 23
Russia Russia 906,763,347,523 +5.4% 7
Rwanda Rwanda 10,960,199,645 +4.2% 74
Saudi Arabia Saudi Arabia 418,858,942,191 +2.71% 9
Sudan Sudan 26,173,435,424 -16.2% 51
Senegal Senegal 18,411,629,201 +3% 58
Singapore Singapore 146,660,484,062 +4.83% 25
Sierra Leone Sierra Leone 10,459,354,602 +4.19% 76
El Salvador El Salvador 22,308,982,885 +3.21% 54
Somalia Somalia 11,495,749,354 +5.95% 69
Serbia Serbia 36,646,949,434 +4.18% 46
Seychelles Seychelles 1,520,676,937 +11.6% 98
Chad Chad 11,085,215,317 +2.97% 72
Togo Togo 6,396,772,340 +5.4% 87
Thailand Thailand 280,946,564,825 +4.41% 15
Tunisia Tunisia 36,951,900,592 +4.08% 45
Turkey Turkey 971,981,088,671 +3.66% 5
Tanzania Tanzania 39,768,555,564 +3.1% 43
Uganda Uganda 34,559,881,883 +0.652% 47
Ukraine Ukraine 73,534,011,900 +6.68% 32
United States United States 15,619,038,363,915 +2.76% 1
Uzbekistan Uzbekistan 98,849,729,326 +7.46% 27
Samoa Samoa 770,174,850 +10.7% 101
Kosovo Kosovo 7,829,001,361 +5.7% 86
South Africa South Africa 245,459,087,569 +1.03% 19
Zimbabwe Zimbabwe 15,227,623,062 +2.98% 60

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