【问题标题】:Exporting results from regressions in Excel在 Excel 中导出回​​归结果
【发布时间】:2019-09-02 22:35:31
【问题描述】:

我想将普通最小二乘 (OLS) 回归的结果存储在双循环中的 Stata 中。

这是我的代码结构:

foreach i2 of numlist 1 2 3{
    foreach i3 of numlist 1 2 3 4{
        quiet: eststo: reg dep covariates, robust
    }
}

最终目标是在 Excel 中创建一个由十二行(每个模型一个)和七列(观察数、估计常数、五个估计系数)组成的表格。

关于如何做到这一点的任何建议?

【问题讨论】:

    标签: stata


    【解决方案1】:

    这样的表可以通过使用community-contributed命令esttab简单地创建:

    sysuse auto, clear
    eststo clear
    
    eststo m1: quietly regress price weight
    eststo m2: quietly regress price weight mpg
    
    quietly esttab
    matrix A = r(coefs)'
    matrix C = r(stats)'
    
    tokenize "`: rownames A'"
    forvalues i = 1 / `=rowsof(A)' {
        if strmatch("``i''", "*b*") matrix B = nullmat(B) \ A[`i', 1...]
    }
    
    matrix C = B , C
    matrix rownames C = "Model 1" "Model 2"
    

    结果:

    esttab matrix(C) using table.csv, eqlabels(none) mlabels(none) varlabels("Model 1" "Model 2")
    
    ----------------------------------------------------------------
                       weight          mpg        _cons            N
    ----------------------------------------------------------------
    Model 1          2.044063                 -6.707353           74
    Model 2          1.746559    -49.51222     1946.069           74
    ----------------------------------------------------------------
    

    【讨论】:

      猜你喜欢
      • 2018-10-02
      • 1970-01-01
      • 2021-07-20
      • 1970-01-01
      • 2021-12-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多