Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: sorted rolling regresion


From   "Austin Nichols" <austinnichols@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: sorted rolling regresion
Date   Mon, 4 Feb 2008 16:21:05 -0500

William Bishop <wbishopco@gmail.com>:
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 <scott.merryman@gmail.com> wrote:
> On Feb 2, 2008 1:47 PM, William Bishop <wbishopco@gmail.com> 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/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index