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 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]