Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Re: moving window regression


From   Christopher F Baum <[email protected]>
To   [email protected]
Subject   st: Re: moving window regression
Date   Fri, 4 Jun 2004 11:11:44 +0100

On Jun 3, 2004, at 7:33 AM, Michael wrote:

Subject: st: Re: Beginner needs help trying to run rolling regressions in STATA 8 (in windows)

I wrote an ado back in 1999 (Stata v6) that does rolling regressions and
fills in the predicted value for each point.

program define rollpred
version 6.0
syntax varlist , [begin(int 200) end(int 10)] gen(str)
confirm new var `gen'
gen `gen'=.
tempvar pred
local obs=_N
local i=1
local j=`i'+(`begin'-`end')
local n=`i'+`begin'
quietly {
while `j'<`obs' {
reg `varlist' in `i'/`j'
cap drop `pred'
predict `pred' in `n'
replace `gen'=`pred' in `n'
local i=`i'+1
local j=`j'+1
local n=`n'+1
}
}
end

For each datapoint, it does a regression on the points starting "begin"
points before it and ending "end" points before it. It then uses predict to
get a prediction for the current point. You could use this as a start for
what you want to do.

A code fragment, not a full program, that does something of this sort is available as a class handout

http://fmwww.bc.edu/ec-c/s2004/771/movingwindow.do

I will have more to say on the subject at this month's SUGUK meeting in London.

Kit

*
* 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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index