Command reference
predict — create fitted values and residuals
Use the most recently fitted model to add a new variable containing predictions, residuals, or the standard error of the linear prediction. The default prediction scale depends on the model you fitted.
Syntax
predict new_variable [, statistic]
Run an estimation command first, then give predict one new variable name. Replace statistic with one of the options below, or omit the comma and option to use the model's default. Choose one statistic per command and a different output name for each result.
After regress, the default is the fitted outcome. After logit or probit, it is the probability of the positive outcome. After poisson or nbreg, it is the expected count; after glm, it is the fitted mean.
Prediction statistics
Example
Fit math to read and female in the bundled synthetic student data. Then save fitted math scores, residuals, and standard errors of the fitted mean, and inspect the first six observations.
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
Sample data included. Opens in a new tab; click Run.
What to look for
Observation 1 has an observed math score of 45 and a fitted score of about 47.82. Its residual is therefore 45 − 47.82 = −2.82: the model predicts a higher score than was observed. Its fitted_se of about 0.48 describes uncertainty in that fitted mean, not how far an individual score may fall from it.
| id | math | fitted_math | residual | fitted_se |
|---|---|---|---|---|
| 1 | 45 | 47.82 | −2.82 | 0.48 |
| 2 | 51 | 51.22 | −0.22 | 0.66 |
| 3 | 43 | 42.72 | 0.28 | 0.64 |
| 4 | 56 | 58.86 | −2.86 | 0.43 |
| 5 | 48 | 50.37 | −2.37 | 0.42 |
| 6 | 60 | 62.68 | −2.68 | 0.41 |