Written and maintained by CASRAI Editorial Board
Last updated
regress is Stata’s command for ordinary least squares (OLS) linear regression, and it is the starting point for a family of estat postestimation commands — estat hettest, estat vif, estat ovtest — that check whether the model you just fit is actually trustworthy. Fitting the model is the easy part; this page covers the full workflow — syntax, reading the output, robust and clustered standard errors, the diagnostics that check the assumptions behind those results, and getting a publication-ready table out the other end with outreg2 or esttab.
For the statistical logic behind linear regression itself — what the coefficients mean, what the assumptions are, and how to interpret the model regardless of software — see CASRAI’s guide to regression analysis first. This page is the Stata-specific procedure: exact commands, exact options, and how to read every line Stata prints.
Basic regress syntax
The command takes a dependent variable followed by one or more independent variables:
regress depvar indepvars
A simple bivariate regression — grant application scores predicted by years of PI experience:
regress score experience
A multiple regression adds more predictors after the first, space-separated, no commas:
regress score experience budget_requested collaborator_count
Categorical predictors use factor-variable notation with the i. prefix rather than hand-built dummy variables — Stata picks the lowest coded value as the base category by default and labels the coefficient rows accordingly:
regress score experience i.department
To force a specific base category instead of the default lowest value, use ib#. (for example ib3.department to set category 3 as the reference). An interaction between a continuous and a categorical variable uses ## or #:
regress score c.experience##i.department
Reading regress output
Every regress run prints the same two-block structure. Here is what it looks like (illustrative numbers, laid out to show the format — not a reported research finding):
Source | SS df MS Number of obs = 120
-------------+---------------------------------- F(3, 116) = 14.82
Model | 1042.38716 3 347.462387 Prob > F = 0.0000
Residual | 2719.94017 116 23.4477601 R-squared = 0.2770
-------------+---------------------------------- Adj R-squared = 0.2580
Total | 3762.32733 119 31.6161961 Root MSE = 4.8422
------------------------------------------------------------------------------
score | Coef. Std. err. t P>|t| [95% conf. interval]
-------------+----------------------------------------------------------------
experience | .3841206 .0812394 4.73 0.000 .223146 .5450952
budget | .0000412 .0000138 2.99 0.003 .0000138 .0000685
collaborators | .2015533 .1204287 1.67 0.097 -.0369201 .4400267
_cons | 12.44107 1.883275 6.61 0.000 8.71059 16.17156
------------------------------------------------------------------------------
- Top-left block — the ANOVA-style decomposition of variance into Model, Residual, and Total sums of squares, each with its degrees of freedom and mean square.
- Top-right block — the overall model fit statistics: the
Ftest (whether the predictors jointly explain variation in the outcome),Prob > F(its p-value),R-squaredandAdj R-squared(variance explained, the second penalized for the number of predictors), andRoot MSE(the standard deviation of the residuals). - Coefficient table — one row per predictor plus
_cons(the intercept).Coef.is the estimated effect on the dependent variable per one-unit increase in that predictor, holding the others constant;Std. err.,t,P>|t|, and the 95% confidence interval follow the same logic as any regression table. (Stata versions before 16 label these columns “Std. Err.” and “P>|t|” with different capitalization; the lowercase style shown here is current.)
After any regress, the fitted results stay available in memory for postestimation commands (ereturn list shows everything stored) until you run another estimation command — that is what makes predict and estat work without re-specifying the model.
Robust and clustered standard errors
The default standard errors in the table above assume homoscedastic, independent errors. Two vce() options relax that:
Heteroskedasticity-robust (Huber-White) standard errors — use when residual variance isn’t constant across observations, which estat hettest below can help you check:
regress score experience budget collaborators, vce(robust)
The shorthand robust option does the same thing:
regress score experience budget collaborators, robust
Robust standard errors change the reported Std. err., t, and confidence interval columns and turn the overall F test into a Wald-type test; the point estimates (Coef.) and R-squared are unaffected, since vce() only changes how uncertainty is estimated, not the fitted values themselves.
Cluster-robust standard errors — use when observations are grouped (repeated measures per subject, students within schools, grant applications within the same funding round) and errors are likely correlated within a group but not across groups:
regress score experience budget collaborators, vce(cluster institution_id)
Clustering generally widens standard errors relative to the default, because it accounts for the fact that observations within a cluster aren’t fully independent pieces of information. As a rule of thumb, clustered inference needs a reasonable number of clusters (commonly cited guidance suggests at least 30-50) to be reliable — with very few clusters, the cluster-robust standard errors themselves become unstable.
Postestimation: predict for fitted values and residuals
predict generates a new variable from the most recently fitted model — run it immediately after regress, before fitting anything else, since it always acts on whatever estimation results are currently in memory. With no options, it returns fitted values (linear predictions, xb):
predict yhat
The most commonly needed variants:
predict resid, residuals
predict rstd, rstandard
predict rstud, rstudent
predict lev, leverage
predict cooksd, cooksd
residuals— the raw residual (observed minus predicted) for each observation.rstandard— the standardized residual, scaled to have constant variance.rstudent— the studentized (jackknifed) residual, which refits the model leaving that observation out — more reliable for spotting individual outliers than the plain standardized residual.leverage(alsohat) — how far an observation’s predictor values sit from the mean of the predictors; high-leverage points can dominate the fitted line.cooksd— Cook’s distance, combining leverage and residual size into one influence measure per observation.
Plotting resid against yhat is the standard way to eyeball non-constant variance before running the formal test below — see CASRAI’s guide to reading a residual plot for what to look for in that plot specifically.
Because predict uses whatever sample regress actually estimated on (e(sample)), rows dropped for missing values come back missing in the new variable too — that’s expected, not a bug, and worth checking if a predicted-values count looks short.
Checking the assumptions: estat hettest, estat vif, estat ovtest
Three built-in postestimation commands, all run directly after regress with no arguments needed beyond the command itself:
estat hettest — the Breusch-Pagan / Cook-Weisberg test for heteroskedasticity. The null hypothesis is constant variance (homoscedasticity); a significant result (conventionally p < 0.05) is evidence against it, which is the cue to add vce(robust) or vce(cluster) to the original regress command.
estat hettest
The default version tests against the fitted values only; estat hettest, rhs instead tests against each right-hand-side predictor separately, which can point to which specific variable is driving non-constant variance.
estat vif — variance inflation factors, one per predictor, for detecting multicollinearity among the independent variables. A commonly cited rule of thumb treats a VIF above 10 as a clear problem, with some researchers flagging above 5 as worth a closer look; there is no universal cutoff, and the right threshold depends on the field and what the model is being used for.
estat vif
For what VIF actually measures, why multicollinearity inflates standard errors without biasing coefficients, and what to do once you’ve found it, see CASRAI’s guide to multicollinearity and VIF in regression — this page covers only the Stata command.
estat ovtest — Ramsey’s RESET (regression equation specification error test) for omitted variables and functional-form misspecification. It adds powers of the fitted values back into the model and tests whether they add explanatory power; the null hypothesis is that the model has no omitted variables. A significant result suggests the specification is missing something — a nonlinear term, an interaction, or a predictor entirely — not necessarily which one.
estat ovtest
None of these three commands work after regress with vce(robust) or vce(cluster) already applied to the same fit for estat hettest/estat ovtest specifically — both are tests about the error structure itself, so run them against the plain (non-robust) fit first, resolve what they find, and add vce() to the final specification afterward. estat vif is unaffected by vce(), since it only looks at the predictors, not the errors.
Exporting publication-ready tables: outreg2 and esttab
Neither command ships with Stata by default — both are user-written packages installed once per machine from the Statistical Software Components (SSC) archive:
ssc install outreg2
ssc install estout
(esttab, along with eststo and estadd, is part of the estout package — installing estout installs all three.)
outreg2 exports the results of the most recent estimation command directly to a file, formatted as a regression table:
regress score experience budget collaborators, robust
outreg2 using results.doc, replace
Running additional models and swapping replace for append adds each as a new column in the same table — a standard “Model 1 / Model 2 / Model 3” comparison layout:
outreg2 using results.doc, replace ctitle(Model 1)
regress score experience budget collaborators i.department, robust
outreg2 using results.doc, append ctitle(Model 2)
outreg2 writes to Word (.doc), Excel (.xls), or plain text depending on the file extension given.
esttab takes a different workflow: store each model’s estimates with eststo as you fit it, then export all stored models together:
eststo clear
eststo: regress score experience budget collaborators, robust
eststo: regress score experience budget collaborators i.department, robust
esttab using results.rtf, se star(* 0.10 ** 0.05 *** 0.01) replace
esttab without a using clause prints the same table straight to the Results window, which makes it useful for a quick side-by-side check before exporting anything. It also supports LaTeX output directly (.tex), which outreg2 does not handle as cleanly — a genuine reason to prefer esttab for a manuscript headed to a journal that typesets in LaTeX, while outreg2‘s Word/Excel output tends to be the faster path when the destination is a grant report or a collaborator who works in Office.
Common mistakes
- Running
estatcommands after fitting a different model in between. Postestimation commands always act on the most recently run estimation command — if you fit a secondregress(even to check something quickly) before runningestat vif, you’ll get diagnostics for the second model, not the one you meant. - Treating VIF or the RESET test as pass/fail rather than diagnostic. Both flag a potential problem; neither one tells you the fix automatically. A high VIF might mean dropping a redundant predictor, combining two correlated ones, or simply accepting it if the variable of interest itself isn’t the collinear one.
- Forgetting that
i.notation changes what a coefficient means. With factor variables, each level’s coefficient is the effect relative to the omitted base category, not an independent effect — misreading it as the latter is a common write-up error. - Comparing R-squared across models fit on different samples. If one specification drops more rows to missing values than another (a longer predictor list is more likely to hit a missing value somewhere), the two R-squared values aren’t comparable even though both came from
regress— checke(N)matches before comparing fit statistics across models.
Frequently asked questions
What does the regress command do in Stata?
It fits an ordinary least squares (OLS) linear regression of one dependent variable on one or more independent variables and stores the results in memory for postestimation commands like predict and estat to use afterward.
How do I get robust standard errors in Stata?
Add vce(robust) (or the shorthand robust) to the end of the regress command, after a comma. Use vce(cluster varname) instead when observations are grouped and errors are likely correlated within those groups.
How do I check for multicollinearity after regress in Stata?
Run estat vif immediately after regress, with no arguments. It prints a variance inflation factor for each predictor; conventionally, a VIF above 10 is treated as a clear problem.
What’s the difference between outreg2 and esttab in Stata?
Both export regression results to a formatted table, but outreg2 writes straight to Word or Excel from each estimation command in turn, while esttab (from the estout package) works with eststo to store multiple models first and export them together, and adds direct LaTeX support that outreg2 doesn’t have. Neither ships with Stata — both need ssc install first.
How do I test for heteroskedasticity in Stata?
Run estat hettest after regress. It’s the Breusch-Pagan / Cook-Weisberg test; a significant result is evidence against constant-variance errors and a cue to refit with vce(robust).
For choosing between Stata and other statistical packages more generally, see CASRAI’s comparisons of SPSS vs. Stata and R vs. Stata, and CASRAI’s guide to logistic regression in R if your outcome is binary rather than continuous. For the equivalent procedure elsewhere in the same statistical-software subcluster, see CASRAI’s guide to running a t-test in Stata.








