GNI (constant 2015 US$)

Source: worldbank.org, 03.09.2025

Year: 2024

Flag Country Value Value change, % Rank
Angola Angola 96,110,619,558 +2.75% 37
Argentina Argentina 559,491,898,313 -5.01% 13
Armenia Armenia 15,529,056,370 +2.6% 73
Australia Australia 1,700,601,140,201 +0.74% 7
Benin Benin 18,887,628,839 +7.83% 69
Burkina Faso Burkina Faso 19,430,827,269 +11.8% 68
Bangladesh Bangladesh 358,008,735,614 +4.56% 24
Bulgaria Bulgaria 65,318,014,024 +2.51% 45
Bosnia & Herzegovina Bosnia & Herzegovina 21,339,358,308 +2.97% 63
Belarus Belarus 62,288,465,143 +4.19% 47
Bermuda Bermuda 7,832,334,312 +5.59% 86
Brazil Brazil 1,982,780,769,104 +2.95% 5
Brunei Brunei 14,725,050,290 +2.3% 77
Central African Republic Central African Republic 2,654,372,829 +1.54% 90
Canada Canada 1,851,799,988,902 +1.45% 6
Chile Chile 295,980,008,524 +3.53% 25
Côte d’Ivoire Côte d’Ivoire 75,628,607,654 +11.1% 41
Cameroon Cameroon 42,454,317,425 +2.13% 53
Congo - Kinshasa Congo - Kinshasa 124,899,736,849 +12.5% 31
Colombia Colombia 372,763,113,154 +2.6% 22
Comoros Comoros 1,298,335,046 +3.42% 95
Cape Verde Cape Verde 2,491,783,622 +9.14% 91
Costa Rica Costa Rica 69,277,052,004 +4.31% 43
Cyprus Cyprus 27,540,874,006 +1.75% 56
Germany Germany 3,823,996,962,813 +0.257% 2
Djibouti Djibouti 3,794,593,747 +3.87% 89
Denmark Denmark 376,325,360,950 +3.95% 19
Dominican Republic Dominican Republic 99,914,847,187 +3.86% 35
Ecuador Ecuador 110,745,923,128 +0.805% 32
Egypt Egypt 445,543,710,421 +0.619% 15
Gabon Gabon 24,182,567,251 +2.37% 61
Georgia Georgia 24,263,987,475 +13.1% 60
Ghana Ghana 76,928,987,039 +11% 40
Guinea Guinea 15,027,096,749 +11.3% 75
Gambia Gambia 1,964,069,934 -0.408% 93
Guinea-Bissau Guinea-Bissau 1,714,599,254 +4.92% 94
Equatorial Guinea Equatorial Guinea 7,830,053,813 -1.21% 87
Guatemala Guatemala 84,925,031,311 +5.63% 39
Hong Kong SAR China Hong Kong SAR China 374,933,293,094 +4.97% 20
Honduras Honduras 25,946,982,956 +6% 59
Croatia Croatia 69,259,765,106 +5.72% 44
Haiti Haiti 14,987,491,471 -2.61% 76
Indonesia Indonesia 1,192,005,927,130 +4.85% 9
India India 3,429,362,694,363 +4.15% 3
Iraq Iraq 256,675,154,151 -1.85% 27
Israel Israel 421,537,656,038 +1.81% 17
Italy Italy 2,013,816,102,363 +1.15% 4
Kenya Kenya 105,171,339,368 +4.86% 33
Cambodia Cambodia 38,558,013,749 +2.31% 54
Libya Libya 53,245,933,190 +5.02% 49
Sri Lanka Sri Lanka 88,184,509,870 +7.25% 38
Morocco Morocco 134,033,804,187 +4.78% 30
Moldova Moldova 10,057,201,766 +3.88% 81
Madagascar Madagascar 13,756,087,359 +2.84% 78
Mexico Mexico 1,385,177,896,871 +1.07% 8
North Macedonia North Macedonia 12,244,461,056 +3.78% 80
Mali Mali 23,675,486,322 +5.93% 62
Malta Malta 16,965,937,151 +5.32% 71
Montenegro Montenegro 5,694,454,247 +2.07% 88
Mongolia Mongolia 20,350,619,986 +4.23% 67
Mozambique Mozambique 20,442,685,960 +3.32% 66
Malaysia Malaysia 409,909,999,529 +4.75% 18
Namibia Namibia 13,321,988,808 +5.71% 79
Niger Niger 18,683,990,061 +13.5% 70
Nicaragua Nicaragua 15,630,171,523 +7.23% 72
Nepal Nepal 36,710,282,661 +4.05% 55
Pakistan Pakistan 434,263,687,975 +4.01% 16
Peru Peru 233,535,526,496 +5.93% 29
Philippines Philippines 487,243,454,587 +7.56% 14
Poland Poland 633,459,780,724 +2.86% 11
Portugal Portugal 242,911,789,491 +4.22% 28
Paraguay Paraguay 43,957,734,112 +2.87% 52
Romania Romania 261,081,663,144 +3.19% 26
Rwanda Rwanda 15,106,833,469 +14% 74
Saudi Arabia Saudi Arabia 934,871,874,328 -1.48% 10
Senegal Senegal 27,243,084,627 +5.15% 57
Singapore Singapore 374,215,088,496 +6.18% 21
Sierra Leone Sierra Leone 9,272,933,455 -2.79% 83
El Salvador El Salvador 26,069,750,336 +1.93% 58
Somalia Somalia 9,409,409,028 +5.99% 82
Serbia Serbia 54,720,598,121 +4.07% 48
Slovakia Slovakia 98,514,296,501 +2.33% 36
Sweden Sweden 596,329,401,891 +1.05% 12
Seychelles Seychelles 1,968,136,456 +2.77% 92
Chad Chad 20,538,106,602 +2.1% 65
Togo Togo 8,517,631,813 +5.14% 85
Tunisia Tunisia 47,794,367,714 +1.35% 50
Tanzania Tanzania 74,498,101,486 +6.04% 42
Uganda Uganda 46,046,904,635 +3.73% 51
Ukraine Ukraine 102,110,212,666 +3.15% 34
Uruguay Uruguay 62,818,228,855 +2.57% 46
United States United States 22,746,727,415,547 +2.63% 1
Samoa Samoa 984,950,445 +12.3% 96
Kosovo Kosovo 8,774,801,289 +5.25% 84
South Africa South Africa 368,153,551,100 +0.146% 23
Zimbabwe Zimbabwe 20,983,771,245 +2.08% 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 = 'NY.GNP.MKTP.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 <- 'NY.GNP.MKTP.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))