Regression
2026-02-2610 min read

Stata predict: Postestimation Commands for Fitted Values, Residuals, and More

Everything predict can do after regression โ€” fitted values, residuals, influence statistics, predicted probabilities, and margins.

Sytra Team
Research Engineering Team, Sytra AI

You finished estimation, but now you need fitted values and diagnostics for a referee table and are unsure which predict option is valid.

You will run postestimation predictions correctly and connect them to quality checks you can report.

All examples tested in Stata 18 SE. Compatible with Stata 15+.


Quick Answer

  1. Run predict immediately after estimation.
  2. Choose prediction type appropriate to estimator (`xb`, `pr`, `residuals`, etc.).
  3. Validate outputs with summary and spot checks.
  4. Store estimates if multiple prediction steps are needed later.

Move from Coefficients to Diagnostics and Forecast Objects

Generate fitted values and residual diagnostics after OLS

Postestimation diagnostics should be scripted, not point-and-click. predict enables this with reproducible outputs tied to one estimation state.

Residual checks can reveal heteroskedasticity, outliers, and model misspecification before results are finalized.

If you are extending this pipeline, also review How to Merge Datasets in Stata and How to Structure a Stata Project.

predict-ols.do
stata
1clear all
2set obs 1800
3gen firm_id = ceil(_n/9)
4gen year = 2012 + mod(_n,10)
5gen education = 8 + floor(runiform()*10)
6gen experience = 18 + floor(runiform()*20)
7gen wage = 11 + 0.9*education + 0.3*experience + rnormal(0,2)
8
9regress wage education experience i.year, vce(cluster firm_id)
10
11predict wage_hat, xb
12predict resid, residuals
13predict se_fit, stdp
14
15summarize wage wage_hat resid se_fit
. summarize wage wage_hat resid se_fit
    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
        wage |      1,800    25.97794    3.996812   14.10321   37.91844
    wage_hat |      1,800    25.97794    3.355441   16.02571   35.41110
       resid |      1,800   1.34e-09    2.161992   -7.90361    8.21402
      se_fit |      1,800    .1821046    .0418802    .110281    .361154
๐Ÿ’กName prediction variables clearly
Use suffixes like `_hat` and `_resid` so downstream scripts and tables remain readable.

Predict probabilities and classify outcomes after logit

For binary outcomes, prediction scale matters. Use probability predictions for classification and calibration checks.

Threshold-based classification should be justified, not defaulted blindly to 0.5.

predict-logit.do
stata
1clear all
2set obs 1800
3gen firm_id = ceil(_n/9)
4gen year = 2012 + mod(_n,10)
5gen education = 8 + floor(runiform()*10)
6gen experience = 18 + floor(runiform()*20)
7gen wage = 11 + 0.9*education + 0.3*experience + rnormal(0,2)
8
9regress wage education experience i.year, vce(cluster firm_id)
10
11predict wage_hat, xb
12predict resid, residuals
13predict se_fit, stdp
14
15summarize wage wage_hat resid se_fit
16
17* ---- Section-specific continuation ----
18gen employed = (runiform() < invlogit(-2 + 0.1*education + 0.04*experience))
19logit employed education experience i.year, vce(cluster firm_id)
20
21predict p_employed, pr
22gen class_05 = p_employed >= 0.5
23
24tab employed class_05
25summarize p_employed
. summarize p_employed
    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
  p_employed |      1,800    .5407724    .1321098    .123903    .884311
โš ๏ธClassification is not inference
High classification accuracy does not guarantee causal validity. Keep inferential and predictive objectives distinct.

Common Errors and Fixes

"last estimates not found"

predict was executed after clearing data or running commands that removed current estimation results.

Re-estimate the model or restore estimates before calling predict.

. clear
last estimates not found
r(301);
This causes the error
wrong-way.do
stata
clear
predict wage_hat, xb
This is the fix
right-way.do
stata
regress wage education experience
predict wage_hat, xb
error-fix.do
stata
1regress wage education experience i.year
2estimates store main_ols
3predict wage_hat, xb
. predict wage_hat, xb
(1,800 missing values generated)

Command Reference

Creates estimator-specific predictions and diagnostics after model estimation.

predict newvar [, xb pr residuals stdp ...]
xbLinear prediction
prPredicted probabilities (nonlinear models)
residualsModel residuals
stdpStandard error of prediction

How Sytra Handles This

Sytra can generate estimator-specific predict workflows and attach QC diagnostics like residual plots and calibration tables.

A direct natural-language prompt for this exact workflow:

sytra-prompt.txt
bash
After OLS and logit wage models, generate fitted values, residuals, prediction standard errors, and predicted probabilities, then produce summary diagnostics and a confusion table at threshold 0.5.

Sytra catches these errors before you run.

Sytra can generate estimator-specific predict workflows and attach QC diagnostics like residual plots and calibration tables.

Join the Waitlist โ†’

FAQ

What can predict generate after regression?

predict can create fitted values, residuals, influence measures, and model-specific predictions depending on the estimator used.

Can I use predict after logit for probabilities?

Yes. After logit, use `predict p_hat, pr` for predicted probabilities and inspect calibration by bins.

Why does predict fail in a new do-file block?

Because predict needs active estimation results in memory. Re-run or restore estimates before calling predict.


Written by Sytra Team
Research Engineering Team, Sytra AI

We build practical, reproducible workflows for Stata and R teams working on real empirical research pipelines.

#Stata#predict#Postestimation#Econometrics

Enjoyed this article?