Households and NPISHs final consumption expenditure (% of GDP)

Source: worldbank.org, 03.09.2025

Year: 2024

Flag Country Value Value change, % Rank
Angola Angola 55.3 -1.99% 86
Albania Albania 69.6 -0.897% 40
Argentina Argentina 68.1 +3.26% 45
Armenia Armenia 66.5 +1.79% 53
Australia Australia 51.2 +1.81% 89
Azerbaijan Azerbaijan 55.4 +2.69% 84
Benin Benin 58.9 -2.87% 76
Burkina Faso Burkina Faso 60.6 -6.17% 72
Bangladesh Bangladesh 70.1 +2.27% 38
Bulgaria Bulgaria 57.6 -0.153% 80
Bahamas Bahamas 64.3 +1.42% 60
Bosnia & Herzegovina Bosnia & Herzegovina 69 +0.987% 42
Belarus Belarus 56.8 +5.32% 83
Bermuda Bermuda 45.6 +0.288% 95
Brazil Brazil 63.8 +1.35% 62
Brunei Brunei 28.5 +3.29% 103
Botswana Botswana 45.3 +5.6% 96
Central African Republic Central African Republic 94.7 -2.79% 5
Chile Chile 58.1 -3.86% 79
Côte d’Ivoire Côte d’Ivoire 66 -3.45% 55
Cameroon Cameroon 74.5 +0.811% 32
Congo - Kinshasa Congo - Kinshasa 62.7 -0.305% 65
Congo - Brazzaville Congo - Brazzaville 47.4 +7.47% 93
Colombia Colombia 73.1 -0.667% 33
Comoros Comoros 104 -0.162% 2
Cape Verde Cape Verde 74.7 -2.8% 30
Costa Rica Costa Rica 63.9 -0.916% 61
Cyprus Cyprus 58.9 -1.34% 77
Djibouti Djibouti 73 +3.26% 34
Dominican Republic Dominican Republic 67.7 -0.53% 49
Ecuador Ecuador 64.9 -1.16% 57
Egypt Egypt 87.6 +10.9% 9
Ethiopia Ethiopia 80.2 +1.59% 20
Gabon Gabon 33.7 +0.972% 99
Georgia Georgia 71.3 -0.177% 36
Ghana Ghana 84.1 -1.62% 15
Guinea Guinea 67.4 -4.56% 50
Gambia Gambia 83.2 -3.17% 16
Guinea-Bissau Guinea-Bissau 77 -2.77% 24
Equatorial Guinea Equatorial Guinea 52.9 +0.453% 87
Guatemala Guatemala 88 +0.697% 7
Hong Kong SAR China Hong Kong SAR China 67.4 -3.72% 51
Honduras Honduras 86 -1.09% 12
Croatia Croatia 57 -0.495% 82
Haiti Haiti 99.8 -0.352% 3
Indonesia Indonesia 55.4 +1.79% 85
India India 61.5 +2.16% 68
Iran Iran 50.5 +0.381% 90
Iraq Iraq 41.2 +3.6% 98
Kenya Kenya 75.5 -1.88% 29
Cambodia Cambodia 59.8 -0.91% 73
Libya Libya 32.7 +0.888% 100
Sri Lanka Sri Lanka 68.7 -2.95% 43
Macao SAR China Macao SAR China 29 -3.72% 102
Morocco Morocco 61.3 -0.09% 70
Moldova Moldova 86.8 +1.25% 10
Madagascar Madagascar 69.8 -2.45% 39
Mexico Mexico 70.3 +0.65% 37
North Macedonia North Macedonia 67.9 -0.824% 48
Mali Mali 71.9 -0.85% 35
Malta Malta 46.6 -0.222% 94
Montenegro Montenegro 76.3 +4.29% 25
Mongolia Mongolia 49.8 +11.8% 91
Mozambique Mozambique 69 -11.5% 41
Mauritius Mauritius 68.6 -1.71% 44
Malaysia Malaysia 60.8 +0.508% 71
Namibia Namibia 79.3 +7.46% 22
Niger Niger 59.2 -7.44% 75
Nicaragua Nicaragua 80.6 +3.05% 19
Nepal Nepal 86.3 +0.214% 11
Pakistan Pakistan 85.2 +2.31% 13
Peru Peru 61.6 -3.45% 67
Philippines Philippines 76.1 -0.488% 27
Poland Poland 57.6 -0.142% 81
Puerto Rico Puerto Rico 76 -1.43% 28
Paraguay Paraguay 67 +1.49% 52
Palestinian Territories Palestinian Territories 95.5 -3.49% 4
Romania Romania 63.5 +2.6% 63
Russia Russia 49.4 +0.223% 92
Rwanda Rwanda 64.9 -13% 58
Saudi Arabia Saudi Arabia 45 +3.3% 97
Sudan Sudan 80.7 +0.0368% 18
Senegal Senegal 65.8 -2.37% 56
Singapore Singapore 31.5 -0.317% 101
Sierra Leone Sierra Leone 87.6 +1.56% 8
El Salvador El Salvador 79.6 +0.568% 21
Somalia Somalia 124 +0.376% 1
Serbia Serbia 62.7 +0.231% 64
Seychelles Seychelles 74.6 +7.96% 31
Chad Chad 61.3 -3.21% 69
Togo Togo 78.3 +0.25% 23
Thailand Thailand 58.2 +1.29% 78
Tunisia Tunisia 76.2 -2.73% 26
Turkey Turkey 59.4 +0.103% 74
Tanzania Tanzania 52.9 -2.25% 88
Uganda Uganda 66.3 -7.47% 54
Ukraine Ukraine 62.4 +2.27% 66
United States United States 67.9 +0.0422% 47
Uzbekistan Uzbekistan 68 -0.724% 46
Samoa Samoa 80.8 -7.9% 17
Kosovo Kosovo 84.3 +0.175% 14
South Africa South Africa 64.8 +0.701% 59
Zimbabwe Zimbabwe 91.5 +20% 6

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

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

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