Hello, I am very new to Stata and this forum so please excuse and feel free to correct any mistakes that I make (trying my best to post correctly)!
I have 48 years of monthly panel data for stock returns as follows (only an illustration):
gvkey date Peer_Excess Market_Excess sic Return
1001 jan1982 .063452 .034827 508 .032871
1001 feb1982 -.039245 .043827 508 -.067398
.
.
.
1002 jan1982 .032718 .031563 372 .021783
1002 feb1982 -.023142 .024892 372 -.042892
.
.
1003 march1983 .023813 .043291 210 .049382
1003 may1983 .032432 .032871 210 .054938
where gvkey is the identifier for each stock and Peer_Excess is the return on an equally weighted portfolio of peer firms in firm i's three-digit industry group (sic). I need to perform rolling regressions for each firm by regressing each firm's returns on the Peer_Excess and Market_Excess variables. The window begins with 24 months and increase up to 60 months. I need to save the intercept and betas for each regression. I have xtset my data prior to attempting any regressions.
The main problem is that the data is unbalanced. For instance, one firm has 200 data points over time and another has 120. The majority of the firm data also have gaps between months. I have looked at all of the help files and the Stata manual as well as all of the forum postings regarding rolling regressions and I cannot seem to find a workable solution. I have made attempts with rolling and rollreg (user written command).
I have also tried the following from another thread:
Any help or hints are greatly appreciated!!
I have 48 years of monthly panel data for stock returns as follows (only an illustration):
gvkey date Peer_Excess Market_Excess sic Return
1001 jan1982 .063452 .034827 508 .032871
1001 feb1982 -.039245 .043827 508 -.067398
.
.
.
1002 jan1982 .032718 .031563 372 .021783
1002 feb1982 -.023142 .024892 372 -.042892
.
.
1003 march1983 .023813 .043291 210 .049382
1003 may1983 .032432 .032871 210 .054938
where gvkey is the identifier for each stock and Peer_Excess is the return on an equally weighted portfolio of peer firms in firm i's three-digit industry group (sic). I need to perform rolling regressions for each firm by regressing each firm's returns on the Peer_Excess and Market_Excess variables. The window begins with 24 months and increase up to 60 months. I need to save the intercept and betas for each regression. I have xtset my data prior to attempting any regressions.
The main problem is that the data is unbalanced. For instance, one firm has 200 data points over time and another has 120. The majority of the firm data also have gaps between months. I have looked at all of the help files and the Stata manual as well as all of the forum postings regarding rolling regressions and I cannot seem to find a workable solution. I have made attempts with rolling and rollreg (user written command).
I have also tried the following from another thread:
Code:
gen alpha=. compress save "intermediate.dta" forvalues i=1/_N{ use intermediate.dta keep if gvkey==`i' sum caldt if gvkey==`i' local start_time=r(min)+24 local end_time=r(max) forvalues t=`start_time'/`end_time'{ quitely reg Return Excess_Return Peer_Excess if gvkey==`i' & caldt<=`t' & caldt>=`t'-59 replace alpha=_b[_cons] if gvkey==`i' & caldt==`t' & e(N)>=24 }save intermediate`i'.dta } use intermediate.dta forvalues i=1/_N{ append using intermediate`i'.dta erase intermediate`i'.dta }
Comment