Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Slow -rolling- regressions on panel data


From   Richard Herron <[email protected]>
To   [email protected]
Subject   st: Slow -rolling- regressions on panel data
Date   Mon, 26 Sep 2011 10:37:35 -0400

I am using -rolling- for rolling regressions on panel data, but it is
exceedingly slow. I found a Statalist thread
(http://www.stata.com/statalist/archive/2009-09/msg01239.html) with a
more manual solution, but it is equally slow (both are too slow to run
to completion in a reasonable amount of time).

Is -regress- the bottleneck? I only want the AR(1) coefficient; is
there a different approach I should take? Are rolling
regressions/calculations best done in different software?

Thanks!

* ----- begin code -----
* generate data
clear
set obs 250000
egen firm = seq(), from(1) to(2500) block(100)
egen date = seq(), from(1) to(100)
generate eps = 1 + rnormal()
sort firm date
tsset firm date

* generate variables for rolling regressions
bysort firm (date): generate l_eps = eps[_n - 1]
label variable l_eps "One-Quarter Lagged EPS"
bysort firm (date): generate end = _n
label variable end "Firm-Quarter (for rolling regressions)"

* the simple approach is very slow
rolling _b, window(16) clear: regress eps l_eps, noconstant

* and the approach from an old Statalist thread
http://www.stata.com/statalist/archive/2009-09/msg01239.html) is
equally slow
tempfile tempfile_rr
egen level_firm = group(firm)
summarize level_firm, meanonly
forvalues l = 1/`r(max)' {
   rolling if level_firm == `l'
///
       , window(16) keep(firm) ///
       saving(`tempfile_rr', replace) nodots ///
       : regress eps l_eps, noconstant
   merge 1:1 firm end using "`tempfile_rr'" ///
       , update replace nogenerate keepusing(firm end _b_l_eps)
}
label variable _b_l_eps "Earnings Persistence"
* ----- end code -----
*
*   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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index