Changes in inventories (current US$)

Source: worldbank.org, 03.09.2025

Year: 2024

Flag Country Value Value change, % Rank
Argentina Argentina -717,508,320 -114% 88
Armenia Armenia 123,568,864 +21.2% 62
Australia Australia 2,176,589,599 -81.5% 28
Austria Austria -10,596,929,082 -509% 104
Azerbaijan Azerbaijan 3,184,823,529 +1,184% 23
Belgium Belgium -2,478,867,750 -142% 98
Benin Benin 85,100,025 +5.79% 64
Burkina Faso Burkina Faso 2,459,271,492 +126% 26
Bulgaria Bulgaria 2,714,627,716 +151% 24
Bahamas Bahamas 163,200,000 +0.741% 60
Belarus Belarus 1,546,334,906 -1.06% 32
Brazil Brazil -2,684,573,779 -81.2% 99
Brunei Brunei 31,312,014 +2.28% 69
Botswana Botswana 1,493,744,344 +65.2% 33
Canada Canada 13,610,009,920 -39.9% 11
Switzerland Switzerland 18,104,836,119 +1,143% 7
Chile Chile -824,629,510 -72.1% 89
Côte d’Ivoire Côte d’Ivoire -5,304,805 -100% 72
Congo - Kinshasa Congo - Kinshasa 346,433,585 +17% 51
Congo - Brazzaville Congo - Brazzaville 47,991,545 +2.22% 66
Colombia Colombia 2,380,698,669 -943% 27
Costa Rica Costa Rica -149,222,905 -81.3% 77
Cyprus Cyprus -572,299,083 +109% 86
Czechia Czechia -433,909,304 -118% 81
Germany Germany 8,893,920,312 +13.7% 14
Djibouti Djibouti -1,134,710,925 +4.32% 92
Denmark Denmark -2,469,040,233 -337% 97
Dominican Republic Dominican Republic 1,089,899,034 -177% 36
Ecuador Ecuador 90,089,400 -90.7% 63
Egypt Egypt 5,052,340,874 -6.09% 21
Spain Spain 16,198,906,095 -22.8% 10
Estonia Estonia 32,657,584 -134% 68
Finland Finland 598,556,399 -154% 44
France France -12,282,745,321 -768% 105
United Kingdom United Kingdom 17,987,906,082 -229% 8
Georgia Georgia 258,785,450 -76.2% 55
Ghana Ghana 132,634,773 -34% 61
Guinea Guinea -239,998,082 -0.332% 78
Guinea-Bissau Guinea-Bissau -40,301,064 -25.4% 74
Equatorial Guinea Equatorial Guinea -14,809,218 -344% 73
Greece Greece 7,465,077,432 +95.8% 16
Guatemala Guatemala 644,991,904 +360% 43
Hong Kong SAR China Hong Kong SAR China -1,891,506,392 -38.3% 95
Honduras Honduras -531,983,144 -1.36% 85
Croatia Croatia -147,104,526 -121% 76
Hungary Hungary 541,323,386 -17.1% 45
Indonesia Indonesia 31,427,482,275 +92.6% 5
India India 58,826,738,017 +5.97% 2
Ireland Ireland 1,276,319,236 -92.6% 35
Iran Iran 58,010,587,713 +19.4% 3
Iraq Iraq 24,627,110,654 +4% 6
Iceland Iceland 51,774,385 -75.9% 65
Israel Israel 3,978,403,067 -55.6% 22
Italy Italy 9,243,204,489 -2.11% 13
Kenya Kenya -1,092,264,372 +15.7% 91
Cambodia Cambodia 278,478,271 +6.94% 53
Sri Lanka Sri Lanka 7,638,848,455 +46% 15
Lithuania Lithuania -1,772,518,162 +27% 94
Luxembourg Luxembourg 761,101,804 -32.5% 40
Latvia Latvia -849,041,970 +1,746% 90
Macao SAR China Macao SAR China 351,257,853 -9.83% 49
Morocco Morocco 5,587,744,422 +19.3% 19
Moldova Moldova 208,526,928 +92.5% 57
Mexico Mexico -76,846,048 -155% 75
Mali Mali -289,149,120 -623% 79
Malta Malta 173,370,396 +9.68% 59
Montenegro Montenegro 669,507,025 +11.6% 42
Mongolia Mongolia 1,849,547,221 +6.12% 29
Mauritius Mauritius 35,010,479 -173% 67
Malaysia Malaysia 5,469,946,314 -57.6% 20
Namibia Namibia 261,299,568 +9.96% 54
Niger Niger 1,954 -100% 71
Nicaragua Nicaragua 350,468,899 +181% 50
Netherlands Netherlands -5,464,938,987 +248% 103
Norway Norway 10,385,327,646 -17.3% 12
Nepal Nepal 2,605,127,990 -3.24% 25
Pakistan Pakistan 5,969,149,692 +10.4% 18
Philippines Philippines 501,646,419 -149% 46
Poland Poland 6,925,773,146 -447% 17
Puerto Rico Puerto Rico 282,600,000 -38% 52
Portugal Portugal 812,572,242 -30.7% 38
Paraguay Paraguay 830,918,111 -498% 37
Palestinian Territories Palestinian Territories 222,400,000 -19.2% 56
Romania Romania -5,337,378,219 +23% 102
Russia Russia 90,560,960,520 -12.7% 1
Rwanda Rwanda -455,929,043 +3.35% 82
Saudi Arabia Saudi Arabia 17,946,400,000 +11.7% 9
Senegal Senegal 179,410,953 -90.7% 58
Singapore Singapore 1,662,733,969 -129% 31
El Salvador El Salvador -652,160,000 +50.7% 87
Serbia Serbia 1,726,429,054 +70.8% 30
Slovakia Slovakia -371,829,080 -78.3% 80
Slovenia Slovenia 795,733,649 +29.2% 39
Sweden Sweden 1,452,169,565 -267% 34
Chad Chad 703,740,414 +4.35% 41
Thailand Thailand -3,554,730,047 +46.4% 100
Turkey Turkey -72,180,902,309 +241% 106
Tanzania Tanzania -1,249,097,124 -8.38% 93
Uganda Uganda 403,643,398 +13.7% 47
Ukraine Ukraine -493,473,779 -85.3% 83
Uruguay Uruguay -519,188,088 -296% 84
United States United States 51,950,000,000 +24.6% 4
Uzbekistan Uzbekistan -4,321,791,178 -293% 101
Samoa Samoa 23,019,972 -3.57% 70
South Africa South Africa -2,311,333,433 -201% 96
Zimbabwe Zimbabwe 395,435,308 -72.5% 48

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