Command reference

logit — model a binary outcome

Fit a logistic regression when the outcome has two states. The model relates predictors to the log odds of the positive outcome and reports coefficients, uncertainty estimates, and an overall model test.

Syntax

logit outcome predictors [if condition] [in first/last] [weight] [, options]
logit [, level(#) coef]

The first variable is the outcome; supply at least one predictor after it. Zero is the negative outcome, and every other nonmissing numeric value is treated as positive. Both outcomes must occur in the estimation sample. Coding the outcome explicitly as 0 and 1 makes its meaning easier to check.

Use i.group to include a categorical predictor with an omitted reference category; an ordinary numeric predictor enters on a continuous scale. if and in restrict the estimation rows. Optional [fw=count], [iw=weight], or [pw=weight] weights go before the comma. Frequency weights represent integer repetition counts; sampling weights imply robust standard errors. Analytic weights are not accepted.

Calling logit with no variable list displays the latest binary-logit results. To display the same estimates as odds ratios, use the related logistic command.

Options

robust / vce(robust)
Use a sandwich variance estimate for robust standard errors. The maximum-likelihood coefficients are unchanged. Choose this or another vce() form, rather than combining conflicting variance options.
vce(oim)
Calculate standard errors from the observed information matrix, using the curvature of the fitted log likelihood. This is the default unless sampling weights imply robust standard errors.
vce(opg)
Calculate standard errors from the outer products of the observations' likelihood scores. This provides an alternative variance estimate for the same coefficients.
vce(cluster group)
Use standard errors that allow correlated observations within each cluster identified by group. Choose the grouping variable to match how the observations were sampled or related.
vce(bootstrap, reps(#) seed(#))
Estimate uncertainty by refitting on samples of rows drawn with replacement. The default is 50 repetitions; reps() changes that count and optional seed() makes the draws reproducible.
vce(jackknife)
Estimate uncertainty from fits that omit one observation at a time. The displayed coefficients remain those estimated from the full analysis sample.
noconstant
Exclude the intercept. Without this option, the model includes an intercept named _cons. Removing it forces the log odds to zero when all predictors and any offset are zero.
offset(variable)
Add the named variable to the model's log-odds equation with its coefficient fixed at 1, rather than estimating a coefficient for it.
level(#)
Set the confidence-interval percentage, from 10 through 99.99; the default is 95. You can change this percentage when displaying the previous estimates.
nolog / log
Hide or show the iteration log while fitting. The log is shown by default; these options affect display rather than the fitted model.
coef
Display log-odds coefficients. This is already the default for logit; with logistic, it switches the display from odds ratios to coefficients.

Example

Use the 24 synthetic teaching records to model the binary female indicator from math and read, with robust standard errors. This small invented dataset is useful for learning how to read a coefficient table.

clear
import delimited "data/student_scores.csv"
logit female math read, robust
Open example in browser

Sample data included. Opens in a new tab; click Run.

What to look for

The coefficients are approximately −1.80 for math and 2.77 for read. Each describes a change in log odds while holding the other score fixed; neither is a percentage-point change in probability. Their wide confidence intervals show that these estimates are imprecise.

The robust overall Wald test has a p-value of about 0.1232. The pseudo R-squared is about 0.5899, but should not be interpreted like the R-squared from a linear regression. These results describe the synthetic example only.