【问题标题】:Tabulate a combined matrix of coefficients / t-statistics and export in LaTeX将系数/t 统计量的组合矩阵制成表格并在 LaTeX 中导出
【发布时间】:2018-12-06 01:22:26
【问题描述】:

我对四个结果变量进行了多次回归(每年一次,超过 15 年)。

我创建了两个15x4 矩阵:一个带有系数,一个带有 t 统计量。我现在被困住了,我想以经典的方式将它们制成表格,每一行都有每个模型的系数,在它们下面是括号之间的相应 t 统计量。

我可以将单个矩阵制成表格,但即使使用estadd 我也无法获得上述结果。

这是我的代码:

*creates matrix of all results row(year) column(outcome)
matrix OLS_years = r_Mall, r_hotMall, r_totMall, r_irpMall
matrix list OLS_years
matrix TSTATS = ex_Tall, hot_Tall, tot_Tall, irp_Tall
matrix list TSTATS 

使用 community-contributed 命令estout 只会生成一个包含系数的表格:

    estout matrix(OLS_years), ///
     cells(OLS_years TSTATS(par)) ///
     stats(N, fmt(0) labels ("No. of Obs." )) ///
     starlevels(* 0.1 ** 0.05 *** 0.001) ///
     varwidth(20) ///
     modelwidth(12) ///
     delimiter(&) ///
     end(\\) ///
     prehead(`"\begin{tabular}{l*{4}{c}}"' `"\toprule"') ///
     posthead("\midrule") ///
     prefoot("\midrule") ///
     postfoot(`"\bottomrule"' `"\multicolumn{@span}{l}{\footnotesize t-statistics in parentheses}\\"' `"\multicolumn{@span}{l}{\footnotesize *** p{$<$}0.01; ** p{$<$}0.05; * p{$<$}0.10.}\\"' `"\end{tabular}"') ///
     varlabels(_cons Constant, end("" \addlinespace) nolast) ///
     eqlabels(, begin("\midrule" "") nofirst) ///
     substitute(_ \_ "\_cons " \_cons) ///
     interaction(" $\times$ ") ///
     notype ///
     level(95) ///
     style(esttab)

谁能帮忙?

【问题讨论】:

    标签: matrix latex stata


    【解决方案1】:

    我的挑战是将@Pearly Spencer 解释的方法应用于更复杂的设置,我必须将来自 4 种不同规格和 15 年的回归估计值堆叠在一个准备输入的 Latex 表中。我通过使用 -esttab- 和 -noisily- 选项解决了这个问题,这非常方便,因为它显示了它背后的 estout 命令(esttab 是 estout 的包装器)。通过这种方式,我设法个性化了桌子的三个部分(顶部、中间、底部),以便我可以很好地堆叠它们。我以一般方式发布代码,其中 y1、y2、y3、y4 是不同的结果变量,而 T 是治疗变量,您希望看到对 y 的影响。

    set more off
    
    *-----------------FIRST YEAR I.E. TOP PART OF THE TABLE
    eststo clear
        label var T "T 2002"
    
                    qui reg Y1 T `x_prop' ///
                    if year==2002 
                    eststo y1_2002
    
                    qui reg Y2 T `x_prop' ///
                    if year==2002 
                    eststo y2_2002
    
                    qui reg Y3 T `x_prop' ///
                    if year==2002 
                    eststo y3_2002
    
                    qui reg Y4 T `x_prop' ///
                    if year==2002 
                    eststo y4_2002
    
    qui cap erase "C:\Users\...\tabz.tex"   // the replace option did not seem to work, so I used this way instead
    
    estout using `"C:\Users\...\tabz.tex"' , ///
     cells(b(fmt(a3) star) t(fmt(2) par)) ///
     starlevels(* 0.1 ** 0.05 *** 0.001) ///
     varwidth(20) ///
     modelwidth(12) ///
     delimiter(&) ///
     end(\\) ///
     prehead("{\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi} \begin{tabular}{l*{4}{c}} \toprule  &\multicolumn{1}{c}{(5)}&\multicolumn{1}{c}{(6)}&\multicolumn{1}{c}{(7)}&\multicolumn{1}{c}{(8)}\\") ///
     posthead("\midrule") ///
     label ///
     varlabels(_cons Constant, end("" \addlinespace) nolast) ///
     mlabels(, depvar span prefix(\multicolumn{@span}{c}{) suffix(})) ///
     collabels(none) ///
     eqlabels(, begin("\midrule" "") nofirst) ///
     substitute(_ \_ "\_cons " \_cons) ///
     interaction(" $\times$ ") ///
     notype ///
     level(95) ///
     style(esttab) ///
     keep(T) 
    
     *-----------------OTHER YEARS I.E. MID PART OF THE TABLE
    forval i=2003/2015 { 
    eststo clear
    
        label var T "T `i'"
                    qui reg Y1 T `x_prop' ///
                    if year==`i'
                    eststo y1_`i'
    
                    qui reg Y2 T `x_prop' ///
                    if year==`i'
                    eststo y2_`i'
    
                    qui reg Y3 T `x_prop' ///
                    if year==`i'
                    eststo y3_`i'
    
                    qui reg Y4 T `x_prop' ///
                    if year==`i'
                    eststo y4_`i'
    
    esttab using "C:\Users\...\tabz.tex\tabz.tex", keep(T) append f label nomtitle nonumber collabels(none) ///
    starlevels(* 0.1 ** 0.05 *** 0.001) booktabs gaps noline ///
        notes addnotes("t-statistics in parentheses" "*** p{$<$}0.01; ** p{$<$}0.05; * p{$<$}0.10.") ///
        noobs
    }
    
     *-----------------OTHER YEARS I.E. BOTTOM PART OF THE TABLE
    
    eststo clear
    
        label var T "T 2016"
                    qui reg Y1 T `x_prop' ///
                    if year==2016 & violat_2016==0
                    eststo y1_2016
    
                    qui reg Y2 T `x_prop' ///
                    if year==2016 & violat_2016==0
                    eststo y2_2016
    
                    qui reg Y3 T `x_prop' ///
                    if year==2016 & violat_2016==0
                    eststo y3_2016
    
                    qui reg Y4 T `x_prop' ///
                    if year==2016 & violat_2016==0
                    eststo y4_2016
    
    esttab using "C:\Users\...\tabz.tex", keep(T) append f label nomtitle nonumber collabels(none) ///
    starlevels(* 0.1 ** 0.05 *** 0.001) booktabs gaps noline ///
        notes addnotes("t-statistics in parentheses" "*** p{$<$}0.01; ** p{$<$}0.05; * p{$<$}0.10.") ///
         prefoot("\midrule") ///
         postfoot("\bottomrule \multicolumn{5}{l}{\footnotesize t-statistics in parentheses}\\ \multicolumn{5}{l}{\footnotesize *** p{$<$}0.01; ** p{$<$}0.05; * p{$<$}0.10.}\\ \end{tabular}")
    

    我希望这对其他人有用,因为我花了很长时间。

    【讨论】:

      【解决方案2】:

      在这种情况下创建矩阵是不必要的。相反,您可以使用estimates store post-estimation 命令运行回归并保存结果。

      以下是使用 Stata 的 auto toy 数据集作为示例的方法:

      sysuse auto.dta, clear
      estimates clear
      
      regress price gear_ratio length
      estimates store A
      
      regress mpg i.foreign trunk turn
      estimates store B
      
      regress displacement headroom length weight
      estimates store C
      
      esttab A B C
      

      ------------------------------------------------------------
                            (1)             (2)             (3)   
                          price             mpg    displacement   
      ------------------------------------------------------------
      gear_ratio         -162.4                                   
                        (-0.17)                                   
      
      length              54.88**                        -0.601   
                         (2.78)                         (-0.88)   
      
      0.foreign                               0                   
                                            (.)                   
      
      1.foreign                          -1.168                   
                                        (-0.91)                   
      
      trunk                              -0.312*                  
                                        (-2.32)                   
      
      turn                               -0.840***                
                                        (-5.34)                   
      
      headroom                                            7.146   
                                                         (1.07)   
      
      weight                                              0.118***
                                                         (6.15)   
      
      _cons             -3659.7           59.26***       -68.23   
                        (-0.60)         (10.25)         (-0.92)   
      ------------------------------------------------------------
      N                      74              74              74   
      ------------------------------------------------------------
      t statistics in parentheses
      * p<0.05, ** p<0.01, *** p<0.001
      

      或者在 LaTeX 中:

      esttab A B C using table.tex
      
      type table.tex
      
      {
      \def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
      \begin{tabular}{l*{3}{c}}
      \hline\hline
                  &\multicolumn{1}{c}{(1)}&\multicolumn{1}{c}{(2)}&\multicolumn{1}{c}{(3)}\\
                  &\multicolumn{1}{c}{price}&\multicolumn{1}{c}{mpg}&\multicolumn{1}{c}{displacement}\\
      \hline
      gear\_ratio  &      -162.4         &                     &                     \\
                  &     (-0.17)         &                     &                     \\
      [1em]
      length      &       54.88\sym{**} &                     &      -0.601         \\
                  &      (2.78)         &                     &     (-0.88)         \\
      [1em]
      0.foreign   &                     &           0         &                     \\
                  &                     &         (.)         &                     \\
      [1em]
      1.foreign   &                     &      -1.168         &                     \\
                  &                     &     (-0.91)         &                     \\
      [1em]
      trunk       &                     &      -0.312\sym{*}  &                     \\
                  &                     &     (-2.32)         &                     \\
      [1em]
      turn        &                     &      -0.840\sym{***}&                     \\
                  &                     &     (-5.34)         &                     \\
      [1em]
      headroom    &                     &                     &       7.146         \\
                  &                     &                     &      (1.07)         \\
      [1em]
      weight      &                     &                     &       0.118\sym{***}\\
                  &                     &                     &      (6.15)         \\
      [1em]
      \_cons      &     -3659.7         &       59.26\sym{***}&      -68.23         \\
                  &     (-0.60)         &     (10.25)         &     (-0.92)         \\
      \hline
      \(N\)       &          74         &          74         &          74         \\
      \hline\hline
      \multicolumn{4}{l}{\footnotesize \textit{t} statistics in parentheses}\\
      \multicolumn{4}{l}{\footnotesize \sym{*} \(p<0.05\), \sym{**} \(p<0.01\), \sym{***} \(p<0.001\)}\\
      \end{tabular}
      }
      

      【讨论】:

        猜你喜欢
        • 2017-05-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-04-13
        • 2013-02-19
        • 1970-01-01
        • 1970-01-01
        • 2020-06-15
        相关资源
        最近更新 更多