数据是一个企业的若干月份的股票回报以及市场回报和行业回报。想要求残差。
回归就用 reg return market ind
但是需要月份数据滚动回归,然后求残差。具体而言
1.使用本企业前60个月的数据进行回归。用所得回归系数与本年数据计算本年各个月份的残差。
to obtain residual for IBM between January 1990 and December 1990, we first estimate above equation using monthly returns from January 1985 through December 1989. Using the estimated coefficients and the factor returns from January 1990 through December 1990, we use above equation to compute the expected return and idiosyncratic returns
这是计算的原文,应该跟我理解一致。
2.在计算完本年残差之后,同样的过程,滚动到下一年求残差。
3.一个企业完成上述过程之后,继续第二个企业。。。(我企业样本一千多)
请教这个程序应该如何编写啊?
感谢各位了!
首先你有一个公司代码变量比如code,要根据这个生成一个数值变量group,命令如下:
egen group=group(code)
*20为公司个数
forvalues i=1/20 {
reg y x if tin(2007m1,2007m12) & group==`i'
predict ee if tine(2008m1,2008m12) & group==`i',residuals
}