Instrumental Variables with 2SLS

hard
Unit 23 · Causal Inference0/0 to milestone

When a treatment xx is correlated with unobserved confounders, OLS is biased. An instrument zz affects yy only through xx. Two-stage least squares:

  1. regress xx on zz (with intercept) and take fitted values x^\hat x
  2. regress yy on x^\hat x (with intercept); the slope is the IV estimate
Pro problem

Unlock this and every premium problem across all tracks — plus hidden-test grading, advanced AI engineering modules and new content every week.

Start 7-day free trial
solution.py · Python 3.13
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Instrumental Variables with 2SLS · TechGradify