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]

Re: st: rolling regression in panel data


From   Richard Herron <[email protected]>
To   [email protected]
Subject   Re: st: rolling regression in panel data
Date   Wed, 5 Oct 2011 23:43:14 -0400

I think the key is to make sure that each quarter has 64 trading days,
even if many are empty. -regress- will remove the empty rows, but
-rolling- needs a clearly defined structure to use the window and
stepsize options.

I think this should do it (but beware, I just switched to Stata and
don't have a daily CRSP file handy to test this)

* get permnos
use crsp, clear
keep in 1/10000
keep permno
duplicates drop
save permnos, replace

* generate 64 trading days
clear
set obs 64
generate int n = _n

* cross permno and n
cross using permnos
save permnos_cross_ns, replace

* now make sure that every permno has 64 trading days per quarter w/ merge
* we should end up with 0-5 empty trading days per quarter,
* we need this so that -rolling- can use a constant window and stepsize
* -regress- will just through the empty rows, but -rolling- won't know
use crsp, clear
keep in 1/10000
generate int date_qtr = yq(year(date), quarter(date))
format date_qtr %tq
bysort permno date_qtr (date): generate int n = _n
merge m:1 n permno using permnos_cross_ns, nogenerate

* now we have 64 rows per permno and quarter
* but we can't tsset on permno n, yet, because we have duplicate n
* so I will add a multiple of 64 to each quarter
* all that matters is that each window has 64 rows
replace n = n + 64*(4*year(date) + quarter(date))
tsset permno n

* now use -rolling- with 256 day window and 64 day stepsize
rolling, window(256) stepsize(64) saving(rolling_output, replace) ///
    : regress ret

* to be sure, this is a nonsense regression


On Wed, Oct 5, 2011 at 17:11, Katharina Raatz <[email protected]> wrote:
> Dear Statalist,
>
> I have a dta file containing daily return data of several stocks. I would
> like to calculate the CAPM betas of these stock on basis of the
> previous year's return data for each quarter beginning in 2000, i.e. from
> 01mar1999 to 28feb2000, from 01jun1999 to 31may2000 and so, for each stock.
>
> I tried to implement this with a combination of statsby and rolling or
> rollreg, but I could only find an options for these commands that would
> calculate the betas from 01mar1999 to 28feb2000, 02mar1999 to 01mar2000
> etc. so for subsequent business day.
>
> To overcome this, I constructed a help variable indicating all regression
> period start dates for all stocks e.g. the day 01mar1999 with "1". So what
> I would like to know is whether there is a command e.g. for rollreg with
> which I can specify that the regression should be based on data starting
> where help == "1" and end e.g. 252 rows later? And if so, is there any
> chance that I can also export the date (either of the start or the end) and
> the stock ticker besides the coefficient estimate, so that I have a clear
> identification of the regression period and to which stock the beta
> belongs?
>
> Many thanks in advance! Kristin
>
> --
> NEU: FreePhone - 0ct/min Handyspartarif mit Geld-zurück-Garantie!
> Jetzt informieren: http://www.gmx.net/de/go/freephone
> *
> *   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index