11.07.2015 Views

[U] User's Guide

[U] User's Guide

[U] User's Guide

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

[ U ] 20.9 Obtaining predicted values 27320.9.2 Making in-sample predictionspredict does not retrieve a vector of prerecorded values—it calculates the predictions on thebasis of the recorded coefficients and the data currently in memory. In the above examples, when wetyped things like. predict probhatpredict filled in the prediction everywhere that it could be calculated.Sometimes we have more data in memory than were used by the estimation command, eitherbecause we explicitly ignored some of the observations by specifying an if exp with the estimationcommand or because there are missing values. In such cases, if we want to restrict the calculation tothe estimation subsample, we would do that in the usual way by adding if e(sample) to the endof the command:. predict probhat if e(sample)20.9.3 Making out-of-sample predictionsBecause predict makes its calculations on the basis of the recorded coefficients and the data inmemory, predict can do more than calculate predicted values for the data on which the estimationtook place—it can make out-of-sample predictions, as well.If you fit your model on a subset of the observations, you could then predict the outcome for allthe observations:. logit foreign weight mpg if rep78 > 3. predict pallIf you do not specify if e(sample) at the end of the predict command, predict calculates thepredictions for all observations possible.In fact, because predict works from the active estimation results, you can use predict withany dataset that contains the necessary variables.Example 8Continuing with our previous logit example, assume that we have a second dataset containingthe mpg and weight of a different sample of cars. We have just fit your model and now continue:. use otherdat, clear(Different cars). predict probhat Stata remembers the previous model(option pr assumed; Pr(foreign)). summarize probhat foreignVariable Obs Mean Std. Dev. Min Maxprobhat 12 .2505068 .3187104 .0084948 .8920776foreign 12 .1666667 .3892495 0 1

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!