Command reference

regress — fit a linear regression

Estimate how a numeric outcome changes with one or more predictors. Ordinary least squares fits a straight-line model and reports coefficients, standard errors, confidence intervals, and measures of fit.

Syntax

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

Put the outcome first, followed by the predictors. An intercept is included automatically; with no predictors, the model estimates the outcome mean. if selects observations by a condition, and in selects positions in the current row order. Calling regress without a variable list displays the most recent linear-regression results.

Use i.group for categories and c.x for a continuous variable. The lowest category is the default reference; ib2.group chooses category 2. i.group#c.x requests an interaction, while i.group##c.x includes the main effects and their interaction. A bare numeric variable is treated as continuous, even when its numbers are category codes.

Optional weights go before the comma: [fw=count] represents replicated observations, [aw=precision] supplies analytic weights, [pw=weight] supplies sampling weights, and [iw=weight] supplies importance weights. Frequency weights must be integers; zero weights are excluded and negative weights are rejected. Sampling weights imply robust standard errors. Importance weights require the conventional variance estimate.

Options

robust / vce(robust)
Use heteroskedasticity-robust standard errors. This changes uncertainty estimates, tests, and confidence intervals while retaining the same fitted coefficients.
vce(conventional)
Use the usual constant-variance OLS standard errors. This is the default for unweighted estimation; sampling weights imply robust estimation instead.
vce(cluster group) / cluster(group)
Allow observations within the same cluster to have correlated errors. At least two nonmissing clusters are required. Reported t tests and confidence intervals use the number of clusters minus one as their degrees of freedom.
vce(bootstrap, reps(#) seed(#))
Estimate coefficient uncertainty by repeatedly drawing rows with replacement and refitting the model. reps() sets the number of draws (default 50), and an optional seed() makes the draws reproducible. The reported coefficients remain those fitted to the original sample.
vce(jackknife)
Estimate coefficient uncertainty by leaving out one observation at a time and refitting the model.
vce(hac nwest #)
Use Newey–West standard errors allowing heteroskedasticity and correlation across up to # row lags. Supply a nonnegative lag count and put the observations in the intended time order first. With weights, this form accepts analytic weights only.
level(#)
Set the confidence-interval percentage; the default is 95. Values from 10 through 99.99 are accepted. This changes interval widths, not coefficients or p-values, and can also be used when displaying the previous results.

Example

Fit math scores to a binary indicator and a categorical predictor in 24 synthetic student records. The example imports the bundled data, treats race as categories, and requests robust standard errors. The records are invented for learning the command.

clear
import delimited "data/student_scores.csv"
regress math female i.race, robust
Open example in browser

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

What to look for

The coefficient on female is about 8.92: within this fitted model, observations with female = 1 have a math score about 8.92 points higher than those with female = 0, holding the race category fixed. The coefficient for race group 2 is 10, relative to reference group 1.

The model reports 24 observations and an R-squared of about 0.8545. Read the robust standard errors, p-values, and confidence intervals alongside the estimates to assess their precision. These teaching data illustrate an association, not a causal effect.