Statalist


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

RE: st: Using Rolling Regression with Panel Data


From   "Degas Wright" <degasw@decaturcapital.com>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: Using Rolling Regression with Panel Data
Date   Wed, 30 Sep 2009 13:13:43 -0400

Brian & Martin,
Thank you for your response

This seems to be a tough application of the xt commands.  Gustave from the
STATA staff sent the following to me on this question:

Dear Degas,

We do not have a one line command to perform the regressions that you
Require and store the coefficient estimates. As I mentioned in my previous
mail, "You may rather need to write a short program including a loop and
using the -postfile- command". The code below reproduces an example with one
of the datasets available from our website:

        webuse grunfeld,clear
	xtset company year

	tempname vector
        postfile `vector' time1 time2				/// 
			  beta_mvalue beta_kstock beta_const	/// 
                          se_mvalue   se_kstock   se_const	/// 
			  using mybeta, replace
						  
	set more off
		
	forvalues i=1935/1952 {
		local j=`i'+2
		display _n(3) in white _col(30) /// 
		"Time period:" `i' "-" `j'
		  xtreg invest mvalue kstock if year>=`i' & year<=`j' 
		  post `vector'					/// 
			(`i') (`j')				/// 
			(_b[mvalue])  (_b[kstock])  (_b[_cons])	/// 
			(_se[mvalue]) (_se[kstock]) (_se[_cons])
		    local j=`j'+1

        }
        postclose `vector'

        set more on

        use mybeta,clear


I hope this helps.
Sincerely,

Gustavo

I plan to try this solution and the others that you suggested.  Using the xt
commands in this way appears to be an efficient means to increase the
R-square of the model as compared to simply using a one period cross
sectional regression.

Thank you,

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

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Martin Weiss
Sent: Wednesday, September 30, 2009 12:19 PM
To: statalist@hsphsun2.harvard.edu
Subject: AW: st: Using Rolling Regression with Panel Data


<> 

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: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Brian R. Landy
Gesendet: Mittwoch, 30. September 2009 17:28
An: statalist@hsphsun2.harvard.edu
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 <degasw@decaturcapital.com>:

> 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/




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