General government final consumption expenditure (% of GDP)

Source: worldbank.org, 03.09.2025

Year: 2024

Flag Country Value Value change, % Rank
Angola Angola 6.27 +21.2% 96
Albania Albania 12.8 +6.45% 62
Argentina Argentina 15 -8.28% 43
Armenia Armenia 10.7 -24.1% 76
Australia Australia 22.2 +4.29% 8
Azerbaijan Azerbaijan 14.4 +3.99% 49
Benin Benin 9.01 -5.15% 84
Burkina Faso Burkina Faso 18.8 -6.08% 21
Bangladesh Bangladesh 5.91 +4.29% 97
Bulgaria Bulgaria 19.7 +6.84% 15
Bahamas Bahamas 12.9 -1.54% 60
Belarus Belarus 19 +6.45% 18
Bermuda Bermuda 11 -3.05% 74
Brazil Brazil 18.8 -1.17% 19
Brunei Brunei 23 +0.726% 6
Botswana Botswana 32.1 +9.64% 3
Central African Republic Central African Republic 9.67 +16% 81
Chile Chile 15.1 -1.52% 42
Côte d’Ivoire Côte d’Ivoire 8.96 -0.538% 85
Cameroon Cameroon 10.5 -0.371% 78
Congo - Kinshasa Congo - Kinshasa 8.12 +3.32% 90
Congo - Brazzaville Congo - Brazzaville 13.4 +2.15% 55
Colombia Colombia 14.7 +0.419% 45
Comoros Comoros 9.18 -2.75% 83
Cape Verde Cape Verde 20.7 -4.67% 12
Costa Rica Costa Rica 14.7 -1.31% 46
Cyprus Cyprus 18.6 -0.217% 22
Djibouti Djibouti 18.8 +10.3% 20
Dominican Republic Dominican Republic 11.5 +2.03% 71
Ecuador Ecuador 13.3 -2.16% 56
Egypt Egypt 6.27 -7.63% 95
Ethiopia Ethiopia 5.53 -12.5% 100
Gabon Gabon 12.2 +3.09% 68
Georgia Georgia 13.4 +10.7% 51
Ghana Ghana 4.83 -12.2% 102
Guinea Guinea 13.4 -0.603% 54
Gambia Gambia 8.46 +14.7% 88
Guinea-Bissau Guinea-Bissau 17.8 +10.5% 30
Equatorial Guinea Equatorial Guinea 28.3 +8.17% 4
Guatemala Guatemala 10.9 -3.05% 75
Hong Kong SAR China Hong Kong SAR China 12.8 -3.55% 61
Honduras Honduras 15.5 +4.01% 40
Croatia Croatia 22.6 +6.32% 7
Haiti Haiti 5.69 -8.54% 99
Indonesia Indonesia 7.73 +3.7% 91
India India 10.1 -1.56% 79
Iran Iran 12.9 +0.304% 59
Iraq Iraq 20.3 +15.9% 14
Kenya Kenya 11.5 -3.52% 72
Cambodia Cambodia 5.82 -4.29% 98
Libya Libya 36.7 +4.09% 2
Sri Lanka Sri Lanka 6.96 +2.69% 94
Macao SAR China Macao SAR China 12.2 -11.4% 67
Morocco Morocco 18 -0.785% 27
Moldova Moldova 17.9 -0.292% 28
Madagascar Madagascar 15.3 -2.24% 41
Mexico Mexico 11.2 +0.661% 73
North Macedonia North Macedonia 16.8 +12.5% 35
Mali Mali 13.1 +0.553% 58
Malta Malta 17.2 +2.84% 32
Montenegro Montenegro 17.9 -0.231% 29
Mongolia Mongolia 16.3 +25.4% 39
Mozambique Mozambique 17.1 -0.683% 34
Mauritius Mauritius 14.7 +2.36% 47
Malaysia Malaysia 12 +0.563% 69
Namibia Namibia 21.5 -1.28% 9
Niger Niger 11.8 -12.2% 70
Nicaragua Nicaragua 12.3 -4.91% 66
Nepal Nepal 7.44 +12.3% 93
Pakistan Pakistan 8.5 -17.5% 87
Peru Peru 13.4 -1.12% 53
Philippines Philippines 14.5 +2.02% 48
Poland Poland 20.8 +9.63% 11
Puerto Rico Puerto Rico 8.21 -2.45% 89
Paraguay Paraguay 12.6 +4.04% 63
Palestinian Territories Palestinian Territories 20.7 +2.15% 13
Romania Romania 18.3 +6.87% 25
Russia Russia 18.6 +3.31% 24
Rwanda Rwanda 17.1 +4.79% 33
Saudi Arabia Saudi Arabia 21.4 +2.04% 10
Sudan Sudan 16.5 -5.23% 37
Senegal Senegal 16.4 +3.45% 38
Singapore Singapore 10.6 +5.95% 77
Sierra Leone Sierra Leone 5.5 0.00000% 101
El Salvador El Salvador 19.2 +0.568% 17
Somalia Somalia 7.61 +4.13% 92
Serbia Serbia 17.8 +3.73% 31
Seychelles Seychelles 26.3 +7.92% 5
Chad Chad 8.72 -3.33% 86
Togo Togo 13.1 +4.44% 57
Thailand Thailand 16.7 +0.449% 36
Tunisia Tunisia 18.6 -4.57% 23
Turkey Turkey 14.7 +12.6% 44
Tanzania Tanzania 9.19 +4.87% 82
Uganda Uganda 9.98 +4.3% 80
Ukraine Ukraine 37.9 -9.4% 1
United States United States 13.4 -0.101% 52
Uzbekistan Uzbekistan 13.9 -3.71% 50
Samoa Samoa 18.2 +0.0962% 26
Kosovo Kosovo 12.3 -1.99% 65
South Africa South Africa 19.2 -0.613% 16
Zimbabwe Zimbabwe 12.5 -17.4% 64

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