Trade (% of GDP)

Source: worldbank.org, 03.09.2025

Year: 2024

Flag Country Value Value change, % Rank
Angola Angola 62.3 -7.02% 92
Albania Albania 79.1 -4.15% 71
Argentina Argentina 28.2 +5.7% 130
Armenia Armenia 152 +27.1% 14
Australia Australia 47.3 -3.88% 111
Austria Austria 111 -5.37% 34
Azerbaijan Azerbaijan 82.7 -1.01% 64
Belgium Belgium 158 -6.22% 10
Benin Benin 40.6 -9.01% 121
Burkina Faso Burkina Faso 63.4 -2.15% 88
Bangladesh Bangladesh 26.8 -13.6% 132
Bulgaria Bulgaria 109 -8.67% 36
Bahamas Bahamas 79.2 +3.52% 70
Bosnia & Herzegovina Bosnia & Herzegovina 100 +0.358% 45
Belarus Belarus 132 +0.253% 27
Bermuda Bermuda 80.5 +9.41% 68
Brazil Brazil 35.5 +5.54% 128
Brunei Brunei 133 -2.66% 26
Botswana Botswana 67 -2.66% 83
Central African Republic Central African Republic 47.8 +9.99% 109
Canada Canada 65.2 -2.18% 85
Switzerland Switzerland 134 -0.905% 24
Chile Chile 63.9 +5.16% 87
China China 37.2 +3.03% 125
Côte d’Ivoire Côte d’Ivoire 54.7 +5.12% 100
Cameroon Cameroon 35.9 -3.58% 127
Congo - Kinshasa Congo - Kinshasa 97.5 +7.83% 48
Congo - Brazzaville Congo - Brazzaville 93.2 -3.14% 56
Colombia Colombia 36.9 -8.66% 126
Comoros Comoros 44.4 -2.87% 114
Cape Verde Cape Verde 95.1 +0.544% 52
Costa Rica Costa Rica 71.3 -1.57% 77
Cyprus Cyprus 190 -1.8% 7
Czechia Czechia 132 -0.783% 28
Germany Germany 80.3 -2.96% 69
Djibouti Djibouti 309 +8.62% 4
Denmark Denmark 129 +0.684% 30
Dominican Republic Dominican Republic 51.8 +3.89% 105
Ecuador Ecuador 57.2 +0.36% 96
Egypt Egypt 39.6 -2.1% 123
Spain Spain 70.3 -2.61% 79
Estonia Estonia 152 -1.86% 15
Ethiopia Ethiopia 17.3 -15.9% 135
Finland Finland 82.5 -3.98% 65
France France 67.2 -4.73% 82
Micronesia (Federated States of) Micronesia (Federated States of) 96.6 -1.75% 49
Gabon Gabon 94.5 +3.83% 54
United Kingdom United Kingdom 62.4 -4.04% 91
Georgia Georgia 104 -2.63% 39
Ghana Ghana 69.4 +7.71% 81
Guinea Guinea 100 +4.45% 44
Gambia Gambia 43.7 +3.07% 115
Guinea-Bissau Guinea-Bissau 40.7 -2.28% 120
Equatorial Guinea Equatorial Guinea 60.5 -1.47% 95
Greece Greece 89.3 -3.08% 59
Guatemala Guatemala 47.3 -1.97% 110
Hong Kong SAR China Hong Kong SAR China 359 +1.82% 2
Honduras Honduras 91.1 -7.78% 58
Croatia Croatia 103 -4.63% 41
Haiti Haiti 22.2 -27.7% 134
Hungary Hungary 144 -8.48% 16
Indonesia Indonesia 42.6 +2.99% 116
India India 44.7 -0.715% 113
Ireland Ireland 253 +6.64% 5
Iran Iran 49.7 -4.72% 108
Iraq Iraq 74.7 +7.59% 75
Iceland Iceland 84.3 -2.78% 62
Israel Israel 54.5 -6.1% 101
Italy Italy 63.2 -3.75% 89
Jordan Jordan 99.7 -0.666% 46
Kenya Kenya 30.3 -5.61% 129
Cambodia Cambodia 143 +6.89% 17
Kiribati Kiribati 101 -5.98% 42
Libya Libya 134 -14% 25
Sri Lanka Sri Lanka 42.4 -2.62% 117
Lithuania Lithuania 143 -4.02% 18
Luxembourg Luxembourg 398 -1.54% 1
Latvia Latvia 132 -3.53% 29
Macao SAR China Macao SAR China 135 -4.85% 23
Morocco Morocco 95.8 +2.1% 50
Moldova Moldova 88.7 -5.67% 60
Madagascar Madagascar 55 -10.1% 98
Mexico Mexico 74.7 +1.28% 76
North Macedonia North Macedonia 138 -6.86% 20
Mali Mali 50.9 -11.7% 107
Malta Malta 230 -1.26% 6
Montenegro Montenegro 112 -5.16% 32
Mongolia Mongolia 139 -2.78% 19
Mozambique Mozambique 95.7 -9.43% 51
Mauritius Mauritius 104 -1.05% 40
Malaysia Malaysia 137 +4.01% 21
Namibia Namibia 110 -1.03% 35
Niger Niger 52 +11.8% 104
Nicaragua Nicaragua 98.5 -6.17% 47
Netherlands Netherlands 156 -5.87% 13
Norway Norway 81.2 +1.07% 67
Nepal Nepal 40.5 -2.5% 122
Nauru Nauru 158 +9.94% 11
Pakistan Pakistan 27.5 -3.93% 131
Peru Peru 51.5 +1.36% 106
Philippines Philippines 65.9 -2.28% 84
Poland Poland 101 -8.52% 43
Puerto Rico Puerto Rico 94.8 -6.86% 53
Portugal Portugal 91.1 -2.9% 57
Paraguay Paraguay 76.8 -6.76% 74
Palestinian Territories Palestinian Territories 81.3 +2.24% 66
Romania Romania 77.3 -6.98% 73
Russia Russia 39.5 -3.25% 124
Rwanda Rwanda 70 +7.78% 80
Saudi Arabia Saudi Arabia 54.8 +1.17% 99
Sudan Sudan 2.46 -0.493% 136
Senegal Senegal 71.2 -0.274% 78
Singapore Singapore 322 -1.02% 3
Sierra Leone Sierra Leone 64.5 +15.4% 86
El Salvador El Salvador 84.7 +3.6% 61
Somalia Somalia 94.4 +1.81% 55
Serbia Serbia 111 -2.65% 33
Slovakia Slovakia 170 -5.96% 9
Slovenia Slovenia 156 -2.26% 12
Sweden Sweden 105 -1.81% 38
Seychelles Seychelles 188 +4.17% 8
Chad Chad 45.4 -3.38% 112
Togo Togo 62.5 +1.7% 90
Thailand Thailand 137 +6.17% 22
Tunisia Tunisia 105 -7.02% 37
Turkey Turkey 55.8 -15.8% 97
Tanzania Tanzania 41.5 +8.64% 118
Uganda Uganda 41.5 +24.4% 119
Ukraine Ukraine 77.8 +0.314% 72
Uruguay Uruguay 52.5 -0.843% 103
United States United States 24.9 -0.0457% 133
Uzbekistan Uzbekistan 60.7 -8.14% 94
Samoa Samoa 83.1 -8.3% 63
Kosovo Kosovo 114 +3.92% 31
South Africa South Africa 61.7 -5.34% 93
Zimbabwe Zimbabwe 52.7 +3.7% 102

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