Does -rolling- know you have panel data?
Another way to accomplish this is to use -postfile- to collect the estimated
coefficient and -predict- the residuals and predicted values for each
individual.
For example:
webuse grunfeld, clear
tempfile results
tempname hold
postfile `hold' constant coef rho using `results'
qui {
gen predicted = .
gen residual = .
forv i = 1/10 {
prais invest mvalue if com == `i'
local const = _b[_cons]
local coef = _b[mvalue]
local rho = e(rho)
predict pred if com == `i'
predict resid if e(sample), r
replace predicted = pred if com == `i'
replace residual =resid if com == `i'
drop pred resid
post `hold' (`const') (`coef') (`rho')
}
}
save predicted, replace
postclose `hold'
preserve
use `results', clear
save roll,replace
restore
Scott
> -----Original Message-----
> From: [email protected] [mailto:owner-
> [email protected]] On Behalf Of [email protected]
> Sent: Sunday, July 16, 2006 12:00 PM
> To: [email protected]
> Subject: st: rolling prais regression in paneld dataset
>
> Hi I am using Stata9's new rolling capability with prais regression
> on a panel dataset (unbalanced panal with about 10,000 individuals
> and roughly 15 years for each).
>
> Stata-tech support helped me write a little program that collects,
> in addition to coefficients of the regression, its predicted values
> and residuals. But the program doesn't seem to work well, and I am
> not sure where the bug is, I tried recontacting tech support, but
> so far no answer. Here is my code, any help would be greately
> appreciated:
> *************************
>
> tsset person year
>
> program myforecast, rclass
> syntax [if]
> prais r exp `if'
> summ year if e(sample)
> local min=r(min)
> predict pred`min' if e(sample)
> predict resid`min' if e(sample), r
> return scalar n=r(N)
> return scalar rho=e(rho)
> end
>
>
> rolling rho=r(rho) n=r(n), window(15) ///
> saving(roll, replace): myforecast
> save pred, replace
> *****************************
>
>
> Olga Gorbachev Melloni
> Economics Ph.D. Student
> Columbia University
> www.columbia.edu/~ocg2001
>
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/