我试图在stata中重现以下内容。这是平均投资组合收益(y轴)和预测的重组(x轴)的散点图。
为了做到这一点,我需要你帮助我如何从25次回归中提取拦截到一个变量?我目前正在运行25个投资组合回归,如下所示。我已经看到parmest
可能会这样做,但无法让它与forval一起使用。非常感谢
forval s = 1 / 5 {
forval h = 1 / 5 {
reg S`s'H`h' Mkt_Rf SMB HML
}
}
答案 0 :(得分:2)
我不知道你的数据是什么样的,但也许这样的东西会起作用:
gen intercepts = .
local i = 1
forval s = 1 / 5 {
forval h = 1 / 5 {
reg S`s'H`h' Mkt_Rf SMB HML
// assign the ith observation of intercepts
// equal to the regression constant
replace intercepts = _b[_cons] if _n == `i'
// increment i
local ++i
}
}
答案 1 :(得分:1)
postfile
系列命令在这种情况下非常有用。这些命令允许您将结果存储在单独的数据集中,而不会丢失内存中的数据。
您可以从这个开始作为一个简单的例子。此代码将生成一个名为" results.dta"的Stata数据集。变量s h和常数以及每个回归的记录。
cap postclose results
postfile results s h constant using results.dta, replace
forval s = 1 / 5 {
forval h = 1 / 5 {
reg S`s'H`h' Mkt_Rf SMB HML
loc c = _b[_cons]
post results (`s') (`h') (`c')
}
}
postclose results
use results, clear