Scott and Austin:
Thank you both for your help with the rolling regression. That did
what I was hoping to accomplish.
BTW, when I modified Scott's code to be time<`i' instead of time<=`i'
it stopped making predictions. I assume that has to do with the
e(sample) line, which I am unfamiliar with - will have to look into
that.
Thanks again.
William
On Feb 4, 2008 1:21 PM, Austin Nichols <[email protected]> wrote:
> 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/
>
*
* 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/