People practicing open defecation, rural (% of rural population)

Source: worldbank.org, 03.09.2025

Year: 2022

Flag Country Value Value change, % Rank
Afghanistan Afghanistan 12 -7.14% 40
Angola Angola 54.2 0% 10
Albania Albania 0 89
Andorra Andorra 0 89
United Arab Emirates United Arab Emirates 0 89
Armenia Armenia 0.0291 0% 88
Antigua & Barbuda Antigua & Barbuda 0.601 0% 70
Austria Austria 0 89
Burundi Burundi 1.67 0% 66
Belgium Belgium 0 89
Benin Benin 65.5 -1.55% 4
Burkina Faso Burkina Faso 46.7 -4.05% 13
Bangladesh Bangladesh 0 89
Bulgaria Bulgaria 0 89
Belarus Belarus 0 89
Belize Belize 0.439 0% 75
Bolivia Bolivia 29.3 -4.95% 21
Brazil Brazil 0.745 0% 68
Bhutan Bhutan 0 89
Botswana Botswana 15.6 0% 34
Central African Republic Central African Republic 38.8 0% 16
Canada Canada 0 89
Switzerland Switzerland 0 89
Chile Chile 0 89
China China 0 -100% 89
Côte d’Ivoire Côte d’Ivoire 37.6 -2.63% 17
Cameroon Cameroon 9.13 -2.72% 49
Congo - Kinshasa Congo - Kinshasa 18.8 0% 29
Colombia Colombia 10.3 -6.86% 45
Cape Verde Cape Verde 17.6 0% 31
Costa Rica Costa Rica 0.208 -17.3% 81
Cuba Cuba 0.452 0% 72
Cyprus Cyprus 0 89
Czechia Czechia 0 89
Germany Germany 0 89
Djibouti Djibouti 64.1 0% 5
Denmark Denmark 0 89
Dominican Republic Dominican Republic 5.15 -3.8% 56
Algeria Algeria 0 89
Ecuador Ecuador 1.82 -38.6% 64
Egypt Egypt 0 89
Spain Spain 0 89
Estonia Estonia 0 89
Ethiopia Ethiopia 21.8 0% 26
Finland Finland 0 89
Fiji Fiji 0 89
France France 0 89
Gabon Gabon 3.46 -0.88% 60
United Kingdom United Kingdom 0 89
Georgia Georgia 0 89
Ghana Ghana 29.7 -0.209% 20
Guinea Guinea 10.9 -11.1% 43
Gambia Gambia 0 -100% 89
Guinea-Bissau Guinea-Bissau 15 0% 37
Greece Greece 0 89
Guatemala Guatemala 1.69 -35% 65
Guyana Guyana 0.379 -12.7% 77
Honduras Honduras 8.39 -10.9% 51
Haiti Haiti 31.5 0% 18
Hungary Hungary 0 89
Indonesia Indonesia 6.96 -20.4% 55
India India 17 -16.6% 32
Ireland Ireland 0 89
Iraq Iraq 0 89
Iceland Iceland 0 89
Israel Israel 0 89
Italy Italy 0 89
Jamaica Jamaica 0.586 0% 71
Jordan Jordan 0.395 0% 76
Kazakhstan Kazakhstan 0.0708 0% 87
Kenya Kenya 8.73 -6.54% 50
Kyrgyzstan Kyrgyzstan 0 89
Cambodia Cambodia 16.1 -19% 33
Kiribati Kiribati 47.4 -0.662% 12
Laos Laos 25.9 0% 24
Liberia Liberia 57.3 -1.44% 7
St. Lucia St. Lucia 7.15 0% 54
Sri Lanka Sri Lanka 0 89
Lesotho Lesotho 19.8 -7.86% 28
Lithuania Lithuania 0 89
Luxembourg Luxembourg 0 89
Morocco Morocco 0 89
Moldova Moldova 0.233 0% 79
Madagascar Madagascar 44.8 -0.51% 14
Maldives Maldives 0 89
Mexico Mexico 0 -100% 89
Marshall Islands Marshall Islands 21.2 -3.6% 27
North Macedonia North Macedonia 0.268 0% 78
Mali Mali 7.37 -10.4% 53
Malta Malta 0 89
Myanmar (Burma) Myanmar (Burma) 9.6 0% 48
Montenegro Montenegro 0.129 0% 83
Mongolia Mongolia 15.4 -7.95% 35
Mozambique Mozambique 28.5 -6.58% 22
Mauritania Mauritania 55.7 -1.59% 9
Malawi Malawi 2.93 -17.9% 62
Namibia Namibia 56.7 0% 8
Niger Niger 76.3 -1.09% 2
Nigeria Nigeria 31.2 +0.13% 19
Netherlands Netherlands 0 89
Norway Norway 0 89
Nepal Nepal 7.94 0% 52
New Zealand New Zealand 0 89
Oman Oman 0 89
Pakistan Pakistan 10.8 -15.1% 44
Panama Panama 11.9 0% 41
Peru Peru 9.67 -15.9% 47
Philippines Philippines 4.32 -11.3% 58
Palau Palau 0 89
Papua New Guinea Papua New Guinea 18 0% 30
Poland Poland 0 89
North Korea North Korea 0 89
Portugal Portugal 0 89
Paraguay Paraguay 0.867 -2.38% 67
Palestinian Territories Palestinian Territories 0.448 -9.75% 73
Romania Romania 0 89
Russia Russia 0 89
Rwanda Rwanda 1.99 0% 63
Saudi Arabia Saudi Arabia 0 89
Senegal Senegal 14.1 -7.41% 38
Sierra Leone Sierra Leone 26 -1.67% 23
El Salvador El Salvador 0 -100% 89
Somalia Somalia 40.3 0% 15
Serbia Serbia 0.0717 0% 86
South Sudan South Sudan 73.3 0% 3
São Tomé & Príncipe São Tomé & Príncipe 53.5 0% 11
Suriname Suriname 3.25 0% 61
Slovakia Slovakia 0 89
Sweden Sweden 0 89
Eswatini Eswatini 0 89
Turks & Caicos Islands Turks & Caicos Islands 0.231 0% 80
Chad Chad 77.6 0% 1
Togo Togo 61.5 -1.4% 6
Thailand Thailand 0 89
Tajikistan Tajikistan 0.44 0% 74
Turkmenistan Turkmenistan 0 89
Timor-Leste Timor-Leste 15.3 -10.4% 36
Tonga Tonga 0.0912 -7.14% 85
Tunisia Tunisia 0 89
Turkey Turkey 0.64 0% 69
Tuvalu Tuvalu 3.6 -10.5% 59
Tanzania Tanzania 9.72 -2.17% 46
Uganda Uganda 4.55 -10.5% 57
Ukraine Ukraine 0 89
Uruguay Uruguay 0 89
United States United States 0 89
Uzbekistan Uzbekistan 0.1 0% 84
Vietnam Vietnam 0 -100% 89
Vanuatu Vanuatu 0 89
Samoa Samoa 0.152 +3.23% 82
Yemen Yemen 13.5 0% 39
South Africa South Africa 0 89
Zambia Zambia 11.2 0% 42
Zimbabwe Zimbabwe 25.6 0% 25

                    
# 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 = 'SH.STA.ODFC.RU.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 <- 'SH.STA.ODFC.RU.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))