Gross capital formation (current US$)

Source: worldbank.org, 03.09.2025

Year: 2024

Flag Country Value Value change, % Rank
Angola Angola 20,100,497,840 -0.407% 61
Argentina Argentina 99,571,356,365 -20.4% 30
Armenia Armenia 5,717,376,315 +11.5% 94
Australia Australia 427,382,546,112 +3.16% 11
Austria Austria 116,332,850,016 -10.5% 25
Azerbaijan Azerbaijan 15,667,588,235 +21.9% 66
Belgium Belgium 159,662,159,421 -2.35% 20
Benin Benin 7,532,176,827 +10.9% 86
Burkina Faso Burkina Faso 6,299,924,109 +37.5% 93
Bangladesh Bangladesh 138,188,871,817 +2.07% 22
Bulgaria Bulgaria 22,839,711,656 +12.9% 56
Bahamas Bahamas 4,244,200,000 +21.6% 101
Bosnia & Herzegovina Bosnia & Herzegovina 8,720,739,625 +20.1% 80
Belarus Belarus 19,625,394,924 +9.57% 62
Bermuda Bermuda 1,013,300,000 +5.46% 121
Brazil Brazil 368,532,645,337 +6.72% 13
Brunei Brunei 4,385,711,083 -1.94% 100
Botswana Botswana 7,021,613,823 +19.4% 90
Central African Republic Central African Republic 423,984,487 -30.1% 125
Canada Canada 521,502,104,640 +0.421% 8
Switzerland Switzerland 252,757,426,251 +8.74% 16
Chile Chile 76,752,978,609 -2.08% 36
Côte d’Ivoire Côte d’Ivoire 21,181,432,955 +1.94% 59
Cameroon Cameroon 10,973,360,192 +14.1% 75
Congo - Kinshasa Congo - Kinshasa 23,650,998,045 +10.3% 54
Congo - Brazzaville Congo - Brazzaville 4,219,971,933 +9.25% 102
Colombia Colombia 71,518,396,925 +18.8% 37
Comoros Comoros 181,426,032 -2.55% 128
Cape Verde Cape Verde 441,674,794 -10.1% 124
Costa Rica Costa Rica 14,940,481,178 +13.2% 68
Cyprus Cyprus 6,882,219,312 -1.61% 92
Czechia Czechia 89,849,893,396 -6.56% 34
Germany Germany 980,817,462,226 -0.00179% 3
Djibouti Djibouti -154,441,289 +21.7% 129
Denmark Denmark 92,912,275,382 -0.0136% 32
Dominican Republic Dominican Republic 33,553,778,958 +0.147% 50
Ecuador Ecuador 23,043,140,000 -7.89% 55
Egypt Egypt 50,565,105,807 -22.6% 44
Spain Spain 352,727,229,537 +3.65% 14
Estonia Estonia 11,196,918,553 -2.09% 74
Finland Finland 64,946,075,266 -4.22% 38
France France 693,522,513,262 -1.85% 4
Gabon Gabon 3,780,342,008 +7.5% 105
United Kingdom United Kingdom 652,109,524,029 +12.4% 5
Georgia Georgia 7,706,204,376 +0.157% 85
Ghana Ghana 8,246,545,828 +3.42% 82
Guinea Guinea 7,899,968,986 +50.5% 84
Gambia Gambia 977,561,341 +49.5% 122
Guinea-Bissau Guinea-Bissau 443,704,074 +12.6% 123
Equatorial Guinea Equatorial Guinea 1,143,278,272 -0.997% 120
Greece Greece 46,744,404,871 +14.7% 46
Guatemala Guatemala 18,885,780,349 +9.83% 63
Hong Kong SAR China Hong Kong SAR China 64,099,398,334 +4.23% 39
Honduras Honduras 8,343,209,291 +9.46% 81
Croatia Croatia 21,747,654,494 +10.7% 58
Haiti Haiti 2,507,120,060 -8.83% 114
Hungary Hungary 52,653,124,566 -5% 43
Indonesia Indonesia 438,387,324,293 +5.37% 10
India India 1,275,962,564,854 +5.11% 2
Ireland Ireland 100,540,763,114 -30.8% 29
Iran Iran 174,807,142,782 +11.3% 18
Iraq Iraq 82,181,561,649 +26.9% 35
Iceland Iceland 8,890,111,513 +10.8% 79
Israel Israel 126,593,278,774 -5.34% 23
Italy Italy 530,397,602,245 +0.382% 7
Kenya Kenya 20,897,192,859 +18.3% 60
Cambodia Cambodia 14,919,123,975 +5.84% 69
Libya Libya 6,919,569,687 -6.9% 91
Sri Lanka Sri Lanka 26,679,452,150 +29.6% 53
Lithuania Lithuania 17,323,870,659 -1.01% 65
Luxembourg Luxembourg 14,122,496,628 -7.22% 70
Latvia Latvia 9,204,884,973 -12% 78
Macao SAR China Macao SAR China 7,254,974,007 +2.52% 87
Morocco Morocco 46,197,988,630 +11% 47
Moldova Moldova 3,845,955,631 +14.6% 104
Madagascar Madagascar 3,938,159,103 +24.6% 103
Mexico Mexico 447,632,471,063 +4.24% 9
North Macedonia North Macedonia 4,742,492,804 +1.52% 98
Mali Mali 5,544,527,037 +0.954% 95
Malta Malta 4,573,445,462 +3.81% 99
Montenegro Montenegro 2,302,596,263 +10.8% 115
Mongolia Mongolia 8,171,156,579 +18.6% 83
Mozambique Mozambique 5,409,126,259 +29.8% 96
Mauritius Mauritius 3,168,351,389 +13% 112
Malaysia Malaysia 92,211,804,974 +2.67% 33
Namibia Namibia 3,425,125,875 -1.46% 110
Niger Niger 3,649,705,545 +0.792% 109
Nicaragua Nicaragua 4,863,242,560 +23.3% 97
Netherlands Netherlands 236,768,562,778 +2.76% 17
Norway Norway 116,168,561,458 -0.827% 26
Nepal Nepal 13,045,676,220 +2.03% 71
Pakistan Pakistan 48,260,540,405 +1.85% 45
Peru Peru 56,166,045,516 +9.67% 41
Philippines Philippines 109,332,466,585 +6.88% 28
Poland Poland 161,486,320,656 +12.5% 19
Puerto Rico Puerto Rico 18,599,200,000 +9.21% 64
Portugal Portugal 61,997,752,048 +4.51% 40
Paraguay Paraguay 10,152,331,419 +16.8% 77
Palestinian Territories Palestinian Territories 3,218,000,000 -29.6% 111
Romania Romania 93,012,199,896 +2.88% 31
Russia Russia 571,693,958,658 +2.19% 6
Rwanda Rwanda 3,693,191,920 +9.26% 107
Saudi Arabia Saudi Arabia 372,881,333,333 +4.79% 12
Sudan Sudan 1,433,914,068 +65.4% 119
Senegal Senegal 10,612,045,718 -17.5% 76
Singapore Singapore 121,521,246,669 +13.2% 24
Sierra Leone Sierra Leone 2,226,282,571 +76.1% 116
El Salvador El Salvador 7,194,730,000 +2.74% 88
Somalia Somalia 2,750,440,440 +12.1% 113
Serbia Serbia 22,773,597,763 +13.7% 57
Slovakia Slovakia 28,460,640,247 +7.3% 52
Slovenia Slovenia 15,333,620,842 -0.231% 67
Sweden Sweden 150,266,051,434 +3.23% 21
Seychelles Seychelles 372,099,665 -17.3% 126
Chad Chad 3,672,564,776 +4.35% 108
Togo Togo 2,212,641,880 +5.1% 117
Thailand Thailand 113,558,890,016 -2% 27
Tunisia Tunisia 7,132,384,812 +90.4% 89
Turkey Turkey 338,008,576,373 +0.875% 15
Tanzania Tanzania 31,326,473,002 -3.37% 51
Uganda Uganda 11,968,878,074 +7.56% 73
Ukraine Ukraine 35,559,948,655 +8.59% 49
Uruguay Uruguay 12,627,301,858 -7.67% 72
United States United States 6,345,913,000,000 +6.27% 1
Uzbekistan Uzbekistan 38,279,643,948 +7.74% 48
Samoa Samoa 350,162,228 +0.658% 127
Kosovo Kosovo 3,767,886,673 +6.03% 106
South Africa South Africa 55,805,163,094 -5.66% 42
Zimbabwe Zimbabwe 1,974,196,498 -65.6% 118

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