Educational attainment, at least completed upper secondary, population 25+, male (%) (cumulative)

Source: worldbank.org, 03.09.2025

Year: 2023

Flag Country Value Value change, % Rank
Australia Australia 80.6 -2.46% 13
Austria Austria 86.5 +0.301% 10
Azerbaijan Azerbaijan 92.6 -0.561% 5
Burkina Faso Burkina Faso 7.56 -1.68% 53
Bahrain Bahrain 60.3 -5.15% 26
Bahamas Bahamas 87.9 +4.1% 7
Bosnia & Herzegovina Bosnia & Herzegovina 81.9 -0.844% 11
Belarus Belarus 97.5 -0.0581% 1
Bolivia Bolivia 55.6 +3.35% 29
Brazil Brazil 58.6 +13.2% 27
Botswana Botswana 47.7 +3.41% 32
Canada Canada 89.1 +0.429% 6
Switzerland Switzerland 87 +0.349% 8
Chile Chile 68.6 +1.97% 19
Colombia Colombia 55.8 +1.84% 28
Costa Rica Costa Rica 38.9 -1.43% 43
Dominican Republic Dominican Republic 30.5 -22.2% 47
Spain Spain 54.8 +0.078% 30
France France 79.5 +3.51% 15
United Kingdom United Kingdom 79.3 +1.4% 16
Georgia Georgia 93.8 +0.228% 3
Gambia Gambia 35.5 +30.5% 45
Guatemala Guatemala 18.5 -4.44% 50
Hong Kong SAR China Hong Kong SAR China 67.9 +1.28% 21
Honduras Honduras 18.4 +16.5% 51
Indonesia Indonesia 42.2 -0.34% 39
India India 40.2 +6.27% 41
Jordan Jordan 43.6 -13.9% 38
South Korea South Korea 86.5 +0.996% 9
Latvia Latvia 64.2 -27.1% 24
Moldova Moldova 76.4 +0.708% 17
Mexico Mexico 41.8 +6.58% 40
North Macedonia North Macedonia 76 -1.87% 18
Mongolia Mongolia 81.2 +6.32% 12
Panama Panama 48.6 -0.523% 31
Peru Peru 68.5 +10.6% 20
Poland Poland 62.2 -30.8% 25
Portugal Portugal 45.6 -1.02% 35
Russia Russia 93 +0.531% 4
Rwanda Rwanda 16.5 +5.49% 52
Saudi Arabia Saudi Arabia 64.8 -2.88% 23
Singapore Singapore 66.5 -18.1% 22
El Salvador El Salvador 35.5 -6.39% 46
Serbia Serbia 80.4 +0.907% 14
Eswatini Eswatini 20.2 -48.9% 49
Thailand Thailand 39.6 -0.539% 42
Tunisia Tunisia 47.5 +148% 33
Turkey Turkey 46.5 +3.76% 34
Uruguay Uruguay 30.4 -2.06% 48
United States United States 95.1 +4.99% 2
Vietnam Vietnam 44 -5.15% 37
Yemen Yemen 36.2 +24% 44
South Africa South Africa 44.3 +2.65% 36

                    
# 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.SEC.CUAT.UP.MA.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.SEC.CUAT.UP.MA.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))