Stocks traded, total value (current US$)

Source: worldbank.org, 03.09.2025

Year: 2024

Flag Country Value Value change, % Rank
United Arab Emirates United Arab Emirates 120,524,120,000 +8.18% 20
Armenia Armenia 2,120,000 -69.4% 69
Australia Australia 845,272,170,000 -5.84% 11
Austria Austria 30,204,030,000 +2.14% 26
Azerbaijan Azerbaijan 7,150,000 +159% 67
Bangladesh Bangladesh 12,784,490,000 -4.07% 33
Bulgaria Bulgaria 182,910,000 -18.2% 53
Bahrain Bahrain 801,700,000 +55.3% 44
Belarus Belarus 16,140,000 +264% 63
Bermuda Bermuda 11,250,000 -42.5% 65
Brazil Brazil 909,655,220,000 -24.1% 10
Botswana Botswana 88,990,000 -70.5% 56
Canada Canada 2,149,980,220,000 +6.43% 7
Switzerland Switzerland 719,348,850,000 -6.48% 12
Chile Chile 29,307,930,000 -4.43% 27
China China 34,873,674,380,000 +17% 2
Colombia Colombia 4,934,550,000 +21.3% 37
Cyprus Cyprus 153,400,000 +77.3% 55
Czechia Czechia 3,610,430,000 -22.5% 39
Germany Germany 923,998,030,000 -11.3% 9
Egypt Egypt 20,298,270,000 +2.21% 30
Spain Spain 276,234,040,000 -12.2% 15
Ghana Ghana 78,530,000 +177% 57
Greece Greece 31,265,100,000 +7.66% 25
Hong Kong SAR China Hong Kong SAR China 2,996,539,390,000 +31.5% 6
Croatia Croatia 283,170,000 -4.36% 51
Hungary Hungary 7,375,400,000 +6.74% 35
Indonesia Indonesia 121,529,440,000 -13.5% 19
India India 3,347,429,290,000 +72.1% 4
Iran Iran 18,821,100,000 -95.9% 32
Israel Israel 46,458,590,000 -51.1% 23
Jamaica Jamaica 482,560,000 +72.4% 46
Jordan Jordan 1,509,820,000 -26.4% 42
Japan Japan 7,384,575,420,000 +15.9% 3
Kazakhstan Kazakhstan 456,520,000 -40.2% 47
Kenya Kenya 409,950,000 +23.9% 50
South Korea South Korea 3,126,799,760,000 -7.82% 5
Kuwait Kuwait 46,387,010,000 +40% 24
Sri Lanka Sri Lanka 1,493,820,000 +46.1% 43
Luxembourg Luxembourg 39,120,000 -6.97% 61
Morocco Morocco 6,019,400,000 +78% 36
Mexico Mexico 109,498,560,000 -5.69% 21
Malta Malta 53,400,000 -17% 59
Mauritius Mauritius 253,450,000 -2% 52
Malaysia Malaysia 165,924,380,000 +57.1% 17
Namibia Namibia 22,560,000 -20.6% 62
Nigeria Nigeria 1,543,630,000 -5.49% 41
New Zealand New Zealand 12,580,600,000 +3.75% 34
Pakistan Pakistan 19,831,860,000 +126% 31
Panama Panama 423,190,000 -1.02% 49
Peru Peru 3,824,660,000 +431% 38
Philippines Philippines 21,818,070,000 +3.39% 29
Poland Poland 81,115,020,000 +16.1% 22
Palestinian Territories Palestinian Territories 164,190,000 -50.2% 54
Qatar Qatar 29,236,700,000 -15% 28
Romania Romania 3,015,340,000 -4.05% 40
Rwanda Rwanda 43,890,000 +692% 60
Saudi Arabia Saudi Arabia 474,047,580,000 +38.2% 13
Slovenia Slovenia 426,010,000 +35.9% 48
Seychelles Seychelles 2,620,000 -80% 68
Thailand Thailand 301,890,000,000 -11.9% 14
Tunisia Tunisia 549,100,000 -7.15% 45
Turkey Turkey 959,189,630,000 -12% 8
Tanzania Tanzania 66,240,000 +86% 58
United States United States 42,600,207,070,000 +14.3% 1
Uzbekistan Uzbekistan 10,200,000 -65.3% 66
Vietnam Vietnam 160,406,840,000 +17.7% 18
South Africa South Africa 192,028,040,000 -4% 16
Zambia Zambia 14,470,000 -31.5% 64

                    
# 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 = 'CM.MKT.TRAD.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 <- 'CM.MKT.TRAD.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))