<>
Degas,
when I try to replicate your dataset, I do not even manage to get -rolling-
to estimate a single coefficient. It complains about insufficient
observations. How is your real dataset different from the one I concoct?
*************
clear*
set obs 2000
set seed 14234
gen xticker=_n
gen alpha=rnormal(0,0.02)
expand 88
bys xticker: gen period=_n
forv i=1/20{
gen var`i'=rnormal(0,0.03)
}
egen total=rowtotal(var*)
gen return= /*
*/ 0.02+0.05*total+alpha+ /*
*/ rnormal(0,0.03)
xtset xticker period
rolling _b _se, window(3) clear: /*
*/ xtreg return var*, /*
*/ vce(cluster xticker)
*************
HTH
Martin
-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Brian R. Landy
Gesendet: Mittwoch, 30. September 2009 17:28
An: [email protected]
Betreff: Re: st: Using Rolling Regression with Panel Data
Hi, I'm not really sure what your question is, but I'm guessing you
find rolling: to be slow with a panel? I observed this a while back
(and did report to Stata but have never seen notice that it was
fixed), I found that -rolling- in conjunction with panels is far
slower than the time implied by (# panels)*(time for rolling
regression on just one panel). In my case a regression was taking
over 1 hour on a 4 CPU box, this was for somewhere around 100 panels,
4 years of daily data, and a 2 year rolling regression.
My workaround was to use foreach to loop over the panels, saving and
merging the results of each somewhat like this:
// prep data
tsset id date
gen end=date // for later merging
tempfile stats
levelsof id, local(ids)
foreach id of local ids {
keep if id==`id'
quietly: rolling, window(`window') saving(`stats', replace) ///
nodots: regress y x
merge id end using "`stats'", sort update replace nokeep
drop _merge
}
This took my 1+ hour runtime down to just a few minutes.
Regards,
Brian
Quoting Degas Wright <[email protected]>:
> I have a longitudinal dataset that has 2000 stocks as xticker (id) and
> dependent variable, return (t+1), with 20 independent variables (t) over
88
> periods (months).
>
> I am trying to run a , xtreg, regression over three periods and then use
the
> coefficients from the regression to forecast the t+1 return. When I use
the
> following command:
>
> . rolling _b _se, window (3) clear: xtreg return, var1, var2,.var20,
> vce(cluster xticker)
>
> (running regress on estimation sample)
>
> -> xticker = 1
>
> Rolling replications (86)
> ----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
> .........
>
> -> xticker = 2
>
> Rolling replications (86)
> ----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
> ........
>
> It starts going through each of the 2000 stocks, by listing xticker1,
> xticker 2, etc.. I have stopped it prior to the run being completed
because
> it will take a long time to go through all 2000 stocks.
>
> Is there another command that I should be using? For instance I use the
> forvalues command to run the regression, xtreg, one period at a time for
all
> of the periods, Period 1, Period 2, etc.
>
> Thank you for your assistance.
>
>
>
>
> Degas A. Wright, CFA
> Chief Investment Officer
> Decatur Capital Management, Inc.
> 250 East Ponce De Leon Avenue, Suite 325
> Decatur, Georgia 30030
> Voice: 404.270.9838
> Fax:404.270.9840
> Website: www.decaturcapital.com
>
>
>
>
>
> *
> * For searches and help try:
> * http://www.stata.com/help.cgi?search
> * http://www.stata.com/support/statalist/faq
> * http://www.ats.ucla.edu/stat/stata/
>
>
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/