Net trade in goods and services (BoP, current US$)

Source: worldbank.org, 03.09.2025

Year: 2024

Flag Country Value Value change, % Rank
Angola Angola 14,241,387,650 +7.3% 29
Albania Albania -1,848,064,175 +44.9% 79
Argentina Argentina 16,900,782,717 -281% 25
Armenia Armenia -468,702,340 +142% 70
Antigua & Barbuda Antigua & Barbuda 31,318,769 -136% 57
Australia Australia 19,823,436,844 -66.6% 22
Austria Austria 14,898,841,398 +45.8% 28
Azerbaijan Azerbaijan 6,774,099,000 -35.3% 37
Belgium Belgium -5,568,857,935 +42.2% 93
Bangladesh Bangladesh -21,111,378,001 +47.8% 105
Bulgaria Bulgaria 2,631,660,000 -38.2% 46
Bahrain Bahrain 8,259,042,553 +3.62% 34
Bahamas Bahamas -297,869,650 +13.6% 67
Bosnia & Herzegovina Bosnia & Herzegovina -4,060,945,565 +25.2% 89
Belarus Belarus -1,293,052,644 -608% 78
Belize Belize -83,919,656 +126% 58
Brazil Brazil 11,283,090,117 -77% 33
Brunei Brunei 2,372,398,525 -4.95% 47
Bhutan Bhutan -568,591,172 -37% 71
Canada Canada -5,947,032,090 -539% 94
Switzerland Switzerland 92,504,654,755 -5.44% 6
Chile Chile 11,883,616,133 +274% 32
China China 538,958,018,244 +39.8% 1
Colombia Colombia -9,766,708,285 +25.6% 99
Cape Verde Cape Verde -314,995,202 -30.9% 68
Costa Rica Costa Rica 6,310,784,270 +19.7% 39
Cyprus Cyprus 1,317,833,476 +260% 49
Czechia Czechia 22,518,192,686 +32.4% 20
Germany Germany 174,799,183,479 -1.14% 3
Djibouti Djibouti 484,898,406 -20.2% 51
Dominica Dominica -174,779,840 -23.5% 61
Denmark Denmark 46,450,895,106 +40% 12
Dominican Republic Dominican Republic -7,581,300,000 -12.5% 97
Ecuador Ecuador 4,498,211,130 +1,588% 43
Spain Spain 73,856,232,904 +15.9% 8
Estonia Estonia 262,145,352 -25.2% 52
Finland Finland 1,890,301,304 +105% 48
France France -3,311,261,737 -92.4% 87
United Kingdom United Kingdom -41,224,292,470 +13.7% 109
Georgia Georgia -2,593,149,355 -1.88% 83
Gambia Gambia -710,819,730 +11.8% 72
Greece Greece -13,984,812,965 +16.4% 100
Grenada Grenada -131,638,556 +36.9% 59
Guatemala Guatemala -17,579,310,780 +11.9% 104
Hong Kong SAR China Hong Kong SAR China 16,518,374,546 +636% 26
Honduras Honduras -8,882,297,543 +9.37% 98
Croatia Croatia -3,259,264,201 +86.6% 85
Hungary Hungary 12,425,921,823 +26.3% 31
Indonesia Indonesia 21,449,490,424 -25% 21
India India -101,034,797,310 +17% 112
Iceland Iceland -382,278,038 -633% 69
Israel Israel 12,810,200,000 -9.83% 30
Italy Italy 61,620,081,678 +77.8% 10
Jamaica Jamaica -2,400,772,587 -7.33% 82
Japan Japan -42,600,298,380 -41.5% 110
Kazakhstan Kazakhstan 17,662,721,866 -2.97% 24
Cambodia Cambodia -2,616,768,810 +56.9% 84
St. Kitts & Nevis St. Kitts & Nevis -138,542,834 +54.6% 60
South Korea South Korea 76,425,300,000 +605% 7
Kuwait Kuwait 28,188,883,808 -12% 18
St. Lucia St. Lucia 154,233,444 +21.3% 54
Lesotho Lesotho -1,099,698,565 -7.67% 75
Lithuania Lithuania 4,404,370,172 +41.1% 44
Luxembourg Luxembourg 42,171,155,231 +9.6% 14
Latvia Latvia -1,116,135,565 -29.4% 76
Moldova Moldova -4,701,120,000 +18.3% 90
Maldives Maldives 68,023,386 -165% 55
Mexico Mexico -16,268,563,735 -34.8% 102
North Macedonia North Macedonia -2,198,664,602 +6.86% 81
Malta Malta 4,739,928,988 +18.2% 41
Montenegro Montenegro -1,848,846,671 +32.3% 80
Mozambique Mozambique -1,129,454,668 -36.4% 77
Malaysia Malaysia 22,698,293,285 +11.1% 19
Namibia Namibia -3,312,449,512 +22.1% 88
Nigeria Nigeria -194,385,706 -96.2% 62
Nicaragua Nicaragua -3,302,581,710 +45.4% 86
Netherlands Netherlands 148,313,760,177 +15.1% 4
Norway Norway 66,737,994,417 -10.7% 9
Nepal Nepal -14,032,620,092 +20.8% 101
New Zealand New Zealand -6,199,833,773 -33.9% 95
Pakistan Pakistan -26,624,779,552 +21.8% 107
Panama Panama 6,489,366,214 +228% 38
Peru Peru 16,164,915,867 +75.8% 27
Philippines Philippines -54,164,616,659 +13.2% 111
Poland Poland 36,634,000,000 -23.3% 15
Portugal Portugal 7,258,325,860 +68% 36
Paraguay Paraguay -981,473,459 -234% 74
Palestinian Territories Palestinian Territories -5,379,455,681 -34.6% 92
Qatar Qatar 55,524,450,549 -1.79% 11
Romania Romania -23,322,218,788 +37.7% 106
Russia Russia 93,826,740,000 +9.66% 5
Saudi Arabia Saudi Arabia 43,885,705,969 -44.3% 13
Singapore Singapore 192,576,845,361 +1.79% 2
Solomon Islands Solomon Islands -214,251,464 -36.5% 64
El Salvador El Salvador -6,768,233,250 +5.67% 96
Suriname Suriname 222,216,301 -32.6% 53
Slovakia Slovakia 64,857,364 -97.2% 56
Slovenia Slovenia 4,576,156,270 +5.16% 42
Sweden Sweden 29,326,001,914 +16.7% 17
Thailand Thailand 17,772,045,139 +70.2% 23
Tajikistan Tajikistan -5,289,347,985 +38.2% 91
Timor-Leste Timor-Leste -919,259,512 +96.7% 73
Tonga Tonga -273,376,514 -5.12% 66
Trinidad & Tobago Trinidad & Tobago 896,603,025 -61.5% 50
Turkey Turkey 5,734,000,000 -120% 40
Ukraine Ukraine -35,911,000,000 -5.2% 108
Uruguay Uruguay 4,211,887,073 +56.8% 45
United States United States -917,838,000,000 +16.9% 113
Uzbekistan Uzbekistan -17,450,961,300 -0.829% 103
St. Vincent & Grenadines St. Vincent & Grenadines -215,996,803 -11.4% 65
Vietnam Vietnam 30,711,000,000 -12.8% 16
Samoa Samoa -206,019,343 -3.99% 63
South Africa South Africa 8,039,494,195 +560% 35

                    
# 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.GSR.GNFS.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 <- 'BN.GSR.GNFS.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))