General government final consumption expenditure (constant 2015 US$)

Source: worldbank.org, 03.09.2025

Year: 2024

Flag Country Value Value change, % Rank
Angola Angola 7,849,781,009 -1.88% 43
Albania Albania 1,924,166,000 +3.63% 78
Argentina Argentina 107,223,667,875 -3.18% 10
Armenia Armenia 1,445,957,870 -22.3% 85
Australia Australia 399,887,010,329 +3.7% 2
Benin Benin 1,904,563,127 +0.932% 81
Burkina Faso Burkina Faso 3,746,895,453 +7.09% 59
Bangladesh Bangladesh 20,173,932,081 +9.77% 28
Bulgaria Bulgaria 11,623,086,115 +4.55% 34
Bahamas Bahamas 2,186,045,324 +0.869% 72
Bosnia & Herzegovina Bosnia & Herzegovina 4,123,166,082 +2.16% 57
Belarus Belarus 8,165,058,519 +0.0646% 41
Bermuda Bermuda 827,149,182 -1.18% 92
Brazil Brazil 385,573,609,960 +1.9% 3
Brunei Brunei 3,279,820,144 +0.672% 66
Botswana Botswana 5,975,276,098 +5.82% 46
Central African Republic Central African Republic 226,792,684 +42.8% 98
Chile Chile 47,402,331,484 +3.01% 20
Côte d’Ivoire Côte d’Ivoire 6,940,658,839 +3.12% 45
Cameroon Cameroon 4,565,465,668 +2.69% 55
Congo - Kinshasa Congo - Kinshasa 2,748,425,592 +6.84% 67
Congo - Brazzaville Congo - Brazzaville 875,457,481 +0.501% 90
Colombia Colombia 57,651,928,271 -0.522% 16
Comoros Comoros 139,130,678 +1.74% 101
Cape Verde Cape Verde 478,186,405 +2.61% 96
Costa Rica Costa Rica 11,256,986,652 +0.688% 35
Cyprus Cyprus 5,038,457,273 +1.51% 50
Djibouti Djibouti 774,624,127 +12.6% 93
Dominican Republic Dominican Republic 10,324,433,020 +4.11% 36
Ecuador Ecuador 14,917,413,859 -1.22% 32
Egypt Egypt 49,049,934,073 +0.242% 19
Ethiopia Ethiopia 5,073,497,227 -5.15% 49
Gabon Gabon 2,040,013,450 +4.49% 76
Georgia Georgia 3,687,832,499 +24.7% 60
Ghana Ghana 4,982,476,017 +3.66% 52
Guinea Guinea 2,147,616,775 +3.44% 74
Gambia Gambia 177,746,611 +7.13% 99
Guinea-Bissau Guinea-Bissau 299,605,454 +12.7% 97
Equatorial Guinea Equatorial Guinea 3,313,064,713 +8.2% 64
Guatemala Guatemala 8,935,894,511 +0.935% 38
Hong Kong SAR China Hong Kong SAR China 41,586,252,263 +0.961% 22
Honduras Honduras 4,209,579,490 +5.29% 56
Croatia Croatia 15,030,097,122 +4.52% 30
Haiti Haiti 1,923,260,145 +1.6% 79
Indonesia Indonesia 103,543,873,987 +6.61% 11
India India 335,521,836,179 +3.77% 4
Iran Iran 64,816,113,255 +2.47% 14
Iraq Iraq 52,565,760,499 +16.6% 18
Kenya Kenya 14,056,352,400 +1.98% 33
Cambodia Cambodia 2,344,586,957 +3.42% 70
Libya Libya 19,872,896,275 +5.54% 29
Sri Lanka Sri Lanka 9,265,146,716 -1.85% 37
Macao SAR China Macao SAR China 4,971,869,337 -5.07% 53
Morocco Morocco 27,181,794,316 +4.08% 26
Moldova Moldova 1,200,304,956 -3.6% 86
Madagascar Madagascar 1,497,752,883 -4.13% 84
Mexico Mexico 155,778,948,415 +1.57% 8
North Macedonia North Macedonia 1,871,085,093 +9.12% 82
Mali Mali 3,570,949,574 +6% 61
Malta Malta 3,387,276,913 +7.33% 63
Montenegro Montenegro 894,900,509 +1.71% 89
Mongolia Mongolia 3,546,318,759 +18.3% 62
Mozambique Mozambique 5,016,671,593 -4.98% 51
Mauritius Mauritius 2,018,252,178 +5.7% 77
Malaysia Malaysia 55,347,968,528 +4.65% 17
Namibia Namibia 3,305,006,756 +3.18% 65
Niger Niger 2,173,342,355 -0.308% 73
Nicaragua Nicaragua 2,049,375,699 -1.19% 75
Nepal Nepal 2,568,485,915 +13.3% 68
Pakistan Pakistan 33,532,599,987 -11.8% 24
Peru Peru 34,579,747,647 +3.25% 23
Philippines Philippines 64,584,788,819 +7.28% 15
Poland Poland 124,311,367,555 +8.23% 9
Paraguay Paraguay 5,704,232,231 +7.13% 48
Palestinian Territories Palestinian Territories 2,277,200,000 -25% 71
Romania Romania 31,272,606,728 +0.718% 25
Russia Russia 306,481,020,513 +4.8% 5
Rwanda Rwanda 2,548,792,613 +14.8% 69
Saudi Arabia Saudi Arabia 219,736,134,831 +1.88% 6
Sudan Sudan 1,905,252,272 -0.551% 80
Senegal Senegal 4,052,624,990 +7.17% 58
Singapore Singapore 45,467,895,914 +8.33% 21
Sierra Leone Sierra Leone 553,405,914 +0.836% 94
El Salvador El Salvador 4,917,306,344 +2.36% 54
Somalia Somalia 854,509,101 +10.2% 91
Serbia Serbia 8,892,203,780 +2.48% 39
Seychelles Seychelles 518,911,932 +8.05% 95
Chad Chad 1,843,455,018 +2.97% 83
Togo Togo 897,845,660 +9.49% 88
Thailand Thailand 75,453,076,405 +2.52% 12
Tunisia Tunisia 8,263,861,208 -1.08% 40
Turkey Turkey 171,657,853,720 +1.17% 7
Tanzania Tanzania 7,878,052,940 +9.46% 42
Uganda Uganda 5,805,806,752 +13.9% 47
Ukraine Ukraine 21,334,416,669 -4.5% 27
United States United States 3,009,273,268,437 +2.46% 1
Uzbekistan Uzbekistan 15,003,399,476 +1.15% 31
Samoa Samoa 158,181,772 +7.33% 100
Kosovo Kosovo 1,124,226,406 +0.204% 87
South Africa South Africa 72,017,776,252 +0.387% 13
Zimbabwe Zimbabwe 7,667,339,980 +5.38% 44

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