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: Rolling Regressions


From   Philipp Krueger <[email protected]>
To   [email protected]
Subject   st: Rolling Regressions
Date   Thu, 17 Mar 2011 17:09:34 +0100

Hi,
I have monthly data and I am trying to run regressions on rolling windows of the past 60 months (years: t-5). The resulting beta coefficient should be saved into an existing variable for the months of the current year t. I think that I am trying to use the “if command” as if it was an “if qualifier”, something which STATA apparently does not allow. My logic is to run the regression whenever 60 months of data are available in a period “t” for group “j” and if there is no data available for the last 60 months, setting the variable beta to missing. Unfortunately, my code does not work:


gen beta=.
forvalues i=1986(1)2000 {
disp "year `i' "
foreach j of numlist 1 2 7{
egen count_month=count(retrf) if year<`i'&year>=(`i'-5)&sic2==`j'
	
if count_month==60 {
	reg retrf mktrf if year<`i' &year>=(`i' -5)&sic2==`j'
	quietly mat b=get(_b)
	quietly replace beta=b[1,1] if year==`i' &sic2==`j'
}
else {
	quietly replace beta=. if year==1986&sic2==1
}
drop count_month
	}
}

I would greatly appreciate any kind of help. Many thanks in advance.

Kind regards

Philipp

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