One of the foundational challenges in econometrics is Omitted Variable Bias (OVB): when an unmeasured variable affects both your treatment and your outcome, your estimates will be biased. In previous weeks we addressed this with fixed effects (Week 11) and difference-in-differences (Week 12). This week we tackle a powerful alternative: Instrumental Variables (IV).

This lecture covers:

  • Why OVB persists even with fixed effects and DiD
  • The mechanics of Two-Stage Least Squares (2SLS)
  • Using Stata’s ivreg command
  • Diagnostic tests for instrument validity
  • Panel IV with xtivreg

We will use Mroz.dta, a classic dataset used by labor economists to estimate the returns to education for women. A simple regression of lwage (log average wage) on educ suffers from severe OVB (e.g., unobserved ability, ambition, or family social capital). We will instrument educ using parental education (motheduc and fatheduc).

The Endogeneity Problem

When we estimate:

\[\text{lwage} = \beta_0 + \beta_1 \cdot \text{educ} + \beta_2 \cdot \text{exper} + \beta_3 \cdot \text{expersq} + \varepsilon\]

the variable educ is likely correlated with the error term ε. Unobserved ability, ambition, and family background all influence both how much education someone gets and how much they earn. This means the OLS coefficient on educ is biased — it captures the return to education plus the return to all those unobserved confounders.

* load the mroz dataset
	use             "$data/Mroz.dta", clear
	
* run naive ols regression
	reg             lwage educ exper expersq
	eststo          ols

The coefficient on educ tells us the return to a year of education, but we can’t interpret it causally because of OVB.

The Mechanics of 2SLS

IV solves the endogeneity problem by finding a source of exogenous variation — a variable $Z$ (the “instrument”) that affects our outcome $Y$ only through its effect on the treatment $X$. To be valid, the instrument must meet two conditions:

  1. Relevance: $Z$ must actually affect $X$. We need a strong, statistically significant relationship between the instrument and the endogenous variable. If the relationship is weak, the instrument provides very little exogenous variation, which can perversely magnify whatever bias remains.
  2. Exogeneity (The Exclusion Restriction): $Z$ must not affect $Y$ directly, nor be correlated with the error term $u$. The instrument can only impact the outcome through the treatment variable. Unlike relevance, we cannot statistically test exogeneity; it relies entirely on your theoretical economic reasoning. Even with multiple instruments, true exogeneity remains an untestable, maintained assumption.

We instrument educ using parental education (motheduc and fatheduc). The logic: parents’ education strongly influences how much schooling their child gets (Relevance), but conditional on the child’s own education, years of parental education should not directly affect the child’s adult wages (Exogeneity).

We implement IV using Two-Stage Least Squares (2SLS):

  • Stage 1: Regress $X$ on $Z$ (and our other controls) to isolate the variation in $X$ that is driven purely by $Z$. Predict the fitted values $\hat{X}$.
  • Stage 2: Regress $Y$ on $\hat{X}$. Because $\hat{X}$ is driven purely by the exogenous instrument, our coefficient is an unbiased causal estimate.

Manual 2SLS

Let’s perform 2SLS step by step to build intuition:

* === first stage ===
* regress the endogenous variable on instruments and controls
	reg             educ motheduc fatheduc exper expersq
	eststo          first_stage

* predict the fitted values from the first stage
	predict         educ_hat, xb

* === second stage ===
* regress the outcome on the predicted treatment and controls
	reg             lwage educ_hat exper expersq
	eststo          manual_2sls

The first stage isolates the part of educ that is driven by parental education. The second stage uses only that exogenous variation to estimate the return to education.

A critical caveat: while the coefficients from manual 2SLS are correct, the standard errors are wrong. Stata doesn’t know that educ_hat is an estimated variable rather than a real observed one, so it underestimates the uncertainty. We’ll fix this with ivreg next.

Do Exercise 1 - Manual 2SLS

