General government final consumption expenditure (current US$)

Source: worldbank.org, 03.09.2025

Year: 2024

Flag Country Value Value change, % Rank
Angola Angola 5,038,306,976 +14.8% 58
Albania Albania 3,484,984,889 +22.9% 68
Argentina Argentina 95,185,136,278 -10.1% 11
Armenia Armenia 2,767,747,053 -18.8% 75
Australia Australia 389,492,841,511 +5.75% 5
Azerbaijan Azerbaijan 10,676,764,706 +6.7% 40
Benin Benin 1,936,520,337 +3.57% 85
Burkina Faso Burkina Faso 4,361,912,988 +7.44% 60
Bangladesh Bangladesh 26,593,391,221 +7.32% 27
Bulgaria Bulgaria 22,084,636,268 +17.1% 29
Bahamas Bahamas 2,044,200,000 +2.08% 84
Belarus Belarus 14,434,974,887 +11.6% 35
Bermuda Bermuda 989,800,000 +1.48% 91
Brazil Brazil 410,160,842,541 -1.7% 2
Brunei Brunei 3,561,827,945 +3.18% 66
Botswana Botswana 6,230,128,240 +9.58% 49
Central African Republic Central African Republic 266,118,993 +24.9% 98
Chile Chile 49,762,496,203 -3.06% 23
Côte d’Ivoire Côte d’Ivoire 7,757,053,928 +8.11% 44
Cameroon Cameroon 5,412,427,720 +3.77% 55
Congo - Kinshasa Congo - Kinshasa 5,745,302,239 +9.09% 52
Congo - Brazzaville Congo - Brazzaville 2,103,511,701 +4.81% 83
Colombia Colombia 61,590,392,608 +14.7% 17
Comoros Comoros 141,978,721 +5.11% 101
Cape Verde Cape Verde 572,739,774 +3.91% 94
Costa Rica Costa Rica 13,996,009,436 +8.79% 38
Cyprus Cyprus 6,755,944,972 +6.99% 48
Djibouti Djibouti 766,751,971 +15.1% 93
Dominican Republic Dominican Republic 14,301,332,961 +5.27% 37
Ecuador Ecuador 16,569,731,000 +0.69% 32
Egypt Egypt 24,395,300,951 -9.24% 28
Gabon Gabon 2,537,066,725 +7.26% 78
Georgia Georgia 4,541,828,787 +21.5% 59
Ghana Ghana 3,999,669,268 -9.71% 62
Guinea Guinea 3,397,400,021 +12.4% 69
Gambia Gambia 212,083,321 +20.1% 99
Guinea-Bissau Guinea-Bissau 376,928,583 +12.7% 97
Equatorial Guinea Equatorial Guinea 3,618,229,047 +11.9% 65
Guatemala Guatemala 12,337,063,864 +5.15% 39
Hong Kong SAR China Hong Kong SAR China 52,256,628,249 +3.05% 21
Honduras Honduras 5,759,662,719 +12.3% 51
Croatia Croatia 20,940,560,878 +16.6% 30
Haiti Haiti 1,434,217,740 +16.2% 88
Indonesia Indonesia 107,947,174,941 +5.6% 10
India India 396,911,857,971 +5.85% 4
Iran Iran 56,441,225,556 +8.31% 20
Iraq Iraq 56,806,978,312 +20.5% 19
Kenya Kenya 14,311,962,999 +11.2% 36
Cambodia Cambodia 2,696,427,981 +4.79% 76
Libya Libya 17,127,677,451 +7.64% 31
Sri Lanka Sri Lanka 6,887,315,633 +21.4% 46
Macao SAR China Macao SAR China 6,125,548,739 -2.89% 50
Morocco Morocco 27,742,106,681 +6.09% 26
Moldova Moldova 3,253,842,658 +8.59% 70
Madagascar Madagascar 2,665,227,713 +7.32% 77
Mexico Mexico 207,033,132,352 +3.97% 7
North Macedonia North Macedonia 2,800,815,566 +19.1% 74
Mali Mali 3,491,502,311 +8.58% 67
Malta Malta 4,176,579,463 +12.6% 61
Montenegro Montenegro 1,441,418,506 +6.91% 87
Mongolia Mongolia 3,845,752,233 +45.5% 63
Mozambique Mozambique 3,825,895,498 +6.25% 64
Mauritius Mauritius 2,193,207,213 +8.54% 82
Malaysia Malaysia 50,706,260,801 +6.16% 22
Namibia Namibia 2,871,924,528 +6.39% 72
Niger Niger 2,305,240,218 +2.72% 81
Nicaragua Nicaragua 2,414,896,735 +5.17% 80
Nepal Nepal 3,192,434,123 +17.4% 71
Pakistan Pakistan 31,707,025,236 -8.96% 25
Peru Peru 38,789,864,282 +7.12% 24
Philippines Philippines 66,974,017,380 +7.75% 16
Poland Poland 190,015,130,189 +23.4% 9
Puerto Rico Puerto Rico 10,330,500,000 +3.7% 41
Paraguay Paraguay 5,608,979,102 +7.27% 53
Palestinian Territories Palestinian Territories 2,835,900,000 -21.5% 73
Romania Romania 70,108,081,072 +16.6% 15
Russia Russia 403,319,887,716 +8.42% 3
Rwanda Rwanda 2,434,107,408 +4.2% 79
Saudi Arabia Saudi Arabia 264,356,533,333 +3.63% 6
Sudan Sudan 8,241,416,949 +18.5% 43
Senegal Senegal 5,276,372,088 +8.74% 57
Singapore Singapore 57,991,233,565 +14.7% 18
Sierra Leone Sierra Leone 415,422,745 +17.7% 96
El Salvador El Salvador 6,780,140,000 +5.06% 47
Somalia Somalia 921,924,910 +14.9% 92
Serbia Serbia 15,827,039,173 +13.6% 34
Seychelles Seychelles 569,545,083 +6.93% 95
Chad Chad 1,799,377,757 +4.35% 86
Togo Togo 1,304,205,710 +13% 90
Thailand Thailand 87,863,421,344 +2.49% 12
Tunisia Tunisia 9,912,016,356 +5.75% 42
Turkey Turkey 195,101,395,937 +33.2% 8
Tanzania Tanzania 7,236,879,360 +4.5% 45
Uganda Uganda 5,353,199,656 +14.7% 56
Ukraine Ukraine 72,333,483,173 -4.64% 14
United States United States 3,916,690,000,000 +5.18% 1
Uzbekistan Uzbekistan 16,033,830,414 +7.85% 33
Samoa Samoa 194,068,287 +13.9% 100
Kosovo Kosovo 1,376,744,518 +4.38% 89
South Africa South Africa 76,974,156,286 +4.49% 13
Zimbabwe Zimbabwe 5,509,430,409 +3.64% 54

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