Internally displaced persons, total displaced by conflict and violence (number of people)

Source: worldbank.org, 19.12.2024

Year: 2023

Flag Country Value Value change, % Rank
Afghanistan Afghanistan 4,187,000 -7.22% 6
Armenia Armenia 7,600 0% 51
Azerbaijan Azerbaijan 658,000 -0.152% 18
Burundi Burundi 8,100 -4.71% 50
Benin Benin 8,800 +633% 48
Burkina Faso Burkina Faso 2,063,000 +9.62% 12
Bangladesh Bangladesh 426,000 0% 23
Bosnia & Herzegovina Bosnia & Herzegovina 91,000 0% 35
Brazil Brazil 16,000 +186% 46
Central African Republic Central African Republic 512,000 -0.775% 21
Cameroon Cameroon 1,044,000 +5.78% 17
Congo - Kinshasa Congo - Kinshasa 6,734,000 +18.4% 3
Colombia Colombia 5,077,000 +6.53% 4
Cyprus Cyprus 248,000 +0.813% 28
Ethiopia Ethiopia 2,852,000 -26% 10
Georgia Georgia 311,000 +0.974% 27
Ghana Ghana 3,800 -24% 55
Gambia Gambia 5,700 +1.79% 52
Guatemala Guatemala 242,000 0% 29
Honduras Honduras 101,000 -59.1% 34
Haiti Haiti 311,000 +81.9% 27
Indonesia Indonesia 55,000 -20.3% 40
India India 613,000 +12.1% 19
Iraq Iraq 1,124,000 -3.85% 14
Israel Israel 200,000 30
Kazakhstan Kazakhstan 120 0% 62
Kenya Kenya 40,000 +33.3% 43
Kyrgyzstan Kyrgyzstan 4,000 0% 54
Lebanon Lebanon 74,000 +147,900% 38
Libya Libya 119,000 -11.9% 32
Sri Lanka Sri Lanka 12,000 0% 47
Madagascar Madagascar 2,800 0% 57
Mexico Mexico 392,000 +1.55% 24
North Macedonia North Macedonia 110 0% 63
Mali Mali 344,000 -9.47% 26
Myanmar (Burma) Myanmar (Burma) 2,625,000 +75.2% 11
Mozambique Mozambique 592,000 -42.5% 20
New Caledonia New Caledonia 150 0% 61
Niger Niger 347,000 -6.72% 25
Nigeria Nigeria 3,340,000 -8.39% 9
Nicaragua Nicaragua 1,300 +18.2% 58
Pakistan Pakistan 23,000 +27.8% 44
Peru Peru 75,000 +2.74% 37
Philippines Philippines 113,000 +10.8% 33
Papua New Guinea Papua New Guinea 87,000 +2.35% 36
Palestinian Territories Palestinian Territories 1,710,000 +14,150% 13
Russia Russia 60,000 +733% 39
Sudan Sudan 9,053,000 +155% 1
Senegal Senegal 8,400 0% 49
Solomon Islands Solomon Islands 1,000 0% 59
Sierra Leone Sierra Leone 3,000 0% 56
El Salvador El Salvador 49,000 -5.77% 41
Somalia Somalia 3,862,000 -0.0518% 7
Serbia Serbia 194,000 -0.513% 31
South Sudan South Sudan 1,121,000 -24% 15
Syria Syria 7,248,000 +5.58% 2
Chad Chad 452,000 +50.7% 22
Togo Togo 18,000 +683% 45
Thailand Thailand 41,000 0% 42
Turkey Turkey 1,099,000 0% 16
Uganda Uganda 4,800 +6.67% 53
Ukraine Ukraine 3,689,000 -37.6% 8
Kosovo Kosovo 16,000 0% 46
Yemen Yemen 4,516,000 -0.155% 5
South Africa South Africa 620 60

                    
# 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 = 'VC.IDP.TOCV'

# 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 <- 'VC.IDP.TOCV'

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