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:14:07 -0500

William Bishop <wbishopco@gmail.com>
It's not at all clear what you are trying to accomplish with that
code.  Do you mean to run T-2 regressions for each value of id and
save the predictions like so?

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 time==`t'
  drop temp
 }
}
li time p1 mval, sepby(com) noo

Note the many nonsensical results in that output.

On Feb 4, 2008 3:49 PM, William Bishop <wbishopco@gmail.com> wrote:
> Any ideas on how to approach this?
>
>
> On Feb 2, 2008 11:47 AM, 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.
> >
> > The code below does the regressions but the predictions are not made
> > after each regression but only after the final regression.  So what
> > winds up happening is that all the predictions are based off the final
> > regression.
> >
> > forval i = 3/`Max' {
> >                         bys id (date) : regress varlist if _n < `i'
> >
> >                         predict temp, xb
> >                         bys id (date) : replace p1 = temp if _n == `i'
> >                         drop temp
> > }
> >
> > I'm looking to have the predictions made after each regression.  Can
> > this be done using bys?
*
*   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