School enrollment, primary (gross), gender parity index (GPI)

Source: worldbank.org, 01.09.2025

Year: 2021

Flag Country Value Value change, % Rank
Albania Albania 1.02 -0.944% 16
Armenia Armenia 1.01 -0.53% 23
Azerbaijan Azerbaijan 1.01 -3.24% 20
Benin Benin 0.926 +0.0162% 67
Burkina Faso Burkina Faso 1.02 +0.779% 17
Bangladesh Bangladesh 1.02 -6.82% 15
Belarus Belarus 1 +0.445% 26
Belize Belize 0.955 +0.0189% 62
Barbados Barbados 0.972 +0.184% 53
Bhutan Bhutan 1.04 +2.1% 9
Botswana Botswana 0.982 +0.0847% 45
China China 1.01 -0.119% 21
Côte d’Ivoire Côte d’Ivoire 0.953 +0.977% 64
Costa Rica Costa Rica 0.991 -2.53% 36
Cuba Cuba 0.982 +1.09% 44
Djibouti Djibouti 0.917 -4.27% 68
Dominica Dominica 0.955 +2.33% 63
Dominican Republic Dominican Republic 0.97 +1.41% 55
Ecuador Ecuador 1.02 -0.151% 13
Ethiopia Ethiopia 0.912 +1.12% 70
Fiji Fiji 0.965 -0.281% 59
Micronesia (Federated States of) Micronesia (Federated States of) 0.996 +0.0533% 30
Georgia Georgia 1.01 +0.227% 22
Gibraltar Gibraltar 1.07 -2.38% 4
Gambia Gambia 1.13 +1.04% 3
Guatemala Guatemala 0.985 +0.296% 42
Hong Kong SAR China Hong Kong SAR China 1.04 +0.0384% 6
India India 1.02 -0.334% 18
Jordan Jordan 0.988 +0.0557% 41
Kyrgyzstan Kyrgyzstan 0.995 -0.124% 31
Cambodia Cambodia 0.981 +1.16% 46
St. Kitts & Nevis St. Kitts & Nevis 0.948 +3.29% 65
Kuwait Kuwait 1.15 +2.27% 2
Laos Laos 0.972 +0.459% 52
Macao SAR China Macao SAR China 0.979 +0.373% 48
Morocco Morocco 0.973 +0.239% 51
Moldova Moldova 0.989 +0.715% 40
Marshall Islands Marshall Islands 0.944 -1.86% 66
Montenegro Montenegro 1 +0.552% 25
Mongolia Mongolia 0.978 -0.0835% 49
Mauritius Mauritius 1.02 +0.0539% 11
Namibia Namibia 0.965 -0.257% 57
Niger Niger 0.913 +1.6% 69
Nepal Nepal 0.961 -2.91% 61
Oman Oman 0.997 -6.25% 29
Panama Panama 0.989 +0.00702% 39
Peru Peru 0.97 +0.827% 54
Philippines Philippines 0.977 +0.0891% 50
Palau Palau 0.969 -9.79% 56
Palestinian Territories Palestinian Territories 0.995 -0.0753% 32
Qatar Qatar 1.02 -1.03% 12
Rwanda Rwanda 0.994 +1.44% 33
Saudi Arabia Saudi Arabia 1.01 -0.451% 19
Senegal Senegal 1.16 +1.13% 1
Sierra Leone Sierra Leone 1.04 +0.47% 7
San Marino San Marino 0.991 +1.62% 35
Serbia Serbia 1 +0.409% 28
Suriname Suriname 0.99 -0.944% 38
Seychelles Seychelles 1.03 -1.15% 10
Turks & Caicos Islands Turks & Caicos Islands 1.05 +0.0822% 5
Chad Chad 0.8 +2.81% 71
Togo Togo 0.965 -0.638% 58
Thailand Thailand 0.993 -0.137% 34
Tunisia Tunisia 0.982 -0.234% 43
Tuvalu Tuvalu 0.961 -4.9% 60
Tanzania Tanzania 1.04 +0.765% 8
Uzbekistan Uzbekistan 0.98 -0.19% 47
British Virgin Islands British Virgin Islands 0.99 -2.42% 37
Vietnam Vietnam 1.02 -0.35% 14
Samoa Samoa 1 +1.72% 27
Zimbabwe Zimbabwe 1.01 +0.0262% 24

                    
# 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.ENR.PRIM.FM.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.ENR.PRIM.FM.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))