4.4 — Causal Analysis: Prediction vs Causation, Confounders, Difference-in-Differences, Instrumental Variables

Chapter 4 · Statistical Predictive Models

Prof. Xuhu Wan

Section 4.4 · Chapter 4 · Learning Statistics with Python

Causal Analysis: Prediction vs Causation, Confounders, Difference-in-Differences, Instrumental Variables

Statistical Predictive Models

Prof. Xuhu Wan

ISOM, HKUST Business School · 2026 Edition

Causal Analysis: Prediction vs Causation, Confounders, Difference-in-Differences, Instrumental Variables

Everything so far answered “given \(x\), what is \(y\)?”. A manager asks “if I change \(x\), what happens to \(y\)?”. You will build a case where the best predictor is a useless lever, fix it with a control, and then meet two designs for when the control is not observed.

Two questions that look alike

“Borrowers who use our budgeting tool repay 20 % more.” Which action needs a causal answer?

  • Flag tool users as low-risk when pricing their next loan
  • Use tool usage as a feature in the PD model
  • Push every borrower to install the tool, expecting 20 % better repayment
  • Report the correlation in the annual review

Potential outcomes: each borrower has \(Y(1)\) with the tool and \(Y(0)\) without; we see one. The observed gap is \(\underbrace{E[Y(1)-Y(0)\mid T=1]}_{\text{causal}} + \underbrace{E[Y(0)\mid T=1] - E[Y(0)\mid T=0]}_{\text{selection bias}}\).

A great predictor that is a useless lever

Simulate a hidden trait \(U\) (financial discipline) that drives both tool adoption \(T\) and repayment \(Y\). By construction the tool has zero effect.

Coefficient 2.17 with t = 24 and R² = 0.23. As a predictor of repayment, tool usage is excellent. As a policy, pushing the tool would move repayment by exactly 0.

Regression adjustment: control for the confounder

Add \(U\) as a second regressor. The coefficient on \(T\) will:

  • Stay near 2.17 — \(T\) is still strongly correlated with \(Y\)
  • Collapse toward 0 — the true effect
  • Flip to about −2
  • Become undefined because \(T\) and \(U\) are correlated

Adjusted: 0.066 (truth 0). With a real effect of 0.5, naive says 2.67, adjusted says 0.45. This works only because \(U\) was measured. Draw the graph \(T \leftarrow U \rightarrow Y\) first; include confounders, never mediators or colliders.

When the confounder is not in your data

        U  (unobserved)
       / \
      v   v
      T -> Y
  • Regression adjustment cannot close a backdoor through a variable you do not have. No amount of data on \(T\) and \(Y\) alone recovers the effect.
  • Randomise if you can: an A/B test makes \(T\) independent of \(U\) and the difference of means is causal.
  • If you cannot, two observational designs replace the missing control with a structure:
    • Difference-in-differences — a control group that shares the same time trend.
    • Instrumental variables — a source of variation in \(T\) that has nothing to do with \(U\).

Difference-in-differences: the gap between gaps

Treated group gets a policy between period 0 and 1; the control group does not. \[\hat\tau_{\text{DiD}} = (\bar Y^{\text{tr}}_{1} - \bar Y^{\text{tr}}_{0}) - (\bar Y^{\text{ctl}}_{1} - \bar Y^{\text{ctl}}_{0})\]

The identifying assumption of DiD is:

  • The two groups have the same level of \(Y\) before treatment
  • Treatment was randomly assigned
  • Without treatment, both groups would have followed parallel trends
  • The control group is larger than the treated group

Simulate a two-group, two-period panel

Treated group starts 1.0 higher, everyone drifts up 0.5, and the policy adds 0.8 to the treated group in period 1.

Both naive numbers are wrong: the post gap (1.85) includes the pre-existing level difference; the before-after (1.31) includes the common drift.

Your turn: compute the DiD by hand

did currently holds the treated group’s before-after change. Subtract the control group’s change so that did is the difference-in-differences.

The regression \(y = \alpha + \beta\,\text{group} + \gamma\,\text{period} + \delta\,(\text{group} \times \text{period})\) gives \(\hat\delta\) = 0.861 (se 0.051) — identical to the hand calculation, now with a standard error. Parallel trends cannot be tested after treatment; with more pre-periods, check that the two groups moved in parallel before it.

Instrumental variables: borrow a lottery

An instrument \(Z\) moves \(T\) but touches \(Y\) only through \(T\). Three conditions: relevance (\(Z \to T\)), exclusion (no \(Z \to Y\) path except via \(T\)), independence (\(Z \perp U\)).

Which condition can never be verified from the data alone?

  • Relevance — \(Z\) predicts \(T\)
  • Exclusion — \(Z\) affects \(Y\) only through \(T\)
  • That \(n\) is large enough
  • That \(T\) is binary

Classic instruments: distance to college for schooling (Card 1995), draft-lottery number for military service (Angrist 1990), rainfall for agricultural income. Two-stage least squares: regress \(T\) on \(Z\), then \(Y\) on \(\hat T\).

2SLS by hand with numpy

Hidden \(U\) drives \(T\) and \(Y\); true effect of \(T\) on \(Y\) is 1.0; \(Z\) is a clean shock to \(T\).

OLS says 2.013 — twice the truth, because \(U\) pushes \(T\) and \(Y\) the same way. 2SLS uses only the part of \(T\) that \(Z\) explains and lands on 1.027. The one-instrument case reduces to the ratio \(\text{cov}(Z,Y)/\text{cov}(Z,T)\).

Weak instruments: when the lottery barely moves T

Strong instrument: F = 637. Weak one: F = 7.0 and the 2SLS estimate drifts to 0.72 with a huge standard error. Rule of thumb: first-stage F above 10, or do not trust the second stage.

Design Replaces the missing control with Fails when
Regression adjustment the measured confounder a confounder is unmeasured
Difference-in-differences a control group’s time trend trends are not parallel
Instrumental variables an exogenous shock to \(T\) \(Z\) is weak or has its own path to \(Y\)

What you discovered

  • A predictor with t = 24 and R² = 0.23 had a causal effect of zero; the correlation came entirely from the hidden trait behind both \(T\) and \(Y\).
  • Regression adjustment recovers the effect (0.066 ≈ 0; 0.45 ≈ 0.5) — but only for confounders you measured.
  • DiD nets out level differences and common trends: 0.861 for a true 0.8. Its price is the parallel-trends assumption.
  • 2SLS turned an OLS estimate of 2.01 into 1.03 using a clean instrument; with F = 7 the instrument was too weak to trust.
  • Never report a causal number without naming the assumption it rests on.