stata - Trailing ten-year Fama-MacBeth slope coefficients -
i have panel data in long format panel variable firm id
, monthly time variable between 1986m7 , 2015m12.
i want trailing ten-year beta estimates of fama-macbeth regressions , store in new file later plot them.
i want beta fmb regression 1986m7 until 1996m7, beta 1986m8 until 1996m8 , on, last regression 2005m12 2015m12.
i thought first rolling
command don't know how tell stata "roll" on time not id or if possible command.
my second idea work while
loop. don't know how tell stata after every loop should local variable 1 month. possible save local variables dates?
maybe knows way solve problem.
also solution store betas in new file , append new betas appreciated. thought of storing them scalars don't know how put scalars new variable. rolling command problem not 1 since creates new variable me.
what have code far rolling idea, window(120)
because of 120 month (10 year) rolling window:
use mydata, clear ssc install xtfbm xtset id date rolling _b, clear window(120): xtfmb y x
what have code far loop idea:
ssc install xtfmb local = tm(1986m7) while `i' <= tm(2005m7) { use mydata, clear drop if date < tm(`i') drop if date >= tm(`i' + "1year") xtset id date quietly xtfmb y x scalar x`i' = _b[x] local = `i' + "1month" }
a bundle of comments purporting answer:
the program called stata, not stata. elementary.
xtfbm
presumably typo xtfmb
. either way, have never used it, or looked @ it, refrain trying advise on specifically.
more interestingly, rolling
support panel set-ups. here dopey example can try:
webuse grunfeld xtset rolling _b, window(10): regress invest year
as first code block appears trying similar, not clear asking there.
you ask "is possible save local variables dates?" backwards, think understand meaning. stata dates numbers, can save them local macros (which in stata not regarded variables). legal:
local t = ym(1986, 7) while `t' <= ym(2005, 7) { ... local t = `t' + 12 ... local ++t }
and better:
forval t = `=ym(1986, 7)'/`=ym(2005, 7)' { ... local t = `t' + 12 ... }
which might seem clearer
local t1 = ym(1986, 7) local t2 = ym(2005, 7) forval t = `t1'/`t2' { ... local t = `t' + 12 ... }
but advice still try rolling
, you.
Comments
Post a Comment