School enrollment, secondary, male (% gross)

Source: worldbank.org, 03.09.2025

Year: 2023

Flag Country Value Value change, % Rank
Albania Albania 99.5 -1.72% 14
Andorra Andorra 99.6 +1.83% 13
United Arab Emirates United Arab Emirates 102 +23.9% 10
Armenia Armenia 94.9 -2.01% 20
Azerbaijan Azerbaijan 94.3 +1.57% 24
Burkina Faso Burkina Faso 28.2 -9.81% 79
Bangladesh Bangladesh 66.5 +0.105% 64
Bahrain Bahrain 101 -3.97% 11
Bahamas Bahamas 72.6 +16.4% 58
Bosnia & Herzegovina Bosnia & Herzegovina 83.6 -1.65% 50
Belarus Belarus 94.6 -1.88% 21
Belize Belize 82.5 -3.38% 52
Bermuda Bermuda 67.9 -5.84% 63
Bolivia Bolivia 92.4 +1.1% 30
Barbados Barbados 104 -0.35% 9
Brunei Brunei 88.2 +0.652% 42
Côte d’Ivoire Côte d’Ivoire 68 +17.5% 62
Cameroon Cameroon 46.7 -1.7% 73
Comoros Comoros 54.8 -9.75% 70
Cuba Cuba 94.6 -8.09% 22
Curaçao Curaçao 118 -0.781% 3
Cayman Islands Cayman Islands 89 -1.57% 38
Dominica Dominica 89 -0.111% 40
Dominican Republic Dominican Republic 68.5 -6.26% 61
Algeria Algeria 101 -3.42% 12
Ecuador Ecuador 92.2 -1.34% 31
Fiji Fiji 94.2 +3.31% 25
Georgia Georgia 106 +0.674% 7
Gibraltar Gibraltar 91.8 +0.39% 32
Guatemala Guatemala 46.8 +3.53% 72
Guyana Guyana 85.4 +3.53% 47
Honduras Honduras 50.3 +2.67% 71
Indonesia Indonesia 95.8 -2.84% 18
India India 79 -3.51% 53
Jamaica Jamaica 86.2 +2.83% 45
Jordan Jordan 90.8 +2.41% 34
Kazakhstan Kazakhstan 97.2 +1.41% 17
Kyrgyzstan Kyrgyzstan 94.3 -1.73% 23
Cambodia Cambodia 56.3 +4.41% 68
Kiribati Kiribati 86.5 +7% 44
Laos Laos 55.6 -3.72% 69
Lebanon Lebanon 60.8 +2.91% 67
St. Lucia St. Lucia 88.9 +4.99% 41
Macao SAR China Macao SAR China 93.3 +2.74% 26
Morocco Morocco 90.6 +3.26% 35
Maldives Maldives 77.1 +11.4% 55
Mali Mali 41.7 -2.27% 74
Montenegro Montenegro 92.7 +1.9% 28
Mongolia Mongolia 97.4 +1.95% 16
Malaysia Malaysia 83.5 +1.31% 51
Niger Niger 23.8 -17.6% 80
Nicaragua Nicaragua 69.2 +6.25% 60
Nepal Nepal 89.4 +7.03% 37
Nauru Nauru 85.9 +2.99% 46
Oman Oman 97.5 +5.17% 15
Peru Peru 104 +5.25% 8
Philippines Philippines 90.3 +0.158% 36
Palau Palau 92.6 +8.61% 29
Puerto Rico Puerto Rico 112 +21.8% 5
Paraguay Paraguay 77.5 -1.78% 54
Palestinian Territories Palestinian Territories 85.3 -1.25% 48
Russia Russia 93.3 -1.8% 27
Rwanda Rwanda 41.4 +1.62% 75
Senegal Senegal 40.5 -4.07% 76
El Salvador El Salvador 62.9 +1.04% 65
San Marino San Marino 61.7 -3.19% 66
Somalia Somalia 3.86 -52.9% 81
Seychelles Seychelles 72.6 -3.97% 57
Syria Syria 36.2 -0.0268% 77
Turks & Caicos Islands Turks & Caicos Islands 119 +0.88% 2
Chad Chad 30.3 +0.687% 78
Togo Togo 69.6 -1.04% 59
Thailand Thailand 110 +12.3% 6
Tajikistan Tajikistan 89 -2.51% 39
Tonga Tonga 95.4 +2.47% 19
Trinidad & Tobago Trinidad & Tobago 85 +4.55% 49
Tuvalu Tuvalu 76.5 -10.9% 56
Uzbekistan Uzbekistan 86.9 -0.587% 43
St. Vincent & Grenadines St. Vincent & Grenadines 123 -2.41% 1
Venezuela Venezuela 91.3 +13.6% 33
Vanuatu Vanuatu 117 +57% 4

                    
# 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.ENRR.MA'

# 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.ENRR.MA'

# 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))