TAGS :Viewed: 13 - Published at: a few seconds ago

[ How to use predict with stored e(b) from old regression ]

I know that one can get predicted values as follows:

reg y x1 x2 x3
predict pred_values

Let's say that I run a regression and store the values:

reg y x1 x2
matrix stored_b = e(b)

And then I run another regression (doesn't matter what).

Is it possible to use the predict command using stored_b instead of the current e(b)?

(Of course, I could generate the predicted values by manually computing them based on stored_b, but this could get tedious if there are many coefficients.)

Answer 1


There's no need to create a matrix. Stata has commands that facilitate the task. Try estimates store and estimates restore. An example:

clear
set more off

sysuse auto

// initial regression/predictions
regress price weight
estimates store myest
predict double resid, residuals

// second regression/prediction
regress price mpg
predict double residdiff, residuals

// backup and predict from initial regression results
estimates restore myest
predict double resid2, residuals

// should pass
assert resid == resid2

// should fail
assert resid == residdiff