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.
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
- Run predict immediately after estimation.
- Choose prediction type appropriate to estimator (`xb`, `pr`, `residuals`, etc.).
- Validate outputs with summary and spot checks.
- 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.
1clear all2set obs 18003gen 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)89regress wage education experience i.year, vce(cluster firm_id)1011predict wage_hat, xb12predict resid, residuals13predict se_fit, stdp1415summarize 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 .361154Predict 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.
1clear all2set obs 18003gen 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)89regress wage education experience i.year, vce(cluster firm_id)1011predict wage_hat, xb12predict resid, residuals13predict se_fit, stdp1415summarize wage wage_hat resid se_fit1617* ---- Section-specific continuation ----18gen employed = (runiform() < invlogit(-2 + 0.1*education + 0.04*experience))19logit employed education experience i.year, vce(cluster firm_id)2021predict p_employed, pr22gen class_05 = p_employed >= 0.52324tab employed class_0525summarize p_employedVariable | Obs Mean Std. dev. Min Max -------------+--------------------------------------------------------- p_employed | 1,800 .5407724 .1321098 .123903 .884311
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.
last estimates not found r(301);
clearpredict wage_hat, xbregress wage education experiencepredict wage_hat, xb1regress wage education experience i.year2estimates store main_ols3predict wage_hat, xb(1,800 missing values generated)
Command Reference
predict
Stata docs โCreates estimator-specific predictions and diagnostics after model estimation.
xbLinear predictionprPredicted probabilities (nonlinear models)residualsModel residualsstdpStandard error of predictionHow 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:
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.
Related Guides
- Stata margins: Complete Guide to Marginal Effects with Interpretation
- Interaction Effects in Stata: Factor Variables, margins, and Interpretation
- Export Regression Tables in Stata: esttab Tutorial with LaTeX, Word, and CSV
- Clustered Standard Errors in Stata: vce(cluster) Explained with Examples
- Explore the regression pillar page
- Open the full regression guide index
- Browse all Stata & R guides on the blog index
- Browse all Stata pillars
We build practical, reproducible workflows for Stata and R teams working on real empirical research pipelines.