Current education expenditure, total (% of total expenditure in public institutions)

Source: worldbank.org, 03.09.2025

Year: 2021

Flag Country Value Value change, % Rank
Albania Albania 91.6 +3.37% 45
United Arab Emirates United Arab Emirates 79.5 +7.56% 71
Argentina Argentina 95.9 -2.29% 20
Armenia Armenia 95.4 +5.04% 22
Austria Austria 92.8 -0.416% 41
Azerbaijan Azerbaijan 90.4 +1.2% 53
Belgium Belgium 95.2 +0.4% 23
Bulgaria Bulgaria 94.2 -1.37% 33
Bosnia & Herzegovina Bosnia & Herzegovina 97.6 -0.29% 8
Belarus Belarus 90.8 -0.854% 50
Bolivia Bolivia 95.8 -0.851% 21
Brazil Brazil 95 -1.34% 25
Barbados Barbados 96.8 -0.971% 12
Canada Canada 91.5 -0.322% 46
Chile Chile 94.5 -0.388% 28
Côte d’Ivoire Côte d’Ivoire 95.2 +3.9% 24
Costa Rica Costa Rica 97.1 +0.684% 11
Cayman Islands Cayman Islands 58.4 -21.5% 76
Cyprus Cyprus 96.6 -0.404% 14
Czechia Czechia 90 -0.858% 57
Germany Germany 90.6 +0.0577% 51
Denmark Denmark 93.3 +0.588% 38
Ecuador Ecuador 96.7 -0.928% 13
Spain Spain 94 -0.591% 35
Estonia Estonia 88.2 +0.167% 66
Finland Finland 89.8 +1.31% 58
France France 91.3 -0.782% 47
United Kingdom United Kingdom 92.3 +0.377% 43
Guatemala Guatemala 96.5 +1.31% 16
Croatia Croatia 94.4 +2.78% 29
Hungary Hungary 91.1 +1.83% 48
Ireland Ireland 100 +7.68% 1
Iceland Iceland 94.9 -0.653% 26
Israel Israel 90.2 -0.0143% 56
Italy Italy 94.8 +0.12% 27
Jamaica Jamaica 98.7 +0.295% 3
Jordan Jordan 88 +2.74% 67
Japan Japan 87.4 +2.27% 68
Kyrgyzstan Kyrgyzstan 90.9 -3.46% 49
St. Kitts & Nevis St. Kitts & Nevis 65.2 -18.8% 74
South Korea South Korea 83.2 +2.16% 69
Lithuania Lithuania 92.7 +4.82% 42
Luxembourg Luxembourg 89.1 -1.4% 59
Latvia Latvia 88.4 +3.7% 64
Macao SAR China Macao SAR China 88.8 +7.06% 60
Monaco Monaco 57.8 -21.1% 77
Moldova Moldova 90.5 +0.999% 52
Mexico Mexico 97.8 -0.161% 6
Mali Mali 98 +0.577% 5
Malta Malta 88.6 +1.67% 62
Malaysia Malaysia 94.4 -2.89% 30
Netherlands Netherlands 88.5 -0.499% 63
Norway Norway 88.2 +1.16% 65
Oman Oman 88.7 -1.6% 61
Peru Peru 81.9 -5.36% 70
Poland Poland 93.5 +0.0729% 36
Portugal Portugal 96.3 -0.3% 17
Paraguay Paraguay 94.2 +0.0492% 31
Palestinian Territories Palestinian Territories 97.8 -0.0203% 7
Romania Romania 93.1 -0.558% 39
Rwanda Rwanda 64.7 -25.6% 75
Senegal Senegal 93 +1.01% 40
Sierra Leone Sierra Leone 77.2 -22.4% 73
El Salvador El Salvador 78.3 -13.9% 72
San Marino San Marino 99.4 -0.0426% 2
Serbia Serbia 97.4 +0.608% 10
Slovakia Slovakia 94.2 -0.00563% 34
Slovenia Slovenia 92.3 +0.169% 44
Sweden Sweden 94.2 -1.19% 32
Turkmenistan Turkmenistan 98.4 +0.941% 4
Trinidad & Tobago Trinidad & Tobago 93.5 +1.72% 37
Turkey Turkey 90.4 -1.08% 55
Ukraine Ukraine 96.2 +0.875% 18
Uruguay Uruguay 95.9 -0.269% 19
United States United States 90.4 +0.443% 54
Uzbekistan Uzbekistan 97.6 -2.45% 9
South Africa South Africa 96.5 +0.472% 15

                    
# 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 = 'SE.XPD.CTOT.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 <- 'SE.XPD.CTOT.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))