William Bishop <[email protected]>:
Scott's code does not make my mistake of leaving a condition off -predict-:
webuse grunfeld, clear
su time, meanonly
loc Max=r(max)
levelsof com, local(is)
g p1=.
foreach i of local is {
forval t = 3/`Max' {
qui reg mval kst if com==`i'&time<`t'
predict temp, xb
qui replace p1=temp if com==`i'&time==`t'
drop temp
}
}
li time p1 mval kst, sepby(com) noo
but note (still) that the predictions may make no sense. You may
prefer a different flavor of regression, depending on what you are
going to use this for...
On Feb 4, 2008 4:06 PM, Scott Merryman <[email protected]> wrote:
> On Feb 2, 2008 1:47 PM, William Bishop <[email protected]> wrote:
> > I'm trying to do a rolling regression by id that regresses on previous
> > dates and then gets the prediction for the current observation.
>
> No, but you can loop over the groups. Perhaps, something like this will help:
*
* 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/