Conclusion

The whole course, on one dataset — your own

Merlin Schaeffer · Department of Sociology

2026-07-28

The goal of empirical sociology

Use data to discover patterns — and the social mechanisms that bring them about.

Fourteen weeks in two verbs: describe accurately, then explain causally. Today we put the whole toolkit on one table.

One dataset: your own quizzes

Our running example today is you: the weekly-quiz results of this class.

  • mcorrect — a student’s % correct across the weeks.
  • appearances — how many quizzes they completed.
  • woman, Statistics — two labels we’ll build with an LLM in a moment.

Anonymised: real first names were replaced with synthetic ones. Everything numeric is exactly as it was.

Most of you did very well — the class average is 92.2% (red line).

The Null model: just the average

The simplest prediction of anyone’s score is the overall average \(\bar{Y}\).

It explains none of the variation between students — every red line is a full miss from the mean.

This is the baseline every model must beat. All of “describing patterns” is the effort to shrink those red lines.

OLS: a knife that cuts the variation

OLS fits a line by \(\min(\sum e^2)\). It splits each student’s distance from the mean into two:

  • Blue — explained by the model.
  • Red — residual, left unexplained.

Here the model is \[ \operatorname{mcorrect} = \alpha + \beta_{1}(\operatorname{appearances}) + \epsilon \] — score as a function of quizzes completed.

Two goals, one course

1 · Describe patterns accurately

Shrink the red, grow the blue.

  1. Dummy coding — categorical predictors (L4)
  2. Multiple OLS — several predictors at once (L8)
  3. Interaction effects — conditional associations (L11)
  4. Polynomials & transformations — non-linear shapes (L12)

2 · Identify causal mechanisms

Isolate variation in the treatment \(D\) that is as good as random.

  • Assign it: RCTs (L6), natural experiments, ITT & the Wald estimator (L7)
  • Find it with OLS: 2SLS (L10), control for confounders (L8/9), and regression discontinuity (L13)

Goal 1 · Describe patterns accurately

Part 1 of 2

Turn red into blue: give the model better-shaped predictors.

Categorical predictors → dummy variables

A category becomes a 0/1 dummy:

\[x = \begin{cases} 1 & \text{if the condition holds} \\ 0 & \text{otherwise} \end{cases}\]

Do women and men score differently? Let’s regress mcorrect on a gender dummy.

Beware: this cohort is 63 women vs. 9 men — the “Men” estimate rests on nine people. Read it with humility.

% Correct
(Intercept) 93.620***
(1.396)
Women (vs. Men) −1.574
(1.571)
Num.Obs. 72
R2 0.009
+ p < 0.1, * p < 0.05, ** p < 0.01, *** p < 0.001

The gap is about -1.6 points and not significant (\(p = 0.32\)) — no real gender difference here.

Where did “gender” come from? An LLM

We never asked your gender. We inferred it from first names with a zero-shot language model — the same tooling sociologists now use to code open text at scale.

Shown for transparency; the label is a prediction, not ground truth — another reason not to over-read the gap.

library(text)  # Hugging Face models from R

# Zero-shot: is a person with this name a woman?
zeroshot <- text::textZeroShot(
  sequences        = result$name,
  candidate_labels = c("woman"),
  multi_label      = FALSE,
  hypothesis_template = "A person with this name is a {}.",
  model = "alexandrainst/scandi-nli-base")

Stats skill = f(your name)?

Ask the same model a silly question — “A person with this name is great at Statistics” — and it will happily return a number for every name.

Beware: a model will always answer. Slope -0.43, \(p = 0.45\), \(R^2 = 0.006\) — pure noise. Your name does not predict your stats skill.

Multiple OLS: several predictors at once

\[Y_i = \alpha + \beta_1 X_{1i} + \dots + \beta_k X_{ki} + \epsilon_i\]

Each slope is the association of that predictor, holding the others fixed — the Frisch–Waugh logic of Lectures 8–9.

Together, quizzes + gender + (nonsense) stats-skill explain \(R^2 = 0.092\) of the variation — a little more blue.

% Correct
(Intercept) 79.836***
(6.365)
Women (vs. Men) −3.233
(2.019)
Stats skill (LLM) −0.826
(0.746)
Nr. of quizzes 1.312*
(0.564)
Num.Obs. 72
R2 0.092
+ p < 0.1, * p < 0.05, ** p < 0.01, *** p < 0.001

Interaction effects: it depends

\[Y_i = \alpha + \beta_1 X_{1i} + \beta_2 X_{2i} + \color{orange}{\beta_3\, X_{1i} X_{2i}} + \epsilon_i\]

An interaction lets the slope of one predictor depend on another — the effect of practice could differ by group (L11).

Here the two slopes are nearly parallel — little evidence the quiz–score link differs by gender (and remember: nine men).

Polynomials: let the line bend

