1. Do the Setup, if you have not yet done so.

  2. Start a new R script and copy in this starter code (it loads the packages and downloads both data sets — we walked through every line on the slides):

pacman::p_load(
  tidyverse,    # Data manipulation & figures
  wbstats,      # World Bank data via API
  vdemdata,     # Varieties of Democracy data
  estimatr,     # OLS with robust standard errors
  modelsummary  # Nicely formatted regression tables
)

# V-Dem: civil liberties, and state ownership of the economy
Dat_vdem <- vdem %>%
  as_tibble() %>%
  select(country_text_id, year,
         civ_liberties = v2xcl_rol,    # Equality before the law & individual liberty
         state_own_raw   = v2clstown) %>% # State ownership of the economy
  mutate(state_ownership = -state_own_raw)  # Reverse: higher = MORE state ownership

# World Bank: extreme poverty (share below $3.00 a day, 2021 PPP).
# Try the live API; if it is down, fall back to the cached copy.
Dat_poverty <- wb_data("SI.POV.DDAY", start_date = 1972, end_date = 2025) %>%
  rename(poverty = SI.POV.DDAY,
         year = date,
         country_text_id = iso3c) %>%
  select(country_text_id, year, country, poverty) %>%
  drop_na(poverty) %>%
  group_by(country) %>%
  filter(year == max(year)) %>% # Keep the most recent estimate per country
  ungroup()
  1. Now write the join yourself: combine Dat_poverty and Dat_vdem into one tibble called Dat. Think first: which join do you want, and which variables form the key?

We want only countries that appear in both tibbles (an inner join), and a country is identified by its ISO code together with the year.

Dat <- inner_join(Dat_poverty, Dat_vdem, by = c("country_text_id", "year"))

Stuck?

  1. Make a scatter plot with poverty as outcome on the Y-axis and civil liberties as predictor on the X-axis. Ask it the four questions from the lecture: direction, form, spread, outliers.
ggplot(data = Dat, aes(y = poverty, x = civ_liberties)) +
  geom_text(aes(label = country)) +
  labs(y = "% of population below $3.00 a day (2021 PPP)",
       x = "Civil liberties") +
  theme_minimal()

  1. Before you compute anything: judging only from your scatter plot, the correlation between poverty and civil liberties is …

  2. Now check yourself: estimate the correlation with cor() (two digits are enough; point or comma is fine):

Dat %>%
  select(poverty, civ_liberties) %>%
  cor()
#               poverty civ_liberties
# poverty          1.00         -0.33
# civ_liberties   -0.33          1.00
  1. This is edge ② of our triangle. What does the correlation suggest about a liberty–equality trade-off?

  2. Write one sentence in your R script (as a # comment) interpreting the correlation — as if for your term paper. Then compare with the model answer:

Across 161 countries, civil liberties correlate moderately negatively with extreme poverty (r ≈ -0.33): countries with stronger civil liberties tend to have a smaller share of their population in extreme poverty.

(Yours doesn't need the same words — but it should name the direction, the rough strength, and the units of analysis (countries), and it should not claim causality.)


Bonus (for the fast): Dat has 161 countries, but V-Dem covers 179 countries today. So the inner_join() silently dropped 18 of them. Before you open the answer: which kinds of countries do you think have no World Bank poverty estimate, and why?

The 18 lost countries have no World Bank poverty estimate, and for two different reasons. Some states do not run, or do not publish, the household surveys poverty figures are built from — North Korea, Somalia, Eritrea, Cuba, Libya, Afghanistan, several Gulf states. Others are simply too rich for the $3.00 line to be worth measuring — New Zealand, Singapore, Hong Kong, Taiwan. The join also loses 10 countries the other way round: small island states the World Bank surveys but V-Dem does not code.

Check the arithmetic: 161 kept + 18 lost = 179. An inner_join() dropped them silently. Data that are missing are a finding, too: our analysis can only speak about countries that measure poverty — which excludes both the least free and some of the richest.