Instrumental variables & 2SLS for an endogenous treatment (ivreg)
@misc{ivreg,
title = {ivreg},
author = {Fox and Kleiber and Zeileis},
howpublished = {\url{https://zeileis.github.io/ivreg/}},
note = {Software / documentation}
}Follow the analysis.
Select a node to explore the method
Outcome, endogenous treatment, instrument
Data preparation — shapes the raw inputs into what the estimator expects.
Assemble Y, D, Z, X. The instrument must affect D and only affect Y through D.
library(ivreg)
# y ~ d + x | z + x (endogenous d, instrument z)
Before using this step, make its assumptions and its output explicit. A useful peer note explains what you would check, what could go wrong, or what would change your interpretation.
Questions to explore- Which assumption matters most here, and what evidence could challenge it?
- What would you check before passing this output to the next step?
Choose a question to start your comment.
Peer discussion
- Bring your experience, a question, or a different perspective.
Log in to comment on this step.
Check instrument strength (first stage)
A pre-flight check — run this before trusting any estimate downstream.
A weak instrument (first-stage F ≲ 10) gives biased, unreliable 2SLS.
summary(lm(d ~ z + x))$fstatistic
Before using this step, make its assumptions and its output explicit. A useful peer note explains what you would check, what could go wrong, or what would change your interpretation.
Questions to explore- Which assumption matters most here, and what evidence could challenge it?
- What would you check before passing this output to the next step?
Choose a question to start your comment.
Peer discussion
- Bring your experience, a question, or a different perspective.
Log in to comment on this step.
Two-stage least squares (ivreg)
The core estimate — where the causal quantity itself is computed.
Project D on the instrument, then regress Y on the fitted treatment.
fit <- ivreg(y ~ d + x | z + x, data = df)
summary(fit)
Before using this step, make its assumptions and its output explicit. A useful peer note explains what you would check, what could go wrong, or what would change your interpretation.
Questions to explore- Which assumption matters most here, and what evidence could challenge it?
- What would you check before passing this output to the next step?
Choose a question to start your comment.
Peer discussion
- Bring your experience, a question, or a different perspective.
Log in to comment on this step.
Interpret as a complier effect (LATE)
Uncertainty quantification — standard errors, intervals, and aggregation.
Under monotonicity the estimand is the effect for compliers, not everyone.
# robust SEs; the estimate is the LATE
Before using this step, make its assumptions and its output explicit. A useful peer note explains what you would check, what could go wrong, or what would change your interpretation.
Questions to explore- Which assumption matters most here, and what evidence could challenge it?
- What would you check before passing this output to the next step?
Choose a question to start your comment.
Peer discussion
- Bring your experience, a question, or a different perspective.
Log in to comment on this step.
Inputs & data
Outcome Y, an endogenous treatment D, an instrument Z (relevant + excludable), and covariates X.
Show data format & exampleHide example
Format — one row per unit: y, d (endogenous), z (instrument), covariates x.
y d z x1
3.1 1 1 0.4
1.8 0 0 -0.1
2.4 0 1 1.2
⚠️ Unofficial community showcase of ivreg. Not affiliated with the authors; all credit to them.
When treatment is endogenous, an instrument identifies the complier (LATE) effect via two-stage least squares — after you check the instrument is strong.
Discuss the workflow (0)
Log in to join the discussion.