\[Y_i = \alpha + \beta_1 X_i + \color{orange}{\beta_2 X_i^2 + \beta_3 X_i^3} + \epsilon_i\]

Adding powers of \(X\) bends the fit (L12) — but every extra term risks overfitting the wiggles.

A cubic nudges fit to \(R^2 = 0.068\) vs. the straight line’s \(0.058\) — barely worth the two extra terms here.

Transformations: change the scale

\[Y_i = \alpha + \color{orange}{\beta_1 \log_2(X_i)} + \epsilon_i\]

A log2 transform reads as “per doubling” (L12) — often a cleaner, one-coefficient way to capture a curve.

Each doubling of quizzes completed is worth about 9.4 points — one interpretable number.

And you can combine them

\[\small Y_i = \alpha + \beta_1 X_{1i} + \beta_2 X_{2i} + \color{orange}{\beta_3 X_{1i}^2 + \beta_4 X_{1i}X_{2i} + \beta_5 X_{1i}^2 X_{2i}} + \epsilon_i\]

Dummies, curves and interactions are one toolbox — a group-specific bend is just a polynomial interacted with a dummy.

Power comes with responsibility: every term you add must earn its place, or you are fitting noise.

Goal 2 · Identify causal mechanisms

Part 2 of 2

A good description is not a cause. To claim causation we need variation in the treatment \(D\) that is as good as random.

The enemy: selection / omitted-variable bias

A raw group difference mixes the causal effect with selection bias:

\[\small \underbrace{\bar{Y}_{D=1} - \bar{Y}_{D=0}}_{\text{observed gap}} = \underbrace{\text{ATT}}_{\text{causal}} + \underbrace{\bar{Y}_{0\mid D=1} - \bar{Y}_{0\mid D=0}}_{\text{selection bias}}\]

Equivalently, an omitted confounder \(C\) bends the slope:

\[\tilde{\beta}_{Y\leftarrow D} = \beta_{Y\leftarrow D} + \underbrace{\beta_{Y\leftarrow C}\,\beta_{C\leftarrow D}}_{\text{omitted-variable bias}}\]

This one equation — Lectures 5 and 8 — is the reason the whole second half of the course exists.

Strategy A — assign \(D\) at random

Intervene so that all variation in the treatment \(D\) is random. Then the raw difference is the effect.

RCTs & natural experiments

We intervene with an as-if-random \(Z\), and \(Z\) decides the treatment \(D\) perfectly \((|r| = 1)\): treatment and control differ only by chance.

  • Categorical treatment → a simple \(Y = \alpha + \color{red}{\beta} I_i + \epsilon_i\) (L6).
  • A natural experiment — the world does the randomising (L7) — is read the same way, if you can defend the “as-if random” arrow.

Continuous or subgroup questions still use polynomials and interactions from Part 1.

When assignment is imperfect: ITT & Wald

Often \(Z\) only nudges \(D\) \((|r| < 1)\) — an offer some ignore.

  • The intention-to-treat effect (the reduced form, \(\rho\)) is the effect of the offer \(Z\) on \(Y\) (L7).
  • Scale it by the first stage \(\phi\) (how much \(Z\) moved \(D\)) to recover the effect of \(D\) on compliers — the Wald estimator:

\[\lambda = \frac{\rho}{\phi} = \frac{\text{reduced form}}{\text{first stage}} = \frac{\text{ITT}}{r}\]

Same idea, harmonised symbols: \(\rho\) = ITT, \(\phi\) = compliance \(r\). This is exactly the L7/L10 Wald ratio.

Strategy B — find random variation with OLS

Most variation in \(D\) is not random. So carve out the slice that is — and use only that.

Instruments, confounders, mediators

OLS lets us split \(D\) into a trustworthy part and a contaminated part:

  • Instrument \(Z\) — keep the predicted part of \(D\) driven by a random \(Z\): 2SLS (L10).
  • Confounder \(C\) — throw it away by controlling: keep the part of \(D\) unrelated to \(C\) (L8/9).
  • Mediator \(M\) — add it in a second step to see how much of \(D\)’s effect runs through it (L9).

Instrument vs. control — mirror images: keep the predicted values vs. keep the residuals of \(D\).

Regression discontinuity: the causal effect of rules

A strict rule creates a threshold on a running variable (L13). Barely below vs. barely above is as good as random — so the jump at the cutoff is the causal effect.

We fit lines on both sides using all the data, but read the gap exactly at the threshold.

The whole course, in one line

Describe patterns honestly — then hunt for variation that is as good as random to explain them.

  • Read and build a regression: dummies, multiple predictors, interactions, curves.
  • Name selection / omitted-variable bias — and the design that defeats it.
  • Tell RCT, natural experiment, IV/2SLS, control, and RDD apart, and say what each assumes.

Tak — spørgsmål?

Thank you for a great semester.

The weekly quiz, the Friday exercises, and this deck are your revision map for the exam.

```