Skip to content
Tutorials Center
My learning

Topics

Lesson 22 of 36 ยท Regression

Logit, Probit and Marginal Effects

Model binary outcomes in Stata with logit and probit, read odds ratios, compute average marginal effects with margins and check classification with estat.

Many outcomes are yes or no: employed, defaulted, passed, voted. A straight-line regression on a 0/1 outcome can predict probabilities below 0 or above 1. Logistic (logit) and probit regression solve this by modelling the probability through an S-shaped curve. In Stata, logit and probit are the commands, and margins is the tool that turns their coefficients into effects you can explain to a non-statistician.

Stata cannot run here. Commands are read-only, and the runnable blocks are Python stand-ins (a hand-written logistic regression in NumPy) that show what the estimator does. We never print real Stata output.

Fitting the models

STATA
sysuse auto, clear
logit foreign mpg weight
probit foreign mpg weight
logit foreign c.mpg i.rep78, or

The outcome must be 0/1 (or any variable with two distinct non-missing values where nonzero means success). Stata fits the model by maximum likelihood, printing the iteration log, then a table with Coefficient, Std. err., z, P>|z| and a confidence interval. Instead of R-squared you get the log likelihood and a pseudo R-squared; the likelihood-ratio chi-squared tests that all slopes are zero.

Coefficients are on the log-odds scale (logit) or the z-score scale (probit). The sign and significance are readable immediately: positive means higher probability. The size is not directly meaningful, which is why we transform.

Odds ratios

The option or (or the command logistic) reports exponentiated coefficients:

STATA
logit foreign mpg weight, or
logistic foreign mpg weight

An odds ratio of 1.25 for mpg means each extra mile per gallon multiplies the odds of the outcome by 1.25, a 25% rise in odds. Odds ratios are not risk ratios; when the outcome is common they overstate the change in probability. Never say "25% more likely" for an odds ratio.

Average marginal effects

The effect of a variable on the probability depends on where you stand on the S-curve. margins computes it explicitly:

STATA
logit foreign c.mpg c.weight i.rep78
margins, dydx(mpg weight)          // average marginal effects
margins, at(mpg=(15 20 25 30))     // predicted probabilities
margins rep78                      // average probability for each category
marginsplot

dydx reports the average change in probability for a one-unit rise in each variable, computed observation by observation and then averaged. Because logit and probit use the same idea but different curves, their average marginal effects are usually nearly identical even when their coefficients differ by a factor of about 1.6. Reporting marginal effects makes the two comparable and avoids the odds-ratio trap.

Stand-in: logistic regression from scratch

Maximum likelihood for the logit is usually solved by iteratively reweighted least squares (IRLS). The block below simulates data, runs that algorithm, and prints coefficients, odds ratios and the average marginal effect of x computed with the formula beta * p * (1 - p).

Python Logit by IRLS and average marginal effect (Python stand-in)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Compare the average marginal effect with the raw coefficient: they live on different scales. The last line shows a common shortcut, dividing a logit coefficient by 4 to get an upper bound on the probability change near 0.5. It is a rough guide, not a replacement for margins.

Classification and fit

STATA
estat classification, cutoff(0.5)
lroc
lsens
estat gof, group(10)

estat classification builds the two-by-two table of predicted versus actual outcomes and reports sensitivity, specificity and overall accuracy at a cutoff (0.5 by default). lroc plots the ROC curve and the area under it, which measures how well the model ranks cases regardless of cutoff. estat gof is the Hosmer-Lemeshow test. Accuracy alone misleads when the outcome is rare: a model that always predicts zero can be 95% accurate.

The stand-in below computes the same classification table and the AUC with the rank formula.

Python Classification table and AUC (Python stand-in)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Which one: logit or probit?

Both give almost the same fitted probabilities. Logit has the odds-ratio interpretation and is common in medicine and the social sciences; probit is common in economics. Pick one, say why, and report marginal effects. If you need to handle rare events, a very small sample or perfect prediction, see firthlogit (a user-written command) or exlogistic; Stata will drop variables that predict the outcome perfectly and tell you.

Other binary-outcome models follow the same pattern: ologit and oprobit for ordered categories, mlogit for unordered categories, poisson and nbreg for counts. Factor variables from the previous lesson and the diagnostics habits from regression diagnostics carry over, including vce(robust).

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What scale are logit coefficients on?

    A logit coefficient is the change in the log odds of the outcome for a one-unit change in the predictor.
  2. 2. An odds ratio of 1.25 means

    Odds ratios multiply the odds; they are not risk ratios or percentage-point changes.
  3. 3. Which command reports average effects on the probability?

    margins with dydx reports the average marginal effect of a variable on the predicted probability.
  4. 4. Why is accuracy a poor measure for a rare outcome?

    Use sensitivity, specificity and the ROC area, which separate how well each class is detected.

Summary

  • logit and probit model binary outcomes by maximum likelihood; coefficients are on link scales.
  • Use or for odds ratios, but explain them as multiplying the odds.
  • margins, dydx() gives average marginal effects on the probability scale.
  • estat classification, lroc and estat gof assess fit; the Python blocks are stand-ins.

Next: Panel data and xtset