Question: How has global poverty changed over time, and which regions drive this change?

knitr::opts_chunk$set(echo = TRUE, warning = FALSE, message = FALSE, include = TRUE)

library(readr)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(tidyr)
library(ggplot2)
setwd("~/Desktop/mydata")
# Load the data
wdi <- read_csv("WDICSV.csv", show_col_types = FALSE)

# Select two key indicators:
# - Poverty headcount ratio at $2.15/day (2017 PPP)
# - Total population
poverty <- wdi[wdi$`Indicator Code`=="SI.POV.DDAY", ]
pop <- wdi[wdi$`Indicator Code`=="SP.POP.TOTL", ]
# Reshape the data 
poverty_long <- pivot_longer(poverty, cols=starts_with("19")|starts_with("20"),names_to="year", values_to="poverty_rate")
pop_long <- pivot_longer(pop, cols=starts_with("19")|starts_with("20"),names_to="year", values_to="population")
# Merge + clean the data
poverty_pop <- merge(poverty_long, pop_long, by=c("Country Name","Country Code","year"))
poverty_pop <- na.omit(poverty_pop)
# Convert types
poverty_pop$year <- as.integer(poverty_pop$year)
poverty_pop$poverty_rate <- as.numeric(poverty_pop$poverty_rate)
poverty_pop$population <- as.numeric(poverty_pop$population)

Insight 1: Global poverty has declined sharply

world <- poverty_pop[poverty_pop$`Country Name`=="World", ]

ggplot(world, aes(x=year, y=poverty_rate)) +
  geom_line(linewidth=1.2, color="steelblue") +
  labs(title="% of Global Population Living on <$2.15/day", x="Year", y="% in Poverty")

# Preparing Insight 2: Regional analysis
# Focus on six main regions
regions <- c("East Asia & Pacific","Europe & Central Asia", "Latin America & Caribbean","Middle East & North Africa", "South Asia","Sub-Saharan Africa")

region_data <- poverty_pop[poverty_pop$`Country Name` %in% regions, ]

region_summary <- region_data %>%
  dplyr::group_by(`Country Name`) %>%
  dplyr::summarize(avg_poverty_rate = mean(poverty_rate, na.rm=TRUE))

region_summary
## # A tibble: 5 × 2
##   `Country Name`            avg_poverty_rate
##   <chr>                                <dbl>
## 1 East Asia & Pacific                  43.6 
## 2 Europe & Central Asia                 7.13
## 3 Latin America & Caribbean            14.7 
## 4 South Asia                           40.2 
## 5 Sub-Saharan Africa                   55.4

Insight 2: East Asia drove the decline, while Sub-Saharan Africa now makes up most of the global poor.

ggplot(region_data, aes(x=year, y=(poverty_rate/100)*population/1e6, color=`Country Name`)) + geom_line(linewidth=1.2) + labs(title="Absolute Number of Poor by Region", x="Year", y="Millions of People", color="Region")

Conclusion: From 1980 to the 2020s, the share of the global population living on less than $2.15/day fell from about 45% to 10%. Much of this was driven by East Asia & Pacific, while Sub-Saharan Africa now accounts for the largest share of the global poor.