HECKMAN SELECTION MODEL · TWO-STEP · MAXIMUM LIKELIHOOD · INVERSE MILLS RATIO · RUNS IN YOUR BROWSER · NOTHING UPLOADED

Your outcome is only seen for the rows that were selected. Does that bias the answer?

A wage exists only for people in paid work, a loan's loss only for loans that were approved, a test score only for students who sat the test. If whatever decides who is selected also moves the outcome, a regression on the selected rows describes them and not the population, and more data does not fix it. The Heckman selection model fits an equation for who is selected next to the outcome equation, lets their unobserved parts be correlated (ρ), and corrects for it.

Upload one row per unit, selected or not. You get the selection probit, OLS on the selected rows for comparison, Heckman's two-step estimator with the Heckman-Greene corrected standard errors, and full maximum likelihood with conventional, robust or clustered errors, plus ρ with its likelihood-ratio and Wald tests and the two checks that decide whether to trust the correction: is there an exclusion restriction, and how collinear is the inverse Mills ratio with the regressors.

Nothing you enter leaves this browser tab. Statistical output from data you supply, not advice. Not legal, tax, or financial advice, and not medical or policy advice.

Your data

Paste data or load the example.

Method and citation

The model: a unit is selected when zγ + u > 0, and its outcome y = xβ + e is seen only then; (u, e) are bivariate normal with var(u) = 1, var(e) = σ² and correlation ρ. For a selected row E[y | x, selected] = xβ + ρσλ(zγ), with λ(c) = φ(c)/Φ(c) the inverse Mills ratio, so OLS on the selected rows omits a regressor whenever ρ ≠ 0. The selection equation holds the outcome regressors as well as the exclusion restrictions you list.

Two-step (Heckman 1979): a probit of selection on z gives γ; the regression of y on x and λ(zγ) in the selected rows gives β and βλ = ρσ; σ² = e′e/n1 + βλ² mean(δ), δ = λ(λ + zγ). The standard errors are Greene's (1981) correction for the induced heteroskedasticity and the estimated γ: σ²(X*′X*)−1[X*′(I − ρ²D)X* + Q](X*′X*)−1, Q = ρ²(X*′DZ)Vγ(Z′DX*). A two-step ρ outside [−1, 1] is set to ±1, as is usual.

Maximum likelihood (Heckman 1974): log L sums log Φ(−zγ) over unselected rows and log Φ((zγ + ρe/σ)/√(1 − ρ²)) − log σ + log φ(e/σ) over selected rows, in atanh ρ and log σ. It is maximised by damped Newton steps with an analytic gradient and a finite-difference Hessian, from the two-step estimates and again from ρ = 0, keeping the higher peak (and saying so if they differ). Conventional errors invert the Hessian; robust errors are the sandwich (White 1982); clustered errors sum each row's score within clusters (Liang & Zeger 1986) with the factor G/(G − 1). The intervals for ρ and σ are transformed from atanh ρ and log σ, so they stay in range.

Checks (Puhani 2000): whether any variable enters selection without entering the outcome, and the R² of λ on the outcome regressors in the selected rows; the page warns above 0.8 and 0.95. The CSV download carries a spreadsheet formula-injection guard on text cells.

Verified by tests in the source against statsmodels 0.15 and scipy 1.18 (run only as external programs to record reference numbers) on two specifications of the example: probit coefficients and standard errors, OLS with conventional, HC1 and clustered errors, the two-step coefficients and corrected standard errors (the correction recomputed separately in numpy) within 1e-12, and the maximum-likelihood estimates (within 1e-7) and standard errors of all three kinds (within 1e-5) against an independent scipy maximisation with statsmodels' numerical Hessian and scores. A Monte Carlo study of the intervals is in the source (eval/coverage-output.txt).

Limits

BibTeX

@article{heckman1979sample,
  author = {Heckman, James J.}, title = {Sample Selection Bias as a Specification Error},
  journal = {Econometrica}, volume = {47}, number = {1}, pages = {153--161}, year = {1979}, doi = {10.2307/1912352}
}
@article{greene1981sample,
  author = {Greene, William H.}, title = {Sample Selection Bias as a Specification Error: A Comment},
  journal = {Econometrica}, volume = {49}, number = {3}, pages = {795--798}, year = {1981}, doi = {10.2307/1911523}
}
@article{heckman1974shadow,
  author = {Heckman, James J.}, title = {Shadow Prices, Market Wages, and Labor Supply},
  journal = {Econometrica}, volume = {42}, number = {4}, pages = {679--694}, year = {1974}, doi = {10.2307/1913937}
}
@article{white1982maximum,
  author = {White, Halbert}, title = {Maximum Likelihood Estimation of Misspecified Models},
  journal = {Econometrica}, volume = {50}, number = {1}, pages = {1--25}, year = {1982}, doi = {10.2307/1912526}
}
@article{liang1986longitudinal,
  author = {Liang, Kung-Yee and Zeger, Scott L.}, title = {Longitudinal Data Analysis Using Generalized Linear Models},
  journal = {Biometrika}, volume = {73}, number = {1}, pages = {13--22}, year = {1986}, doi = {10.1093/biomet/73.1.13}
}
@article{puhani2000heckman,
  author = {Puhani, Patrick A.}, title = {The Heckman Correction for Sample Selection and Its Critique},
  journal = {Journal of Economic Surveys}, volume = {14}, number = {1}, pages = {53--68}, year = {2000}, doi = {10.1111/1467-6419.00104}
}

Questions

What is sample selection bias?

The outcome you want to explain is recorded only for some units, and whether a unit is recorded depends on things that also move the outcome. Wages exist only for people who work; if the people who choose to work are those with unusually good offers, a regression on workers describes them, not everyone. The bias does not shrink with more data.

What does the Heckman correction do?

It models selection with a probit and assumes the unobserved parts of selection and of the outcome are jointly normal with correlation rho. Selected rows then have an expected error of rho times sigma times the inverse Mills ratio, so adding that ratio to the regression (the two-step estimator) or fitting both equations together (maximum likelihood) removes the bias.

Do I need an exclusion restriction?

In practice, yes: a variable that changes who is selected but has no direct effect on the outcome, such as young children for whether a woman works. Without one the model is identified only by the shape of the normal distribution, the inverse Mills ratio is nearly a linear function of the regressors, and estimates swing with small changes. The page warns when there is none and reports how collinear the ratio is.

Should I report the two-step or the maximum likelihood estimates?

When the normal model holds, maximum likelihood is more efficient and its tests of rho are standard. The two-step estimator is simpler and somewhat less sensitive to how the likelihood is shaped, but its standard errors need the Heckman-Greene correction, which this page applies. Report both if they differ: a large gap is itself a sign that the model is fragile.

How do I test whether there is selection bias at all?

Test rho = 0. The page gives the likelihood-ratio test (the selection model against a probit and a regression fitted separately), the Wald test on atanh(rho), and the t-test on the inverse Mills ratio in the two-step regression. Not rejecting does not prove there is no selection, especially with a weak exclusion restriction.

Does it match Stata, R or Python?

On two specifications of the example data, the probit, OLS (conventional, HC1 and clustered) and the two-step coefficients and corrected standard errors agree with statsmodels and numpy within 1e-12. The maximum-likelihood estimates agree with an independent scipy maximisation within 1e-7 and all three kinds of standard error within 1e-5, the size of the error in the reference's numerical second derivatives. It has not been run against Stata heckman or R sampleSelection.

Is my data uploaded anywhere?

No. The file is read and analysed by JavaScript in this browser tab. There are no accounts, cookies or analytics vendors.