从stata中的多重回归中提取截距

Extract intercepts from multiple regressions in stata

我正在尝试在 stata 中重现以下内容。这是平均投资组合 returns(y 轴)和预测回报率(x 轴)的散点图。

为此,我需要您的帮助,了解如何从 25 个回归中提取截距 到一个变量中?我目前 运行 的 25 个投资组合回归如下。我已经看到 parmest 可以做到这一点,但不能让它与 forval 一起工作。非常感谢

    forval s = 1 / 5 {
    forval h = 1 / 5 {
        reg S`s'H`h' Mkt_Rf SMB HML 

        }
    }

我不知道你的数据是什么样的,但也许像这样的东西会起作用:

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

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