【问题标题】:Extract intercepts from multiple regressions in stata从stata中的多个回归中提取截距
【发布时间】:2017-04-29 03:17:30
【问题描述】:

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

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

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

        }
    }

【问题讨论】:

    标签: stata finance quantitative-finance


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

      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
      

      【讨论】:

        猜你喜欢
        • 2014-01-07
        • 1970-01-01
        • 2019-05-29
        • 1970-01-01
        • 2012-05-27
        • 1970-01-01
        • 2016-08-31
        • 1970-01-01
        • 2020-04-12
        相关资源
        最近更新 更多