Estimating with ivreg

Doing 2SLS by hand is intuitively useful, but we should always use Stata’s built-in ivreg command for actual analysis. It runs both stages simultaneously and correctly adjusts the standard errors. The syntax requires us to specify the endogenous variable and the instruments in parentheses:

ivreg depvar [exogenous_vars] (endogenous_var = instruments)

* estimate the return to education using parental education as instruments
	ivreg           lwage exper expersq ///
	                    (educ = motheduc fatheduc), ///
	                    vce(robust)
	eststo          iv_reg

ivreg2: An Enhanced IV Estimator

While ivreg is the built-in Stata command for IV, the user-written ivreg2 package (Baum, Schaffer, and Stillman) is the preferred command among applied researchers. ivreg2 has the same basic syntax as ivreg but provides several important advantages:

  • Automatic first-stage diagnostics: ivreg2 reports the Cragg-Donald and Kleibergen-Paap F-statistics for weak instrument testing directly in the output, without requiring a separate estat command.
  • Overidentification tests: It reports the Hansen J-statistic (a heteroskedasticity-robust version of the Sargan test) automatically when you are overidentified.
  • More VCE options: It natively supports clustered, two-way clustered, HAC (Newey-West), and other standard error options. More on this in the next lecture.
  • Additional estimators: Beyond 2SLS, ivreg2 supports LIML (limited information maximum likelihood) and GMM estimators, which may have better finite-sample properties.

Install ivreg2 by adding it to the package loop in your project.do file (you’ll also need the ranktest package). The syntax is nearly identical to ivreg:

* ivreg2 with robust standard errors
	ivreg2          lwage exper expersq (educ = motheduc fatheduc), ///
	                    robust first

The first option tells ivreg2 to display the full first-stage regression results alongside the second stage, making it easy to assess instrument strength at a glance.

Notice: the coefficient on educ is identical to the manual 2SLS, but the standard errors will be different (and correct).

Do Exercise 2 - Using ivreg2

Panel Data and xtivreg

While ivreg handles cross-sectional data, what if we have panel data and want to absorb unobserved time-invariant heterogeneity using fixed effects, while also instrumenting a variable?

Stata handles this through the xtivreg command. It combines the mechanics of xtreg, fe with ivreg. The syntax is:

xtivreg depvar [exogenous_vars] (endogenous_var = instruments), fe vce(cluster cluster_var)

Just as xtreg, fe controls for time-invariant unobserved heterogeneity by demeaning within each panel unit, xtivreg, fe does the same demeaning before applying the IV procedure. This is powerful: fixed effects handle confounders that are constant over time, while the instrument handles confounders that vary with time.

xtivreg2: The Panel Extension of ivreg2

Just as ivreg2 improves on ivreg, the xtivreg2 package (also by Baum, Schaffer, and Stillman) extends xtivreg with the same suite of enhanced diagnostics:

  • Automatic weak instrument tests for the panel FE-IV setting
  • Hansen J-statistic for overidentification in panel models
  • Additional estimators: LIML and GMM within the fixed effects framework
  • Redundancy tests: Check whether a particular instrument actually contributes identifying variation after accounting for the other instruments

Install xtivreg2 by adding it to the package loop in your project.do file. The syntax mirrors xtivreg:

xtivreg2 depvar [exogenous_vars] (endogenous_var = instruments), fe cluster(cluster_var) first

Note: xtivreg2 uses cluster() as an option rather than vce(cluster ...). The first option displays the first-stage results. For your exercises this week, you will use ivreg2 and xtivreg2 to take advantage of these richer diagnostics.

Do Exercise 3 - Panel IV with xtivreg2

Diagnosing Instruments

Just because we declare a variable an instrument doesn’t magically make it a valid one. Stata provides a suite of post-estimation diagnostic tests that we should run.

1. Relevance (Weak Instruments)

