Current account balance (% of GDP)

Source: worldbank.org, 03.09.2025

Year: 2024

Flag Country Value Value change, % Rank
Angola Angola 7.85 +59.2% 12
Albania Albania -2.38 +98.7% 75
Argentina Argentina 0.993 -131% 46
Armenia Armenia -3.87 +67.4% 87
Antigua & Barbuda Antigua & Barbuda -8.15 -39.7% 98
Australia Australia -1.96 +554% 72
Austria Austria 2.42 +82.8% 36
Azerbaijan Azerbaijan 6.29 -45.3% 14
Belgium Belgium -0.855 +22.3% 61
Bangladesh Bangladesh 0.416 -58.6% 48
Bulgaria Bulgaria -1.79 +105% 71
Bahrain Bahrain 4.78 -18.2% 23
Bahamas Bahamas -6.65 -5.03% 96
Bosnia & Herzegovina Bosnia & Herzegovina -4.15 +79.2% 90
Belarus Belarus -2.53 +66.4% 78
Belize Belize -1.47 +128% 68
Brazil Brazil -2.81 +120% 81
Brunei Brunei 14.4 +12% 6
Bhutan Bhutan -20.5 -35.7% 109
Canada Canada -0.462 -27.1% 56
Switzerland Switzerland 5.04 -5.09% 21
Chile Chile -1.47 -53% 67
China China 2.26 +56.9% 38
Colombia Colombia -1.77 -21.7% 69
Cape Verde Cape Verde 3.65 -244% 29
Costa Rica Costa Rica -1.35 -5.51% 66
Cyprus Cyprus -8.39 -25.7% 100
Czechia Czechia 1.75 -1,490% 43
Germany Germany 5.73 +3.14% 18
Djibouti Djibouti 14.9 -18.9% 5
Dominica Dominica -23.2 -31.5% 111
Denmark Denmark 13 +32.3% 8
Dominican Republic Dominican Republic -3.35 -8.59% 83
Ecuador Ecuador 5.68 +210% 20
Spain Spain 3.03 +14.1% 32
Estonia Estonia -1.15 -34.6% 64
Finland Finland 0.31 -158% 50
France France 0.392 -139% 49
United Kingdom United Kingdom -2.65 -24.5% 79
Georgia Georgia -4.42 -20.5% 91
Gambia Gambia -2.97 -40.8% 82
Greece Greece -6.38 +3.47% 95
Grenada Grenada -19.5 +5.82% 108
Guatemala Guatemala 2.94 -4.34% 33
Hong Kong SAR China Hong Kong SAR China 12.9 +51.9% 9
Honduras Honduras -4.61 +15.8% 92
Croatia Croatia -1.13 -250% 63
Hungary Hungary 2.28 +549% 37
Indonesia Indonesia -0.607 +307% 58
India India -0.829 -5.65% 60
Iceland Iceland -2.53 -373% 77
Israel Israel 3.09 -14.9% 31
Italy Italy 1.13 +697% 45
Jamaica Jamaica 3.41 +16.3% 30
Japan Japan 4.82 +29.8% 22
Kazakhstan Kazakhstan -1.28 -64.4% 65
Cambodia Cambodia 0.479 -63.3% 47
St. Kitts & Nevis St. Kitts & Nevis -15.9 +37% 104
Kuwait Kuwait 29.1 -6.21% 1
St. Lucia St. Lucia -2.52 +60.6% 76
Lesotho Lesotho 3.72 -152% 28
Lithuania Lithuania 2.48 +125% 35
Luxembourg Luxembourg 13.8 +22.7% 7
Latvia Latvia -2.12 -45.7% 73
Moldova Moldova -16 +41.5% 105
Maldives Maldives -18 -15.2% 107
Mexico Mexico -0.323 +3.29% 54
North Macedonia North Macedonia -2.24 -725% 74
Malta Malta 5.69 -11.4% 19
Montenegro Montenegro -17.4 +54.1% 106
Mozambique Mozambique -11.1 +5.8% 101
Malaysia Malaysia 1.69 +8.24% 44
Namibia Namibia -15.4 +0.71% 103
Nigeria Nigeria 9.17 +419% 11
Nicaragua Nicaragua 4.15 -49.6% 27
Netherlands Netherlands 9.92 +0.779% 10
Norway Norway 17.1 -2.05% 4
Nepal Nepal 4.55 +1,174% 24
New Zealand New Zealand -6.14 -8.18% 94
Pakistan Pakistan 0.187 -161% 53
Panama Panama 1.94 -163% 42
Peru Peru 2.21 +569% 39
Philippines Philippines -3.79 +33.9% 86
Poland Poland 0.196 -89.1% 52
Portugal Portugal 2.17 +288% 40
Paraguay Paraguay -3.75 +815% 84
Palestinian Territories Palestinian Territories -21.1 +30.3% 110
Qatar Qatar 17.5 +2.18% 3
Romania Romania -8.36 +19.8% 99
Russia Russia 2.87 +20.1% 34
Saudi Arabia Saudi Arabia -0.459 -116% 55
Singapore Singapore 17.5 -0.834% 2
Solomon Islands Solomon Islands -3.76 -64.9% 85
El Salvador El Salvador -1.79 +64.6% 70
Suriname Suriname 0.197 -95.4% 51
Slovakia Slovakia -2.75 +215% 80
Slovenia Slovenia 4.46 -0.332% 25
Sweden Sweden 7.42 +6.44% 13
Thailand Thailand 2.11 +46.6% 41
Tajikistan Tajikistan 6.24 +30.9% 15
Timor-Leste Timor-Leste -28.2 +230% 112
Tonga Tonga -3.91 -33.8% 89
Trinidad & Tobago Trinidad & Tobago 4.23 -63.5% 26
Turkey Turkey -0.754 -78.9% 59
Ukraine Ukraine -7.21 +36.6% 97
Uruguay Uruguay -1.01 -70% 62
United States United States -3.88 +18.9% 88
Uzbekistan Uzbekistan -4.99 -34.3% 93
St. Vincent & Grenadines St. Vincent & Grenadines -13.5 -19.6% 102
Vietnam Vietnam 5.89 -0.969% 17
Samoa Samoa 6.05 +41.3% 16
South Africa South Africa -0.596 -63.1% 57

                    
# 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 = 'BN.CAB.XOKA.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 <- 'BN.CAB.XOKA.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))