External balance on goods and services (% of GDP)

Source: worldbank.org, 03.09.2025

Year: 2024

Flag Country Value Value change, % Rank
Angola Angola 13.5 -8.14% 11
Albania Albania -6.85 +32.7% 93
Argentina Argentina 2.51 -320% 43
Armenia Armenia 0.554 -168% 54
Australia Australia 2.1 -52.1% 47
Austria Austria 3.31 +56.6% 41
Azerbaijan Azerbaijan 9.12 -36.9% 20
Belgium Belgium -0.0131 -97.8% 60
Benin Benin -2.96 -36.4% 75
Burkina Faso Burkina Faso -6.45 -9.07% 90
Bangladesh Bangladesh -5.86 +25.4% 83
Bulgaria Bulgaria 2.33 -43.3% 45
Bahamas Bahamas -3.68 +297% 78
Bosnia & Herzegovina Bosnia & Herzegovina -14.3 +21.9% 108
Belarus Belarus -1.79 -482% 69
Bermuda Bermuda 32.1 +19.5% 6
Brazil Brazil 0.498 -78.1% 56
Brunei Brunei 15.4 -7.07% 9
Botswana Botswana -14.9 +246% 111
Central African Republic Central African Republic -16.9 +15.8% 117
Canada Canada -0.256 -480% 62
Switzerland Switzerland 10.2 -9.9% 18
Chile Chile 3.59 +300% 36
China China 2.85 +35.6% 42
Côte d’Ivoire Côte d’Ivoire 0.529 -115% 55
Cameroon Cameroon -6.41 +60.7% 89
Congo - Kinshasa Congo - Kinshasa -4.25 +55% 80
Congo - Brazzaville Congo - Brazzaville 12.4 -29.6% 13
Colombia Colombia -4.94 +4.62% 81
Comoros Comoros -24.6 -1.7% 126
Cape Verde Cape Verde -11.4 -36.5% 103
Costa Rica Costa Rica 5.73 +6.97% 24
Cyprus Cyprus 3.58 +242% 37
Czechia Czechia 6.56 +31.3% 23
Germany Germany 3.86 -3.74% 35
Djibouti Djibouti 12.5 -19.2% 12
Denmark Denmark 10.8 +32.6% 16
Dominican Republic Dominican Republic -6.25 -13.2% 88
Ecuador Ecuador 3.35 +2,401% 39
Egypt Egypt -6.85 +206% 92
Spain Spain 4.28 +9.01% 32
Estonia Estonia 0.564 -34.1% 53
Ethiopia Ethiopia -6.21 -16.2% 87
Finland Finland 0.645 +105% 52
France France -0.735 -63.3% 65
Micronesia (Federated States of) Micronesia (Federated States of) -41.7 +0.032% 133
Gabon Gabon 36.1 -3.39% 3
United Kingdom United Kingdom -1.13 +5.45% 66
Georgia Georgia -7.61 -11.7% 94
Ghana Ghana 1.15 -236% 51
Guinea Guinea -12 +58.8% 105
Gambia Gambia -30.6 +31.9% 131
Guinea-Bissau Guinea-Bissau -15.7 +10.3% 116
Equatorial Guinea Equatorial Guinea 9.79 -16.8% 19
Greece Greece -5.36 +13% 82
Guatemala Guatemala -15.6 +3.14% 115
Hong Kong SAR China Hong Kong SAR China 4.06 +592% 33
Honduras Honduras -24 -0.177% 124
Croatia Croatia -3.12 +70.1% 77
Haiti Haiti -15.4 -23.7% 114
Hungary Hungary 5.55 +21.6% 26
Indonesia Indonesia 1.79 -17.4% 50
India India -2.31 +10.5% 71
Ireland Ireland 42.2 +28.2% 2
Iran Iran -3.92 +3.87% 79
Iraq Iraq 0.279 -97.2% 57
Iceland Iceland -1.14 -844% 68
Israel Israel 2.42 -14.6% 44
Italy Italy 2.29 +60.3% 46
Jordan Jordan -14.5 +8.57% 110
Kenya Kenya -8.02 -8.03% 97
Cambodia Cambodia -0.72 +70.8% 64
Kiribati Kiribati -88.6 -7.45% 136
Libya Libya 15.7 +7.92% 8
Sri Lanka Sri Lanka -2.62 +21.6% 74
Lithuania Lithuania 5.18 +32.7% 28
Luxembourg Luxembourg 32.8 +5.48% 5
Latvia Latvia -2.56 -31% 73
Macao SAR China Macao SAR China 44.4 +9.03% 1
Morocco Morocco -9.19 +10.8% 101
Moldova Moldova -25.8 +8.71% 128
Madagascar Madagascar -7.72 +8.34% 96
Mexico Mexico -1.14 -20.6% 67
North Macedonia North Macedonia -13.1 +0.663% 106
Mali Mali -5.87 -25.4% 84
Malta Malta 17.4 +3.96% 7
Montenegro Montenegro -22.7 +21.7% 123
Mongolia Mongolia -0.615 -106% 63
Mozambique Mozambique -10.2 -32.3% 102
Mauritius Mauritius -11.6 +15.5% 104
Malaysia Malaysia 5.34 +4.77% 27
Namibia Namibia -26.3 +12% 129
Niger Niger 10.3 +1,002% 17
Nicaragua Nicaragua -17.6 +32.3% 118
Netherlands Netherlands 12.1 +8.3% 14
Norway Norway 13.9 -10.1% 10
Nepal Nepal -25.3 -8.25% 127
Nauru Nauru -79.2 +38.9% 135
Pakistan Pakistan -6.67 -12.7% 91
Peru Peru 5.6 +60.6% 25
Philippines Philippines -14.3 +1.36% 109
Poland Poland 4.01 -30.1% 34
Puerto Rico Puerto Rico 9.11 +61.7% 21
Portugal Portugal 1.82 +58.2% 49
Paraguay Paraguay -2.43 -241% 72
Palestinian Territories Palestinian Territories -39.2 -10.9% 132
Romania Romania -6.1 +27.5% 86
Russia Russia 4.33 +4.19% 31
Rwanda Rwanda -8.31 -44.2% 99
Saudi Arabia Saudi Arabia 3.52 -44.2% 38
Sudan Sudan -0.0753 -70.8% 61
Senegal Senegal -15.1 -40.1% 112
Singapore Singapore 35.2 -6.01% 4
Sierra Leone Sierra Leone -22.6 +76.3% 122
El Salvador El Salvador -19.1 +1.15% 121
Somalia Somalia -54.3 +2.07% 134
Serbia Serbia -6.08 +39.9% 85
Slovakia Slovakia 0.202 -86.8% 59
Slovenia Slovenia 6.59 +2.86% 22
Sweden Sweden 4.39 +9.15% 30
Seychelles Seychelles -18 +28.7% 119
Chad Chad 10.9 -14.5% 15
Togo Togo -13.7 +0.668% 107
Thailand Thailand 3.35 +62.4% 40
Tunisia Tunisia -8.12 +45.8% 98
Turkey Turkey 0.268 -111% 58
Tanzania Tanzania -1.85 -51.5% 70
Uganda Uganda -7.66 -24.5% 95
Ukraine Ukraine -18.9 -9.45% 120
Uruguay Uruguay 5.06 +50.1% 29
United States United States -3.09 +7.58% 76
Uzbekistan Uzbekistan -15.2 -11.9% 113
Samoa Samoa -24.5 -26.1% 125
Kosovo Kosovo -30.4 -0.822% 130
South Africa South Africa 2 +507% 48
Zimbabwe Zimbabwe -8.46 +10.8% 100

                    
# 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.RSB.GNFS.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 <- 'NE.RSB.GNFS.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))