Math for Causal Inference
All simulators

Two-Stage Least Squares

Watch both stages, and see why manual second-stage standard errors are wrong.

Day 64: 2SLS in Matrix Form
STAGE 1: x on z
-4-2024-3-2-10123instrument zregressor x
STAGE 2: y on fitted x̂
-2024-2-1012fitted x̂outcome y
first stage π̂
0.477
2SLS
0.387
truth 0.500
OLS
1.126
correct SE
0.1027
residuals y − b̂·x
manual 2nd-stage SE
0.1337
residuals y − b̂·x̂ (wrong)

Stage 1 projects the endogenous regressor on the instrument (left); stage 2 regresses the outcome on the fitted values (right). The slope is 2SLS. Standard errors must use residuals computed with the actual x, not the fitted x̂: compare the two.