Problem Set 1: Causality and Data-Generating Processes

Author

POL 211

Published

September 29, 2026

Due: Monday, October 5 by 11:59 PM. Email both your .qmd and your rendered .html to Max Welch (mwelch@ucdavis.edu).

TipReview Quant Camp as you go

This set leans on the R you learned at Quant Camp. When you get stuck on filtering, grouping, or plotting, go back to the Quant Camp materials. They’re the fastest way to get unstuck.

ImportantUsing AI

Use AI the way people used Google, R’s help pages, and Stack Overflow before AI: ask precise, limited questions to get unstuck on part of a question. Passing off AI-generated work wholesale as your own is not allowed. See the syllabus and the Department’s policy on generative AI.

Format: Write your answers in one Quarto document, saved in the sets/ folder of your course project. Start it with this header, so the HTML renders as one self-contained file:

---
title: "Problem Set 1"
author: "Your name"
format:
  html:
    embed-resources: true
---

Your document should read as a short report: brief prose explaining your reasoning, not just code and output.

Libraries you will need:

library(tidyverse)
library(juanr)
library(wakefield)

Question 3 uses wakefield, a package for making fake data. It’s new, so install it once by running install.packages("wakefield") in the Console (not in your .qmd).

WarningMethods subfield

Parts marked Methods portfolio are required if you plan to choose methods as a subfield. They’re optional, and recommended, for everyone else.

Question 1: Warm-up

This question reviews a few tools from Quant Camp. It uses fearon, from my juanr package: the data behind Fearon and Laitin (2003), a classic study of why civil wars start. (If you don’t have juanr yet, the Getting Started page shows how to install it.) Once juanr is loaded, the data are in fearon.

gdp_cap is GDP per capita, in thousands of dollars. polity2 is a democracy score that runs from \(-10\) (most autocratic) to 10 (most democratic). oil is 1 if oil makes up more than a third of the country’s export earnings, and 0 otherwise.

  1. What is the unit of analysis in fearon?

  2. Make a scatterplot of polity2 (y) against gdp_cap (x) for 1990 only, with labeled axes. Add a smoothing line (geom_smooth()). Why does it make sense to look at one year at a time here? What pattern do you see? Add country names to the plot. Who are the outliers? (Hint: geom_label() or geom_text())

  3. Compute the average gdp_cap and the average polity2 for oil and non-oil country-years. Describe the pattern.

  4. Which countries have the following characteristics: above average mountainous terrain (mtnest), below average ethnic fractionalization (ef), exactly one language spoken by groups larger than 1% of the population (numlang)?

Question 2: Suicide terrorism

In a well-known article, Pape (2003) argues that suicide terrorism follows a strategic logic.

  1. In Pape’s argument, what is the treatment (\(X\)) and what is the outcome (\(Y\))?

  2. What is one row in Pape’s data (the unit of analysis)? Across all of his data, what values does \(Y\) take?

  3. A causal claim is a comparison. Which two groups would we need to compare to learn whether \(X\) causes \(Y\) (in Pape’s study)? Which of those groups can Pape’s data tell us about, and which can’t it?

  4. To see why this matters, you’ll build two made-up worlds. Each has 10,000 country-years. In both, x is 1 if a country-year has the treatment you named in (a), and y is 1 if it has the outcome. The table says how many country-years of each kind each world has:

    Country-years of each kind in two made-up worlds.
    x y World A World B
    1 1 180 160
    1 0 8,820 840
    0 1 20 18
    0 0 980 8,982

    Here is World A in R. tribble() lets you type a small table one row at a time: the first line names the columns (each with a ~ in front), and each line after that is one row. Here each row is one kind of country-year, and n is how many there are. uncount(n) then copies each row n times, so the data end up with one row per country-year:

    world_a = tribble(
      ~x, ~y, ~n,
      1,  1,  180,
      1,  0,  8820,
      0,  1,  20,
      0,  0,  980
    ) |>
      uncount(n)

    Build world_b the same way, using the counts in the table. Check that each world has 10,000 rows. (Hint: nrow().)

  5. In each world, among country-years with y = 1, what share have x = 1? (Hint: filter())

  6. In each world, what share of country-years with x = 1 have y = 1? What share of country-years with x = 0 do? (Hint: group_by(x)) What is the effect of \(X\) on \(Y\) in each world?

