Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Tabstat output

    I seem to be struggling with outputting tabstat output into a tex table. I am using the auto dataset here, but the problem transfers to my data.

    Using the auto data,

    sysuse auto
    estpost tabstat displacement gear_ratio, by(make) stats(mean sem)

    Makes a fine table, but when I try to use esttab or estout to output it, it doesn't work.

    esttab ,cells(mean(fmt(%12.3f)) semean(fmt(%12.3f) par(( ))))
    estout ,cells(mean(fmt(%12.3f)) semean(fmt(%12.3f) par(( ))))

  • #2
    estout is from SSC (FAQ Advice #12). If you are interested in means and their standard errors, use the mean command, as it is an estimation command in the Stata sense. tabstat is not, and that is why you need estpost. The example using make as a by-variable is a poor one, as make uniquely identifies observations in the auto dataset. As such, there is no variance within the defined by-groups. 'rep78' would be a better choice.

    Code:
    sysuse auto, clear
    mean displacement gear_ratio, over(rep78)
    esttab ., se varwidth(30)
    Res.:

    Code:
    . mean displacement gear_ratio, over(rep78)
    
    Mean estimation                                     Number of obs = 69
    
    ----------------------------------------------------------------------
                         |       Mean   Std. err.     [95% conf. interval]
    ---------------------+------------------------------------------------
    c.displacement@rep78 |
                      1  |        191         40      111.1812    270.8188
                      2  |     242.25   27.42506      187.5241    296.9759
                      3  |   230.0333   16.78447      196.5404    263.5262
                      4  |   178.8333   22.64131      133.6533    224.0134
                      5  |   111.0909   7.675764      95.77416    126.4077
                         |
      c.gear_ratio@rep78 |
                      1  |      2.905       .175      2.555793    3.254207
                      2  |    2.68625   .1122487      2.462261    2.910239
                      3  |      2.871   .0750959      2.721149    3.020851
                      4  |   3.176111    .126295      2.924093    3.428129
                      5  |   3.304545   .1008993      3.103204    3.505887
    ----------------------------------------------------------------------
    
    . 
    . esttab ., se varwidth(30)
    
    ----------------------------------------------
                                            (1)   
                                           Mean   
    ----------------------------------------------
    [email protected]                  191***
                                           (40)   
    
    [email protected]                242.2***
                                        (27.43)   
    
    [email protected]                230.0***
                                        (16.78)   
    
    [email protected]                178.8***
                                        (22.64)   
    
    [email protected]                111.1***
                                        (7.676)   
    
    [email protected]                  2.905***
                                        (0.175)   
    
    [email protected]                  2.686***
                                        (0.112)   
    
    [email protected]                  2.871***
                                       (0.0751)   
    
    [email protected]                  3.176***
                                        (0.126)   
    
    [email protected]                  3.305***
                                        (0.101)   
    ----------------------------------------------
    N                                        69   
    ----------------------------------------------
    Standard errors in parentheses
    * p<0.05, ** p<0.01, *** p<0.001
    
    .
    Last edited by Andrew Musau; 09 Nov 2024, 06:46.

    Comment


    • #3
      Thanks Andrew! Completely agree that make as a by variable was a poor choice.

      The struggle I am having is that if you simply esttab the above results using the mean function, they show up stacked as opposed to in two columns right next to one another. Even if I run them separately, eststo: mean displacement, over(rep78) and then eststo: mean gear_ratio, over(rep78), and either esttab or etable, estimates(est1 est2), then they cannot be combined adequately. Do you have a suggestion?

      Comment


      • #4
        If you don't need the significance levels (stars) for testing the means against zero -tabstat- would be most straightforward. -etstab- is not made for this: How could the means be placed in two columns next to each other if they are the means of different variables (displacement vs. gear_ratio) at each level of rep78? What would you expect to be the row names? However, if you are willing to tinker around with variable names, the following may do what want:
        Code:
        . sysuse auto, clear
        (1978 automobile data)
        
        .
        . tabstat displacement gear_ratio, by(rep78) s(mean semean count)
        
        Summary statistics: Mean, se(mean), N
        Group variable: rep78 (Repair record 1978)
        
           rep78 |  displa~t  gear_r~o
        ---------+--------------------
               1 |       191     2.905
                 |        40      .175
                 |         2         2
        ---------+--------------------
               2 |    242.25   2.68625
                 |  27.42506  .1122487
                 |         8         8
        ---------+--------------------
               3 |  230.0333     2.871
                 |  16.78447  .0750959
                 |        30        30
        ---------+--------------------
               4 |  178.8333  3.176111
                 |  22.64131   .126295
                 |        18        18
        ---------+--------------------
               5 |  111.0909  3.304545
                 |  7.675764  .1008993
                 |        11        11
        ---------+--------------------
           Total |       198  2.999275
                 |  11.21369  .0557003
                 |        69        69
        ------------------------------
        
        .
        . clonevar lev_rep78 = displacement
        
        . mean lev_rep78, over(rep78)
        
        Mean estimation                                  Number of obs = 69
        
        -------------------------------------------------------------------
                          |       Mean   Std. err.     [95% conf. interval]
        ------------------+------------------------------------------------
        c.lev_rep78@rep78 |
                       1  |        191         40      111.1812    270.8188
                       2  |     242.25   27.42506      187.5241    296.9759
                       3  |   230.0333   16.78447      196.5404    263.5262
                       4  |   178.8333   22.64131      133.6533    224.0134
                       5  |   111.0909   7.675764      95.77416    126.4077
        -------------------------------------------------------------------
        
        . est sto m1
        
        . drop lev_rep78
        
        .
        . clonevar lev_rep78 = gear_ratio
        
        . mean lev_rep78, over(rep78)
        
        Mean estimation                                  Number of obs = 69
        
        -------------------------------------------------------------------
                          |       Mean   Std. err.     [95% conf. interval]
        ------------------+------------------------------------------------
        c.lev_rep78@rep78 |
                       1  |      2.905       .175      2.555793    3.254207
                       2  |    2.68625   .1122487      2.462261    2.910239
                       3  |      2.871   .0750959      2.721149    3.020851
                       4  |   3.176111    .126295      2.924093    3.428129
                       5  |   3.304545   .1008993      3.103204    3.505887
        -------------------------------------------------------------------
        
        . est sto m2
        
        . drop lev_rep78
        
        . esttab m1 m2, mtitle("displacement" "gear_ratio") se varwidth(30)
        
        --------------------------------------------------------------
                                                (1)             (2)   
                                       displacement      gear_ratio   
        --------------------------------------------------------------
        [email protected]                     191***        2.905***
                                               (40)         (0.175)   
        
        [email protected]                   242.2***        2.686***
                                            (27.43)         (0.112)   
        
        [email protected]                   230.0***        2.871***
                                            (16.78)        (0.0751)   
        
        [email protected]                   178.8***        3.176***
                                            (22.64)         (0.126)   
        
        [email protected]                   111.1***        3.305***
                                            (7.676)         (0.101)   
        --------------------------------------------------------------
        N                                        69              69   
        --------------------------------------------------------------
        Standard errors in parentheses
        * p<0.05, ** p<0.01, *** p<0.001

        Comment

        Working...
        X