Revenue, excluding grants (% of GDP)

Source: worldbank.org, 01.09.2025

Year: 2023

Flag Country Value Value change, % Rank
Albania Albania 24.7 -0.142% 48
United Arab Emirates United Arab Emirates 3.74 +14.4% 86
Argentina Argentina 17.9 -0.328% 66
Armenia Armenia 24 +2.21% 51
Austria Austria 44.6 +0.493% 3
Burkina Faso Burkina Faso 21.2 +7.75% 56
Bulgaria Bulgaria 34.8 -4.81% 20
Bahamas Bahamas 18.7 -0.309% 62
Bosnia & Herzegovina Bosnia & Herzegovina 36.6 +1.95% 14
Belarus Belarus 27.9 +7.1% 40
Brazil Brazil 25.4 -5.81% 47
Botswana Botswana 28.1 -4.76% 38
Canada Canada 19.7 +9.68% 59
Switzerland Switzerland 17.1 -0.731% 70
Chile Chile 22.9 -12% 54
China China 15.1 +2.8% 76
Côte d’Ivoire Côte d’Ivoire 13.6 +12.6% 79
Colombia Colombia 28.4 +11.8% 37
Costa Rica Costa Rica 29.3 +1.55% 35
Cyprus Cyprus 41.3 +7.37% 9
Denmark Denmark 36.7 +2.55% 13
Dominican Republic Dominican Republic 16.9 +3.5% 71
Spain Spain 29.6 -0.524% 30
Estonia Estonia 36.3 +3.8% 15
Ethiopia Ethiopia 4.5 -10.9% 85
Finland Finland 42.1 +13.4% 7
Fiji Fiji 23.3 +12.1% 52
France France 42.3 -4.47% 6
United Kingdom United Kingdom 36 -1.96% 16
Georgia Georgia 28 +5.58% 39
Guinea-Bissau Guinea-Bissau 11 +1.88% 83
Greece Greece 43.2 -4.04% 5
Guatemala Guatemala 12.8 -0.34% 81
Croatia Croatia 35.6 -6.96% 18
Iceland Iceland 31.7 +1.69% 24
Israel Israel 30.4 -8.66% 29
Italy Italy 39.3 -0.83% 10
Jordan Jordan 23.2 -0.901% 53
Kazakhstan Kazakhstan 16.5 -2.08% 74
Kenya Kenya 18.5 +3.71% 63
Kyrgyzstan Kyrgyzstan 30.7 +2.64% 28
Cambodia Cambodia 13.8 -7.99% 78
Kiribati Kiribati 81.1 +22.6% 1
South Korea South Korea 29.5 -7.95% 32
Sri Lanka Sri Lanka 11.1 +35.2% 82
Lithuania Lithuania 34 +2.74% 22
Luxembourg Luxembourg 43.3 +3.31% 4
Latvia Latvia 32.1 +3.93% 23
Macao SAR China Macao SAR China 27.3 +33% 41
Morocco Morocco 26.4 -1.65% 43
Moldova Moldova 29.4 +0.3% 33
Madagascar Madagascar 10.8 +5.62% 84
Mexico Mexico 19.1 -0.956% 61
North Macedonia North Macedonia 29.5 +1.97% 31
Malta Malta 31.3 -2.12% 25
Mauritius Mauritius 24.6 +2.97% 49
Malaysia Malaysia 17.3 +5.3% 69
Namibia Namibia 35.5 +13.6% 19
Nicaragua Nicaragua 21.5 +0.0115% 55
Netherlands Netherlands 38.8 -0.934% 11
Norway Norway 54.2 -3.65% 2
Philippines Philippines 15.7 -2.24% 75
Papua New Guinea Papua New Guinea 16.9 +10.1% 72
Poland Poland 35.9 +6.17% 17
Portugal Portugal 37.7 -1.01% 12
Paraguay Paraguay 17.6 +1.02% 68
Russia Russia 28.7 +6.41% 36
Rwanda Rwanda 19.3 -2.1% 60
Saudi Arabia Saudi Arabia 26.5 -2.8% 42
Senegal Senegal 24.2 +9.14% 50
Singapore Singapore 18.2 +14.7% 65
El Salvador El Salvador 26.1 -7.59% 45
Somalia Somalia 0.00011 +16.1% 87
Slovenia Slovenia 41.8 -1.32% 8
Togo Togo 16.6 +10.3% 73
Thailand Thailand 19.9 +4.98% 58
Tajikistan Tajikistan 18.4 +7.98% 64
Tonga Tonga 26.3 +9.75% 44
Turkey Turkey 29.4 +13.9% 34
Tanzania Tanzania 13.4 -4.19% 80
Uganda Uganda 14.4 +4.36% 77
Ukraine Ukraine 30.8 +5.31% 26
Uruguay Uruguay 30.8 +3.84% 27
United States United States 17.6 -11.7% 67
Uzbekistan Uzbekistan 20.3 -3.85% 57
Vanuatu Vanuatu 25.5 +5.96% 46
Samoa Samoa 34.2 +3.13% 21

                    
# 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 = 'GC.REV.XGRT.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 <- 'GC.REV.XGRT.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))