If our instruments don’t strongly predict the treatment variable, they are “weak” and will amplify bias rather than fix it. We test this by running estat firststage after ivreg. A common rule of thumb is to look for an F-statistic greater than 10, though modern econometrics often demands higher thresholds (Stock and Yogo, 2005).

2. Endogeneity (Durbin-Wu-Hausman Test)

If the treatment variable isn’t actually endogenous, we shouldn’t be using IV. IV throws away variation to achieve consistency, making it less precise than OLS — so if OLS is already consistent, we prefer it. We test endogeneity using estat endogenous. If the p-value is $< 0.05$, the variable is endogenous and IV is justified.

3. Overidentification (Sargan-Basmann Test)

When we have more instruments than endogenous variables (our case: 2 instruments, 1 endogenous variable), we are overidentified. As noted earlier, the exogeneity of instruments (the exclusion restriction) is a maintained assumption and cannot be directly tested. However, overidentification allows us to test the coherence of our instruments. This tests whether the “extra” instruments yield statistically different estimates under the working assumption that at least enough instruments to identify the model are valid. If the p-value is $> 0.05$, we fail to reject the null, meaning our instruments are mathematically consistent with each other.

Let’s run all three tests:

* run the iv regression without robust ses
* (some post-estimation tests require homoskedasticity)
	ivreg           lwage exper expersq (educ = motheduc fatheduc)
	
* test for weak instruments (first stage F-statistic)
	estat           firststage 
	
* test for endogeneity of the education variable
	estat           endogenous
	
* test for overidentifying restrictions
	estat           overid

Interpreting the results: the first-stage F-statistic should exceed 10 (relevance). The endogeneity test tells us whether IV is necessary. The overidentification test tells us whether our instruments yield coherent, mathematically consistent estimates. Together, these three tests form your complete diagnostic checklist.

Do Exercise 4 - Instrument Diagnostics

What does IV estimate?

When we run IV, what exactly is the treatment effect we are estimating? It is fundamentally different from the Average Treatment Effect (ATE) that we typically want to estimate and might get from a perfectly executed randomized experiment.

Instead, IV estimates a Local Average Treatment Effect (LATE). To understand why, consider how people in our dataset respond to the instrument (parental education) and how that affects the treatment (their own education). We can divide our sample into three conceptual groups:

  1. Compliers: People whose treatment status is shifted by the instrument in the expected direction. If their parents had more education, they get more education.
  2. Always-takers / Never-takers: People who are completely unaffected by the instrument. They would either always pursue high education (regardless of their parents) or never pursue it (regardless of their parents).
  3. Defiers: People who do the exact opposite of what the instrument suggests. A key assumption of IV, known as monotonicity, is that there are no defiers.

Because IV relies on variation generated by the instrument, it completely ignores the “always-takers” and “never-takers” (since their behavior wasn’t changed). Therefore, IV only estimates the effect for the compliers.

The LATE is the average treatment effect specifically for these compliers—the people at the margin whose behavior is actually swayed by the instrument. This means we cannot simply interpret our IV coefficient as the effect of education for the entire population. Whether the LATE is useful depends on your research question and whether the “compliers” are the group you care about for policy.

Summary

  • Instrumental Variables allow causal inference when treatment variables are endogenous
  • A valid instrument must be relevant (strongly predicts treatment) and exogenous (only affects outcomes through treatment)
  • 2SLS isolates exogenous variation in the first stage and uses it in the second stage
  • Always use ivreg (or ivreg2) rather than manual 2SLS — the standard errors from manual 2SLS are incorrect
  • ivreg2 is preferred over ivreg because it automatically reports weak instrument tests, overidentification statistics, and supports additional estimators (LIML, GMM)
  • For panel data with fixed effects, use xtivreg or xtivreg2; xtivreg2 provides the same diagnostic advantages as ivreg2
  • Always export your results as publication-ready tables and figures

Next lecture: Standard Errors & Inference.