Say an analyst wants to know how much one extra year of education raises wages. She has a survey with education for everyone, but wages only for people who have a job. She runs a regression on the workers and gets an effect that looks too low. The problem is not her model. It is who made it into the data.
The Heckman selection model is a two-step method for estimating a regression when the outcome is only observed for a non-random part of the sample. Step one fits a probit model for who gets observed. Step two adds a correction term, the inverse Mills ratio, to the outcome regression. James Heckman introduced the method in 1979, and it remains the standard starting point for selection bias in economics, health and marketing data. This guide explains the idea and runs it on a simulation where we know the true answer.
Key Takeaways
- Selection bias happens when the rows you can see differ from the rows you cannot, in ways linked to the outcome.
- The Heckman model fixes this in two steps: a probit model for selection, then a regression that includes the inverse Mills ratio.
- The method needs at least one variable that affects selection but not the outcome (an exclusion restriction). Without one, the correction is fragile.
- In our simulation, plain OLS on the observed rows estimated the education effect at 0.040. The Heckman two-step estimate was 0.086, close to the true value of 0.08.
- Standard errors from the second-step OLS are not correct as printed. Use a package that adjusts them or bootstrap the whole two-step procedure.
What Is Selection Bias?
Selection bias is the error you get when the sample you analyze was chosen by a process that is related to the outcome you are studying. In the wage example, people decide whether to work. Those with high wage offers are more likely to take a job, so the workers are not a random draw from everyone.
Heckman’s insight, in “Sample Selection Bias as a Specification Error” (Econometrica, 1979, volume 47, pages 153 to 162), was to treat this as a missing variable problem. The regression on workers leaves out a term that captures how selection shifts the average error. If you can estimate that term, you can add it back. The earlier working paper version is free to read as NBER Working Paper 172.
That framing links directly to omitted variable bias: the inverse Mills ratio is the omitted variable.
How the Heckman Model Works
The model has two equations that share correlated errors.
- Selection equation. A person is observed (works) when
Z·γ + u > 0. HereZholds the variables that drive selection. - Outcome equation. The outcome is
y = X·β + e, but only for observed rows.
If u and e are correlated, then among observed rows the average of e is not zero. Under the assumption that both errors are jointly normal, that average equals ρσ · λ(Z·γ), where λ is the inverse Mills ratio:
λ(z) = φ(z) / Φ(z) Here φ is the standard normal density and Φ is its cumulative distribution. The inverse Mills ratio is large when a row was unlikely to be selected and close to zero when selection was almost certain. It measures how much “selection luck” each observed row needed.
The two-step recipe follows:
- Fit a probit of the selection indicator on
Zusing every row. Computeλfor each row from the fitted indexZ·γ. - Fit OLS of
yonXplusλ, using only observed rows. The coefficient onλestimatesρσ, and the other coefficients are now corrected.
The Exclusion Restriction
The selection equation should include at least one variable that does not appear in the outcome equation. In wage studies, the classic choice is the number of young children at home: it affects whether someone takes a job but, the argument goes, not the wage they are offered.
Without such a variable, the correction depends only on the curve of the normal distribution. λ then moves almost in step with the other regressors, and the second-step estimates become unstable. If you cannot name a credible exclusion variable, treat any Heckman result with caution.
A Runnable Heckman Two-Step in Python
The simulation below builds 5,000 people. Education raises log wages by 0.08 per year. Having kids lowers the chance of working but has no effect on wages. The errors of the two equations have a correlation of 0.6, so people with high unobserved wage potential are also more likely to work. Because we create the data, we know the right answer.
The code uses NumPy, SciPy and the statsmodels Probit model. It ran on statsmodels 0.15.0.
import numpy as np
import statsmodels.api as sm
from scipy.stats import norm
rng = np.random.default_rng(42)
n = 5_000
# Simulated data: education affects wages; kids affects only who works.
educ = rng.normal(12, 2, n)
kids = rng.integers(0, 4, n)
# Correlated errors: unobserved traits push both work and wages up.
rho, sigma = 0.6, 1.0
cov = [[1.0, rho * sigma], [rho * sigma, sigma**2]]
u, e = rng.multivariate_normal([0, 0], cov, n).T
works = (0.5 + 0.15 * (educ - 12) - 0.6 * kids + u) > 0
log_wage = 1.0 + 0.08 * educ + e # true education effect: 0.08
print(f"Share working: {works.mean():.2f}")
# Naive OLS on workers only
X_out = sm.add_constant(educ)
naive = sm.OLS(log_wage[works], X_out[works]).fit()
print(f"Naive OLS educ coef: {naive.params[1]:.4f}")
# Step 1: probit for selection on everyone
Z = sm.add_constant(np.column_stack([educ, kids]))
probit = sm.Probit(works.astype(int), Z).fit(disp=0)
xb = Z @ probit.params
imr = norm.pdf(xb) / norm.cdf(xb) # inverse Mills ratio
print("Probit coefs (const, educ, kids):", np.round(probit.params, 3))
# Step 2: OLS on workers with the inverse Mills ratio added
X_heck = np.column_stack([X_out, imr])
heck = sm.OLS(log_wage[works], X_heck[works]).fit()
print(f"Heckman educ coef: {heck.params[1]:.4f}")
print(f"IMR coef (rho*sigma): {heck.params[2]:.4f} (true value {rho*sigma})")
# OLS on the full sample, which we could never see in real life
full = sm.OLS(log_wage, X_out).fit()
print(f"Full-sample OLS coef: {full.params[1]:.4f}") Output:
Share working: 0.38
Naive OLS educ coef: 0.0404
Probit coefs (const, educ, kids): [-1.369 0.152 -0.563]
Heckman educ coef: 0.0857
IMR coef (rho*sigma): 0.6573 (true value 0.6)
Full-sample OLS coef: 0.0833 Reading the Results
Only 38% of the simulated people work, so most wages are missing. The naive regression on workers says one year of education is worth 0.040 in log wages, about half the true 0.08. Here is why: people with less education only work when their unobserved wage potential is high, so the low-education workers in the data earn more than low-education people in general. That flattens the slope.
The probit recovers the selection rule well. Its coefficients on education (0.152) and kids (−0.563) are close to the true 0.15 and −0.6. With the inverse Mills ratio added, the education coefficient moves to 0.086, close to the true value and to the 0.083 we get from the full sample that real analysts never see. The coefficient on λ, 0.66, estimates ρσ, which is 0.6 here. A clearly positive value tells you selection was pushing the naive estimate off.
Standard Errors and Other Practical Points
- Do not trust the step-two standard errors as printed. The inverse Mills ratio is itself an estimate, and plain OLS ignores that. Bootstrap the full two-step procedure (resample rows, rerun both steps) or use software with the Heckman correction built in. Our explainer on the Poisson bootstrap shows a resampling method that is easy to apply here.
- Normality matters. The two-step formula assumes jointly normal errors. If that is far from true, the correction can be off. Semiparametric selection models relax this, at the cost of more complexity.
- Two-step versus maximum likelihood. You can also fit both equations at once by maximum likelihood. It is more precise when the assumptions hold, while the two-step method is simpler and easier to inspect.
- Check overlap. If the probit predicts selection with near certainty for almost everyone,
λhas little variation and the second step cannot separate it from the other regressors.
Where Heckman Models Are Used
The same structure appears whenever an outcome is only recorded after a choice. Loan defaults are only seen for approved applicants. Customer spend is only seen for people who opened a promotion email. Patient outcomes after a treatment are only recorded for people who chose to be treated. In each case, ask two questions: what decides who is observed, and is there a variable that affects that decision but not the outcome itself?
Back to the Wage Survey
The analyst from the opening was not wrong to suspect her estimate. In data built to look like hers, the regression on workers cut the education effect roughly in half. With a probit for who works, a number-of-children variable to drive it, and the inverse Mills ratio in the wage regression, the estimate came back to within 0.006 of the true value. The fix took two models and one extra column.
Frequently Asked Questions
What Is the Inverse Mills Ratio?
It is the ratio of the standard normal density to the standard normal cumulative distribution, evaluated at each row’s predicted selection index from the probit. In the Heckman model it measures how much each observed row’s error is shifted by being selected. Adding it to the outcome regression removes that shift.
Is the Heckman Model a Causal Method?
It corrects for one specific problem: non-random selection into the observed sample. It does not by itself handle confounding of the main treatment, such as ability affecting both education and wages. You still need a credible design for the causal question, and Heckman handles the missing outcomes on top of it.
Can I Use Logistic Regression Instead of Probit in Step One?
The classic derivation assumes normal errors, which is why the first step is a probit and the correction uses the normal density and distribution. Swapping in a logit breaks that link. If you want to move away from normality, use a method designed for it rather than mixing a logit with the normal-based ratio.
What If I Have No Exclusion Restriction?
The model is then identified only through the shape of the normal distribution, and results are often unstable and sensitive to minor changes in the specification. Report this openly, compare against the naive estimate, and consider bounding approaches that make weaker assumptions about the missing outcomes.




