Net lending (+) / net borrowing (-) (% of GDP)

Source: worldbank.org, 01.09.2025

Year: 2023

Flag Country Value Value change, % Rank
Albania Albania -1.4 -77.1% 29
United Arab Emirates United Arab Emirates 0.758 +760% 12
Argentina Argentina -3.61 -18.5% 51
Armenia Armenia -1.9 -3.76% 35
Austria Austria -2.03 -48.2% 39
Burkina Faso Burkina Faso -6.75 -38.2% 76
Bulgaria Bulgaria -1.89 -40.1% 34
Bahamas Bahamas -3.5 -32.7% 50
Bosnia & Herzegovina Bosnia & Herzegovina -0.968 -1,015% 22
Belarus Belarus 1.33 -181% 10
Brazil Brazil -6.87 +53.8% 78
Botswana Botswana 0.039 -4.76% 17
Canada Canada 0.501 -279% 14
Switzerland Switzerland 0.146 -73.2% 16
Chile Chile -2.39 -311% 45
Côte d’Ivoire Côte d’Ivoire -5.49 -23.5% 72
Colombia Colombia -2.04 -61.5% 40
Costa Rica Costa Rica 0.439 -939% 15
Cyprus Cyprus 1.94 -23.8% 9
Denmark Denmark 3.13 -5.9% 5
Dominican Republic Dominican Republic -3.26 +1.1% 48
Spain Spain -2.3 -27.6% 43
Estonia Estonia -2.27 +228% 42
Ethiopia Ethiopia -2.31 -42.1% 44
Finland Finland -1.91 +5,889% 36
Fiji Fiji -4 -57.8% 54
France France -5.13 +9.32% 70
United Kingdom United Kingdom -6.86 +20.9% 77
Georgia Georgia -2.02 -20% 38
Guinea-Bissau Guinea-Bissau -8.72 +37.4% 81
Greece Greece -1.05 -54% 24
Guatemala Guatemala -1.26 -26.4% 28
Croatia Croatia -1.45 +223% 31
Iceland Iceland -1.09 -58.2% 25
Israel Israel -5.15 -2,557% 71
Italy Italy -7.33 -8.21% 80
Jordan Jordan -5.13 +14.3% 69
Kazakhstan Kazakhstan -1.14 -226% 27
Kenya Kenya -9.92 +29.1% 83
Kyrgyzstan Kyrgyzstan 2.56 +678% 7
Cambodia Cambodia -3.33 +808% 49
Kiribati Kiribati -1.45 -85.7% 30
South Korea South Korea -1.1 -41.5% 26
Sri Lanka Sri Lanka -9.26 +0.368% 82
Lithuania Lithuania -0.839 -6.52% 21
Luxembourg Luxembourg -0.356 -189% 19
Latvia Latvia -2 -59.3% 37
Macao SAR China Macao SAR China 2.19 -106% 8
Morocco Morocco -4.4 -15.6% 59
Moldova Moldova -5.02 +60.4% 67
Madagascar Madagascar -5.1 +31.7% 68
Mexico Mexico -4.2 -2.66% 56
North Macedonia North Macedonia -4.61 +7.95% 62
Malta Malta -4.57 -12.5% 61
Mauritius Mauritius -5.79 +4.72% 73
Malaysia Malaysia -5 -9.59% 66
Namibia Namibia -1.85 -72.6% 33
Nicaragua Nicaragua 2.66 +105% 6
Netherlands Netherlands -0.366 +34.1% 20
Norway Norway 17.3 -34% 1
Philippines Philippines -6.11 -14.7% 74
Papua New Guinea Papua New Guinea -4.34 -17.3% 58
Poland Poland -4.54 +51.1% 60
Portugal Portugal 1.3 -575% 11
Paraguay Paraguay -3.82 +44.7% 53
Russia Russia 3.32 +128% 4
Rwanda Rwanda -4.09 +5.17% 55
Saudi Arabia Saudi Arabia -1.77 -179% 32
Senegal Senegal -4.94 -11.3% 65
El Salvador El Salvador -2.82 +3.32% 47
Somalia Somalia 0.000575 +7,877% 18
Slovenia Slovenia -2.66 -5.59% 46
Togo Togo -6.6 -17.6% 75
Thailand Thailand -2.26 -53.4% 41
Tajikistan Tajikistan -1.02 +157% 23
Tonga Tonga 6.11 -797% 2
Turkey Turkey -4.72 +49.4% 63
Tanzania Tanzania -3.69 +17.2% 52
Uganda Uganda -4.94 -26.7% 64
Ukraine Ukraine -19.6 +15.2% 84
United States United States -7.14 +61.6% 79
Uzbekistan Uzbekistan -4.27 +20.2% 57
Vanuatu Vanuatu 0.703 -113% 13
Samoa Samoa 4.89 -25.5% 3

                    
# 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 = 'GC.NLD.TOTL.GD.ZS'

# 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 <- 'GC.NLD.TOTL.GD.ZS'

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