【问题标题】:Export summary table with two group-by variables to LaTeX将带有两个分组变量的汇总表导出到 LaTeX
【发布时间】:2017-03-07 16:57:03
【问题描述】:

我正在尝试使用 community-contributed 命令estout 将双向汇总表导出到 LaTeX。这是一个表格,总结了两个分类变量 foreignpricehigh 中数值 weight 的平均值:

sysuse auto, clear
gen pricehigh = 0
replace pricehigh = 1 if price > 6165

tabulate foreign pricehigh, summarize(weight) means label

                          Means of Weight (lbs.)

           |      pricehigh
  Car type |         0          1 |     Total
-----------+----------------------+----------
  Domestic | 3,080.513  4,026.923 | 3,317.115
   Foreign | 2,118.462  2,601.111 | 2,315.909
-----------+----------------------+----------
     Total |     2,840  3,443.636 | 3,019.459

但是,Stata 告诉我,在使用 tabulateestpost 时,tabulatesummarize() 选项是不允许的:

estpost tabulate foreign pricehigh, summarize(weight) means label
option summarize() not allowed
r(198);

我一直在搜索estout 文档(尤其是here)和Statalist,但找不到如何使用estout 重新创建此表。

【问题讨论】:

    标签: export latex stata mean


    【解决方案1】:

    community-contributed 命令tabout 可以轻松生成所需的输出,如下所示:

    sysuse auto, clear
    
    generate pricehigh = 0
    replace pricehigh = 1 if price > 6165
    
    tabout foreign pricehigh using table.tex, style(tex) content(mean weight) sum replace 
    
    type table.tex
    
    \begin{center}
    \footnotesize
    \newcolumntype{Y}{>{\raggedleft\arraybackslash}X}
    \begin{tabularx} {14} {@{} l Y Y Y @{}}
    \toprule
    & \multicolumn{3}{c}{pricehigh}  \\
    \cmidrule(l{1em}){2-4} 
     & 0 & 1 & Total \\
    \cmidrule(l{1em}){2-4} 
     & Mean weight & Mean weight & Mean weight \\
    \midrule 
    Car type \\
    Domestic & 3,080.5 & 4,026.9 & 3,317.1 \\
    Foreign & 2,118.5 & 2,601.1 & 2,315.9 \\
    Total & 2,840.0 & 3,443.6 & 3,019.5 \\
    \bottomrule
    \end{tabularx}
    \normalsize
    \end{center}
    

    相比之下,对estout 执行相同操作需要您自己创建表:

    sysuse auto, clear
    generate pricehigh = 0
    replace pricehigh = 1 if price > 6165
    
    matrix A = J(3, 3, 0)
    
    summarize weight if !foreign & !pricehigh, meanonly
    matrix A[1,1] = r(mean)
    
    summarize weight if !foreign & pricehigh, meanonly
    matrix A[1,2] = r(mean)
    
    summarize weight if !foreign, meanonly
    matrix A[1,3] = r(mean)
    
    summarize weight if foreign & !pricehigh, meanonly
    matrix A[2,1] = r(mean)
    
    summarize weight if foreign & pricehigh, meanonly
    matrix A[2,2] = r(mean)
    
    summarize weight if foreign, meanonly
    matrix A[2,3] = r(mean)
    
    summarize weight if !pricehigh, meanonly
    matrix A[3,1] = r(mean)
    
    summarize weight if pricehigh, meanonly
    matrix A[3,2] = r(mean)
    
    summarize weight, meanonly
    matrix A[3,3] = r(mean)
    
    matrix colnames A = 0 1 Total
    matrix rownames A = Domestic Foreign Total
    

    结果:

    esttab matrix(A), title(Means of Weight (lbs.)) mtitles(pricehigh) gaps
    
    
    Means of Weight (lbs.)
    ---------------------------------------------------
                    pricehigh                          
                            0            1        Total
    ---------------------------------------------------
    Domestic         3080.513     4026.923     3317.115
    
    Foreign          2118.462     2601.111     2315.909
    
    Total                2840     3443.636     3019.459
    ---------------------------------------------------
    

    这里使用命令esttabestout 的包装器)进行说明。

    【讨论】:

      猜你喜欢
      • 2021-10-06
      • 2017-01-11
      • 2018-08-08
      • 2018-03-27
      • 1970-01-01
      • 1970-01-01
      • 2023-01-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多