predict: fitted values, residuals, and prediction uncertainty

Turn the most recent fitted model into observation-level diagnostics and predictions stored as new variables.

Tested 2026-08-06 with the current stats.camp development build · View the do-file on GitHub

Open this example View supported commands

Independent software. Not affiliated with, sponsored by, or endorsed by StataCorp LLC.

Complete example

clear
import delimited "data/student_scores.csv"
regress math read female
predict fitted_math
predict residual, residuals
predict fitted_se, stdp
list id math fitted_math residual fitted_se in 1/6

The first predict uses the default linear prediction. The next two request residuals and the standard error of the fitted mean.

Output from stats.camp

+--------------------------------------------------------+
|  #    id    math   fitted_math   residual   fitted_se  |
|--------------------------------------------------------|
|   1     1     45         47.82      -2.82        0.48  |
|   2     2     51         51.22      -0.22        0.66  |
|   3     3     43         42.72       0.28        0.64  |
|   4     4     56         58.86      -2.86        0.43  |
|   5     5     48         50.37      -2.37        0.42  |
|   6     6     60         62.68      -2.68        0.41  |
+--------------------------------------------------------+

What each generated variable means

fitted_math is the model's conditional mean estimate for each covariate pattern. residual is observed math minus fitted math, so observation 1 has 45 − 47.82 ≈ −2.82. fitted_se quantifies uncertainty in the fitted mean, not the spread of a future individual outcome.

Common options and current limits

See the current predict entry and Stata's regress postestimation manual for an external reference.

Related guides

Run this exact example

Clone the example repository in stats.camp and open the exact do-file shown on this page. No stats.camp account is required.

Open this example