An econometric perspective on instrumental variables
Chapter 23 is where the design-based IV story becomes an econometrics workflow: controls, overidentification, and alternative representations of the same parameter.
Show code
from pathlib import Pathimport mathimport matplotlib.pyplot as pltimport numpy as npimport pandas as pdimport crabbymetrics as cmnp.set_printoptions(precision=4, suppress=True)def repo_root():for candidate in [Path.cwd().resolve(), *Path.cwd().resolve().parents]:if (candidate /"ding_w_source").exists():return candidateraiseFileNotFoundError("could not locate ding_w_source from the current working directory")def iv_moments(theta, data): resid = data["y"] - data["x"] @ thetareturn data["z"] * resid[:, None]def iv_jacobian(theta, data):del thetareturn-(data["z"].T @ data["x"]) / data["x"].shape[0]
TwoSLS coefficient: 0.1571
Control-function coefficient on education: 0.1571
4 Anderson-Rubin Grid
The source R script also inverts a reduced-form test over candidate education returns. For a candidate \(\beta\), regress \(Y - \beta D\) on controls and the excluded instrument. If the excluded instrument is still predictive, that candidate \(\beta\) is inconsistent with the IV moment. This grid uses nearc4, matching the script’s single-instrument Anderson-Rubin calculation.