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
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
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.