People using safely managed sanitation services (% of population)

Source: worldbank.org, 03.09.2025

Year: 2022

Flag Country Value Value change, % Rank
Albania Albania 56.3 +3.48% 69
Andorra Andorra 100 0% 1
United Arab Emirates United Arab Emirates 98.5 -0.000153% 8
Armenia Armenia 10.8 -0.386% 124
American Samoa American Samoa 37 +0.0818% 88
Australia Australia 95.8 +0.107% 17
Austria Austria 99.7 +0.00181% 4
Belgium Belgium 94.9 +0.444% 22
Benin Benin 2.7 +0.387% 129
Burkina Faso Burkina Faso 9.75 +3.06% 125
Bangladesh Bangladesh 31 +2.72% 98
Bulgaria Bulgaria 73.5 +1.39% 52
Bahrain Bahrain 92.2 +0.339% 25
Belarus Belarus 75 +0.197% 50
Brazil Brazil 49.6 +0.0711% 76
Bhutan Bhutan 50.5 -0.227% 75
Central African Republic Central African Republic 13.3 +0.631% 119
Canada Canada 83.9 +0.000574% 40
Switzerland Switzerland 99.8 +0.000316% 3
Chile Chile 95.3 +0.0323% 20
China China 67.2 +1.95% 57
Côte d’Ivoire Côte d’Ivoire 17.2 +1.63% 113
Congo - Kinshasa Congo - Kinshasa 13 -0.173% 120
Colombia Colombia 18.4 +0.74% 111
Costa Rica Costa Rica 25.4 +0.735% 104
Cuba Cuba 41.3 +0.727% 85
Cyprus Cyprus 76.8 +0.0202% 49
Czechia Czechia 89.7 +0.373% 31
Germany Germany 96.9 +0.0076% 13
Djibouti Djibouti 39.6 +0.0981% 86
Denmark Denmark 98.8 +0.0802% 7
Dominican Republic Dominican Republic 43.1 -0.997% 82
Algeria Algeria 62.4 +0.0703% 62
Ecuador Ecuador 41.6 -0.508% 84
Egypt Egypt 67.2 +0.015% 58
Spain Spain 90 -0.000243% 30
Estonia Estonia 90.4 +0.00329% 27
Ethiopia Ethiopia 7.22 +0.9% 127
Finland Finland 90 +0.178% 29
Fiji Fiji 48.8 -0.453% 77
France France 89.7 +0.0809% 32
United Kingdom United Kingdom 98.1 +0.0135% 9
Georgia Georgia 24.1 -1.93% 108
Ghana Ghana 15.8 +3.79% 115
Gambia Gambia 28 -2.26% 99
Guinea-Bissau Guinea-Bissau 15.4 +0.292% 116
Greece Greece 92.2 +0.0914% 26
Greenland Greenland 0 130
Guyana Guyana 44.2 -1.21% 80
Hong Kong SAR China Hong Kong SAR China 96.5 +0.945% 14
Honduras Honduras 52.6 +0.541% 72
Hungary Hungary 87.8 +0.0345% 35
Isle of Man Isle of Man 84.8 0% 38
India India 52.1 +4.23% 73
Ireland Ireland 79.8 +0.0149% 45
Iraq Iraq 52.8 +1.35% 71
Israel Israel 96.3 +0.791% 15
Italy Italy 79 +0.00525% 46
Jordan Jordan 82.3 +0.0618% 42
Japan Japan 99.1 +0.0525% 6
Kenya Kenya 31.5 +1% 97
Kyrgyzstan Kyrgyzstan 92.6 +0.065% 24
Cambodia Cambodia 36.7 +4.29% 89
Kiribati Kiribati 24.8 +1.34% 107
South Korea South Korea 99.4 -0.0159% 5
Kuwait Kuwait 100 0% 1
Laos Laos 61.1 +0.0378% 64
Lebanon Lebanon 25.7 0% 102
Libya Libya 23.8 0% 109
Liechtenstein Liechtenstein 96.2 0% 16
Lesotho Lesotho 47.5 -0.112% 78
Lithuania Lithuania 95.3 +0.542% 21
Luxembourg Luxembourg 95.8 +0.344% 18
Macao SAR China Macao SAR China 68.1 +1.5% 56
Morocco Morocco 61 +0.184% 65
Monaco Monaco 100 0% 1
Madagascar Madagascar 12.3 +3.6% 121
Mexico Mexico 62.5 +4.13% 61
North Macedonia North Macedonia 12.2 -0.266% 122
Mali Mali 15.9 +3.32% 114
Malta Malta 88.2 -0.00002% 34
Myanmar (Burma) Myanmar (Burma) 60.6 -0.0619% 66
Montenegro Montenegro 57.4 +3.61% 68
Mongolia Mongolia 66 +0.62% 59
Malawi Malawi 46.2 +4.63% 79
Malaysia Malaysia 86 +0.841% 37
Niger Niger 8.12 +3.1% 126
Nigeria Nigeria 32 +2.19% 95
Netherlands Netherlands 97.5 +0.00010% 11
Norway Norway 78.1 +0.1% 48
Nepal Nepal 50.6 -0.0669% 74
New Zealand New Zealand 88.7 +0.0686% 33
Peru Peru 57.7 +4.6% 67
Philippines Philippines 62.7 +1.63% 60
Poland Poland 97.9 +0.0593% 10
Puerto Rico Puerto Rico 32.5 0% 93
Portugal Portugal 92.8 +0.609% 23
Paraguay Paraguay 55.2 +0.83% 70
Palestinian Territories Palestinian Territories 70.1 +2.2% 55
Qatar Qatar 99.9 +0.818% 2
Romania Romania 87.6 +0.693% 36
Russia Russia 61.2 +0.24% 63
Saudi Arabia Saudi Arabia 79.9 +0.0437% 44
Senegal Senegal 14.1 +1.38% 118
Singapore Singapore 100 0% 1
Sierra Leone Sierra Leone 15.4 +4.79% 117
San Marino San Marino 90.2 0% 28
Somalia Somalia 32.6 +0.415% 92
Serbia Serbia 25.4 -0.577% 103
São Tomé & Príncipe São Tomé & Príncipe 34 +0.0671% 90
Suriname Suriname 25.2 -0.0463% 105
Slovakia Slovakia 82.5 +0.00542% 41
Slovenia Slovenia 84 +0.252% 39
Sweden Sweden 95.6 +0.0113% 19
Turks & Caicos Islands Turks & Caicos Islands 34 -0.0661% 91
Chad Chad 10.9 +0.724% 123
Togo Togo 5.76 +0.24% 128
Thailand Thailand 26.3 +0.214% 101
Tonga Tonga 32 -0.665% 94
Tunisia Tunisia 81.1 +0.104% 43
Turkey Turkey 78.7 +2.5% 47
Tuvalu Tuvalu 37.2 -1.23% 87
Tanzania Tanzania 25.1 +0.418% 106
Uganda Uganda 17.8 +0.838% 112
Ukraine Ukraine 71.9 -0.0225% 53
United States United States 97 -0.0235% 12
Uzbekistan Uzbekistan 74.5 +0.0512% 51
Venezuela Venezuela 27.1 +2.68% 100
Vietnam Vietnam 43.7 +1.02% 81
Samoa Samoa 42.9 -1.24% 83
Yemen Yemen 19.2 +0.333% 110
South Africa South Africa 71.7 +1.01% 54
Zimbabwe Zimbabwe 31.8 +0.0126% 96

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