Fit a panel IV (2SLS) regression absorbing entity (and time) fixed effects.
The panel analogue of :func:analyze_iv_regression and of Stata’s xtivreg2 ... fe: it instruments the endogenous regressor(s) while absorbing entity fixed effects (and, when twoway, time fixed effects), clustering by entity by default. The panel ids follow the usual expdpy resolution — explicit entity / time win, otherwise the pair declared by :func:expdpy.set_panel is used.
Panel identifiers (unit and period). Resolved from :func:expdpy.set_panel when not passed; entity is required, time is needed only for the two-way specification.
Panel identifiers (unit and period). Resolved from :func:expdpy.set_panel when not passed; entity is required, time is needed only for the two-way specification.
As :func:analyze_iv_regression, with the entity/time fixed effects absorbed.
Examples
Instrument night-time lights (a proxy for local economic activity) with lagged rainfall and drought across African regions, absorbing region and year fixed effects and clustering by region — a panel xtivreg2 fe. The first-stage F is well above 10:
This IV (2SLS) regression instruments **log_lights_lag1** with *rain_lag2, drought_lag2*, relating it to **conflict**. Two-stage least squares isolates the part of the endogenous regressor that moves with the instruments, purging the endogeneity that biases ordinary least squares.
- **log_lights_lag1** (instrumented): a one-unit increase is associated with conflict that is 0.296 lower (statistically significant at the 1% level).
The first-stage F is 25.3 — **above** the conventional weak-instrument threshold of 10, so the instruments are reasonably strong.
IV is trustworthy only when the instruments are both **relevant** (a strong first stage) and **excludable** — related to conflict solely through the instrumented regressor.
_These are associations, not causal effects. A causal reading needs a research design — see `explain('correlation_vs_causation')`._