External debt stocks, private nonguaranteed (PNG) (DOD, current US$)

Source: worldbank.org, 01.09.2025

Year: 2023

Flag Country Value Value change, % Rank
Afghanistan Afghanistan 17,748,000 0% 85
Angola Angola 1,436,085,000 -42.8% 62
Albania Albania 4,032,196,000 +10.6% 48
Argentina Argentina 37,215,527,000 +0.534% 13
Armenia Armenia 5,821,264,000 +3.73% 42
Azerbaijan Azerbaijan 977,880,210 -15.4% 64
Benin Benin 2,286,953,000 0% 57
Burkina Faso Burkina Faso 4,864,904,000 -1.36% 45
Bangladesh Bangladesh 9,153,010,000 +16% 29
Bosnia & Herzegovina Bosnia & Herzegovina 5,062,782,000 +10.3% 44
Belarus Belarus 7,452,357,632 -18.5% 36
Belize Belize 92,975,000 -5.24% 81
Bolivia Bolivia 1,324,563,000 -5.59% 63
Brazil Brazil 317,797,409,000 +4.81% 2
Bhutan Bhutan 43,858,000 0% 84
Botswana Botswana 0 -100% 92
China China 616,235,068,133 -8.07% 1
Côte d’Ivoire Côte d’Ivoire 393,124,666 -24.9% 75
Cameroon Cameroon 360,414,000 -28.5% 76
Congo - Brazzaville Congo - Brazzaville 10,563,800 +6.33% 89
Colombia Colombia 65,483,384,000 +11.4% 9
Costa Rica Costa Rica 16,295,051,000 +0.964% 22
Djibouti Djibouti 10,000,000 -66.7% 90
Dominica Dominica 14,596,000 -18% 87
Dominican Republic Dominican Republic 8,639,939,000 +8.09% 33
Algeria Algeria 281,800,000 +20% 77
Ecuador Ecuador 9,932,836,000 +0.43% 28
Egypt Egypt 1,879,416,000 +109% 59
Fiji Fiji 742,762,000 +12.2% 67
Georgia Georgia 8,974,585,000 -4.18% 31
Ghana Ghana 7,815,454,000 +7.87% 35
Guinea Guinea 90,000,000 -14.3% 82
Guinea-Bissau Guinea-Bissau 0 92
Guatemala Guatemala 11,908,080,000 -8.06% 25
Guyana Guyana 815,745,000 +450% 66
Honduras Honduras 1,528,280,000 -3.75% 61
Haiti Haiti 5,697,000 0% 91
Indonesia Indonesia 107,908,536,588 -4.7% 7
India India 283,349,552,000 +8.81% 3
Iran Iran 727,358,000 0% 68
Jamaica Jamaica 2,762,801,000 -15.4% 55
Jordan Jordan 3,631,546,000 +0.687% 52
Kazakhstan Kazakhstan 116,715,259,084 +0.752% 6
Kenya Kenya 431,726,180 -24.2% 73
Kyrgyzstan Kyrgyzstan 4,222,487,000 +2.96% 47
Cambodia Cambodia 6,725,126,000 -9.88% 38
Laos Laos 8,972,233,550 +28% 32
Lebanon Lebanon 14,531,271,000 -15.1% 24
Liberia Liberia 76,983,230 +107% 83
Sri Lanka Sri Lanka 10,220,487,000 +9.73% 26
Lesotho Lesotho 596,910,000 -7.53% 70
Morocco Morocco 10,213,824,135 +3.68% 27
Moldova Moldova 4,008,068,000 +0.0105% 49
Madagascar Madagascar 497,998,000 -1.71% 71
Maldives Maldives 417,710,000 +2.13% 74
Mexico Mexico 219,444,453,120 -2.96% 4
North Macedonia North Macedonia 3,279,235,000 +14.4% 53
Myanmar (Burma) Myanmar (Burma) 451,539,000 +20.7% 72
Montenegro Montenegro 4,303,147,530 -2% 46
Mongolia Mongolia 22,298,450,000 +4.71% 18
Mozambique Mozambique 55,319,421,380 +4.58% 11
Mauritius Mauritius 5,820,651,000 +2.95% 43
Nigeria Nigeria 31,593,725,986 -4.13% 16
Nicaragua Nicaragua 6,376,370,000 +0.174% 40
Nepal Nepal 197,758,000 -27% 79
Pakistan Pakistan 17,446,843,000 +7.71% 21
Peru Peru 33,868,067,000 -1.39% 14
Philippines Philippines 31,812,774,000 +12.5% 15
Papua New Guinea Papua New Guinea 7,129,447,000 -20.4% 37
Paraguay Paraguay 9,102,834,000 -1.07% 30
Rwanda Rwanda 2,896,486,000 +13.3% 54
Senegal Senegal 15,918,646,000 +27.8% 23
Solomon Islands Solomon Islands 225,774,000 +15.6% 78
El Salvador El Salvador 6,441,724,000 +7.89% 39
Serbia Serbia 19,759,640,000 +12.3% 20
Suriname Suriname 890,619,000 -25% 65
Eswatini Eswatini 152,830,000 -27% 80
Togo Togo 650,000,000 0% 69
Thailand Thailand 88,000,542,734 -4% 8
Tajikistan Tajikistan 2,583,496,000 +2.88% 56
Turkmenistan Turkmenistan 15,641,275 -37.3% 86
Tunisia Tunisia 2,133,350,000 -17.1% 58
Turkey Turkey 169,021,289,000 +4.5% 5
Tanzania Tanzania 5,885,686,000 +18.2% 41
Uganda Uganda 3,842,489,000 -26.1% 50
Ukraine Ukraine 51,467,044,430 +0.723% 12
Uzbekistan Uzbekistan 22,109,233,000 +32.9% 19
Vietnam Vietnam 60,941,041,000 +1.37% 10
Samoa Samoa 12,417,000 -3.22% 88
Kosovo Kosovo 1,830,897,000 +19.4% 60
South Africa South Africa 24,193,700,000 -11.1% 17
Zambia Zambia 7,832,306,000 -1.13% 34
Zimbabwe Zimbabwe 3,802,316,717 -0.59% 51

                    
# 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 = 'DT.DOD.DPNG.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 <- 'DT.DOD.DPNG.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))