WarningMethods portfolio
  1. Build a new world where \(X\) has no effect on \(Y\), but the share from (e) is 50%. (Hint: start from whichever world had no effect in (f).) What did you have to change?

Ashworth et al. (2008) make this critique of Pape formally. It’s short and worth reading.

Question 3: Build your own data-generating process

A data-generating process has a systematic part and a random part. In this question you’ll build one yourself: first with no random part, then with one, so you can see exactly what randomness changes.

Start by making a fake town with wakefield’s r_data_frame(). I won’t show you how it works: figuring out a new package from its documentation is a skill you’ll use all the time. Use it to make a town of 300 people, each with an ID, an age, a sex, and a level of education. (Hint: run ?r_data_frame in the Console and look at the examples at the bottom of the help page, or see the package’s page at https://github.com/trinker/wakefield.) Fill in the parentheses here:

set.seed(211)
town = r_data_frame()

set.seed(211) makes the random draws repeatable: run the chunk again and you get the same town. The rest of this question uses the column names r_data_frame() gives you: ID, Age, Sex, and Education.

  1. What is one row in town? What values does Education take? (Hint: count(town, Education).) Make a variable college that is 1 for anyone with a bachelor’s degree or more, and 0 otherwise. (Hint: case_when().)

  2. The systematic part. Everyone uses the same outcome, hours: the hours per week someone spends watching political news. Write a rule that makes hours from Age and college, like this one:

    \[ \text{hours} = 1 + 0.1 \times \text{Age} + 2 \times \text{college} \]

    Read this as: for each year of age, number of hours watched increases by 0.1. College grads (0/1) watch 2 more hours than non-grads.

    Keep the same variables, but use your own numbers, and say in a sentence why you picked them. Add hours to town with mutate().

  3. Show that hours is perfectly predictable:

    • Find two people with the same age and the same college. Do they have the same hours?
    • Plot hours against Age, colored by college. What do you see?
  4. Try rnorm(). To add a random part, we need random numbers. rnorm() makes them. Try each of these in the Console:

    • Run rnorm(5) three times. What changes each time? What do the numbers look like?

    • Compare rnorm(5, mean = 0, sd = 1) with rnorm(5, mean = 0, sd = 10). What does sd seem to do?

    • Make 10,000 draws below and plot them in a histogram:

      draws = tibble(draw = rnorm(10000, mean = 0, sd = 2))

      Where is the middle of the histogram? What share of the draws fall between \(-2\) and \(2\)? (Hint: use case_when() to define if an observation falls between 2 and -2, then summarise.)

    Noternorm() in plain words

    Think of each draw as a random nudge. Nudges up are as common as nudges down, small nudges are common, and big ones are rare. sd sets how big a typical nudge is. We’ll cover the math behind this later in the quarter; for now, this is all you need.

  5. The random part. Give everyone their own nudge:

    town = town |>
      mutate(hours_noisy = hours + rnorm(n(), mean = 0, sd = 2))

    (n() is the number of rows, so each person gets one nudge.) Now redo part (c) with hours_noisy. Do two people with the same traits still have the same outcome? How does the plot change?

  6. In 3–4 sentences: what does the random part change about (1) how well you can predict the outcome, and (2) the data you get each time you run the process?

WarningMethods portfolio
  1. Turn up the noise. For sd values of 0, 1, 2, 5, and 10, for what share of people is the noisy version of hours within 1 hour of hours itself? expand_grid() makes this easy: it makes one copy of the data for each value you give it. expand_grid(sd = c(0, 1, 2, 5, 10), town) stacks five copies of town, 1,500 rows in all, with a column sd that says which value each copy gets. Give every row a nudge with its own sd, using rnorm(n(), mean = 0, sd = sd), then group_by(sd) to score each copy. Plot the share against sd.

References

Ashworth, Scott, Joshua D. Clinton, Adam Meirowitz, and Kristopher W. Ramsay. 2008. “Design, Inference, and the Strategic Logic of Suicide Terrorism.” American Political Science Review 102(2): 269–73. doi:10.1017/S0003055408080167.
Fearon, James D., and David D. Laitin. 2003. “Ethnicity, Insurgency, and Civil War.” American Political Science Review 97(1): 75–90.
Pape, Robert A. 2003. “The Strategic Logic of Suicide Terrorism.” American Political Science Review 97(3): 343–61.