Tax revenue (% of GDP)

Source: worldbank.org, 01.09.2025

Year: 2023

Flag Country Value Value change, % Rank
Albania Albania 17.8 -1.67% 42
United Arab Emirates United Arab Emirates 0.627 +8.36% 86
Argentina Argentina 9.98 -9.97% 78
Armenia Armenia 22.5 +3% 19
Austria Austria 25.9 -1.21% 8
Burkina Faso Burkina Faso 18.4 +3.88% 39
Bulgaria Bulgaria 20.5 -5.76% 29
Bahamas Bahamas 16.2 +4.3% 50
Bosnia & Herzegovina Bosnia & Herzegovina 19.1 -0.17% 34
Belarus Belarus 12.7 +13.1% 67
Brazil Brazil 14 -4.64% 59
Botswana Botswana 18.7 -4.76% 35
Canada Canada 13.8 +9.1% 63
Switzerland Switzerland 9 +0.152% 81
Chile Chile 17.7 -17% 43
China China 7.64 +1.6% 84
Côte d’Ivoire Côte d’Ivoire 13.2 +11.9% 65
Colombia Colombia 17.6 +15.1% 45
Costa Rica Costa Rica 13.9 -3.08% 61
Cyprus Cyprus 24.1 +3.97% 12
Denmark Denmark 31.4 +2.4% 2
Dominican Republic Dominican Republic 14.5 +3.94% 56
Spain Spain 15 -3.25% 54
Estonia Estonia 21.4 +1.93% 23
Ethiopia Ethiopia 3.93 -12.6% 85
Finland Finland 25.4 +19.7% 9
Fiji Fiji 20.7 +11.6% 27
France France 23.1 -5.8% 16
United Kingdom United Kingdom 27.4 +0.864% 3
Georgia Georgia 23.6 +3.04% 14
Guinea-Bissau Guinea-Bissau 8.85 +0.622% 82
Greece Greece 26.6 -3.74% 7
Guatemala Guatemala 11.6 -2.12% 72
Croatia Croatia 21.5 -0.844% 22
Iceland Iceland 23.3 +3.62% 15
Israel Israel 22.1 -11.5% 20
Italy Italy 24.8 +0.941% 11
Jordan Jordan 17 -2.4% 48
Kazakhstan Kazakhstan 11.9 -1.4% 71
Kenya Kenya 14 -4.15% 60
Kyrgyzstan Kyrgyzstan 19.6 +0.34% 32
Cambodia Cambodia 12.2 -9.73% 69
Kiribati Kiribati 17.7 -12.5% 44
South Korea South Korea 15.7 -14.7% 52
Sri Lanka Sri Lanka 9.92 +36.3% 79
Lithuania Lithuania 21.4 +0.641% 24
Luxembourg Luxembourg 27.2 +2.01% 4
Latvia Latvia 16.7 -2.54% 49
Macao SAR China Macao SAR China 22.8 +36.8% 17
Morocco Morocco 21 -5.12% 25
Moldova Moldova 18.6 -1.78% 37
Madagascar Madagascar 9.61 +4.05% 80
Mexico Mexico 14.2 +6.12% 57
North Macedonia North Macedonia 17.9 +0.978% 41
Malta Malta 21.9 -3.31% 21
Mauritius Mauritius 20.5 +7.7% 28
Malaysia Malaysia 12.6 +8.03% 68
Namibia Namibia 33 +21.3% 1
Nicaragua Nicaragua 19.9 +0.412% 31
Netherlands Netherlands 24.8 +3.94% 10
Norway Norway 27.1 -13.7% 5
Philippines Philippines 14.1 -3.52% 58
Papua New Guinea Papua New Guinea 15.9 +7.88% 51
Poland Poland 18 +5.12% 40
Portugal Portugal 22.8 -1.51% 18
Paraguay Paraguay 10.1 -1.25% 77
Russia Russia 12.1 +11.3% 70
Rwanda Rwanda 13.5 -1.26% 64
Saudi Arabia Saudi Arabia 7.8 +12.2% 83
Senegal Senegal 19.5 +5.08% 33
Singapore Singapore 13.9 +17.9% 62
El Salvador El Salvador 20.7 -2.16% 26
Somalia Somalia 0.00008 +20.8% 87
Slovenia Slovenia 20.3 -3.21% 30
Togo Togo 14.8 +4.03% 55
Thailand Thailand 15.4 +1.88% 53
Tajikistan Tajikistan 10.8 +3.94% 75
Tonga Tonga 23.8 +8.47% 13
Turkey Turkey 18.5 +15.2% 38
Tanzania Tanzania 11.5 -2.55% 74
Uganda Uganda 13 +3.33% 66
Ukraine Ukraine 17.5 +4.6% 46
Uruguay Uruguay 18.7 +0.325% 36
United States United States 10.6 -15.5% 76
Uzbekistan Uzbekistan 11.5 -3.83% 73
Vanuatu Vanuatu 17.4 +8.15% 47
Samoa Samoa 26.7 +4.02% 6

                    
# 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.TAX.TOTL.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.TAX.TOTL.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))