#1821·dowhy

iv.instrumental_variable with 2+ instruments fits 2SLS without an intercept (biased estimate)

Author: lucaluo925Created Sep 24, 2026Updated Sep 25, 2026
Labelsbug

Describe the bug With two or more instruments, method_name="iv.instrumental_variable" runs 2SLS without a constant in either stage, so the effect is badly biased whenever the instruments/treatment/outcome are not mean-zero (e.g. binary 0/1 instruments). In the example below the true effect is 2; DoWhy returns 4.22, while the single-instrument path and textbook 2SLS with a constant both give ≈ 2.00.

Issue #66 (2019) reported that the IV estimator didn't include an intercept; the single-instrument path now uses a covariance ratio (intercept-invariant), but the multi-instrument path in dowhy/causal_estimators/instrumental_variable_estimator.py still calls

python
ivmodel = IV2SLS(est_outcome, est_treatment, self._estimating_instruments)
reg_results = ivmodel.fit()
iv_est = sum(reg_results.params)

with no constant in the regressors or the instrument matrix. sum(reg_results.params) would also add up unrelated coefficients if more than one regressor were present. The existing tests use mean-zero instruments from linear_dataset, which hides the bias.

Suggested fix: add a constant to both matrices (sm.add_constant(treatment), sm.add_constant(instruments)) and take the treatment coefficient by name instead of sum(params).

AI disclosure: I found this with the help of an AI assistant (Claude), which also ran the reproduction below and drafted this issue; I reviewed it before posting.

Steps to reproduce the behavior

python
# IV estimator with two instruments: 2SLS fitted without an intercept
import numpy as np, pandas as pd, warnings; warnings.filterwarnings("ignore")
from dowhy import CausalModel
from statsmodels.sandbox.regression.gmm import IV2SLS
rng = np.random.default_rng(0); n = 20000
Z1 = rng.binomial(1, 0.5, n).astype(float); Z2 = rng.binomial(1, 0.5, n).astype(float)  # two binary encouragement arms
U = rng.normal(size=n)
X = 3.0 + Z1 + Z2 + U + rng.normal(size=n)        # treatment has nonzero mean
Y = 10.0 + 2.0 * X + 2 * U + rng.normal(size=n)     # true effect = 2
df = pd.DataFrame(dict(Z1=Z1, Z2=Z2, X=X, Y=Y))
g = "digraph{Z1->X;Z2->X;U->X;U->Y;X->Y}"
m = CausalModel(df, "X", "Y", graph=g)
ie = m.identify_effect(proceed_when_unidentifiable=True)
est = m.estimate_effect(ie, method_name="iv.instrumental_variable")
print("dowhy IV (2 instruments):", est.value)
# single instrument path for comparison (Cov ratio -> intercept-consistent)
est1 = m.estimate_effect(ie, method_name="iv.instrumental_variable", method_params={"iv_instrument_name": "Z1"})
print("dowhy IV (Z1 only):      ", est1.value)
exog = np.column_stack([np.ones(n), X]); inst = np.column_stack([np.ones(n), Z1, Z2])
print("textbook 2SLS w/ const:  ", IV2SLS(Y, exog, inst).fit().params[1])
print("true effect:              2.0")

Output:

dowhy IV (2 instruments): 4.224120051930772
dowhy IV (Z1 only):       2.000374918616442
textbook 2SLS w/ const:   2.006885535411103
true effect:              2.0

Expected behavior With two binary instruments the estimate should be ≈ 2.0, matching textbook 2SLS with an intercept.

Version information:

  • DoWhy main (cc23521, 2026-09-18); statsmodels 0.15.0; Python 3.11

Additional context Happy to open a PR with a regression test using non-mean-zero (binary) instruments.