Announcement

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

  • Trouble horizontally orienting estpost tabstat table of summary statistics

    Hi all—I am a Stata 17 user on several operating systems. I have run into some version of this problem a few times trying to create basic tables of summary statistics comparing values across different by() groups.

    I have no problem creating a table comparing means and SDs for multiple variables across different by groups that looks very nice, but can only do so in a vertically oriented way:

    Code:
    clear all
    sysuse auto 
    
    *Table I want transposed
    
    estpost tabstat price mpg weight, ///
      by(foreign) stats(mean sd) listwise nototal c(stats)
    
    esttab, main(mean) aux(sd) nostar nogaps ///
      noobs nomtitle nonumber label unstack /// 
      note("Standard deviations in parentheses")

    Which produces (sorry in advance that this isn't rendering in an attractive way) :

    ----------------------------------------------
    Domestic Foreign
    ----------------------------------------------
    Price 6072.4 6384.7
    (3097.1) (2621.9)
    Mileage (mpg) 19.83 24.77
    (4.743) (6.611)
    Weight (lbs.) 3317.1 2315.9
    (695.4) (433.0)
    ----------------------------------------------
    Standard deviations in parentheses


    I would like a transposed version of this, with the rows being the by-groups and the columns being the variables, with the same structure of mean (sd) preserved. Yet when I try the direct modification (using c(variables) instead of c(stats) in the estpost command), I get no table at all:

    Code:
    est clear
    *My attempt at using c(variables) does not work: 
    estpost tabstat price mpg weight, ///
      by(foreign) stats(mean sd) listwise nototal c(variables)
    
    esttab, main(mean) aux(sd) nostar nogaps ///
      noobs nomtitle nonumber label unstack /// 
      note("Standard deviations in parentheses")
    This produces just 3 horizontal lines with no data at all.

    Thank you in advance for the help!

  • #2
    estout is from SSC (FAQ Advice #12). You need to look at how the matrices holding the results are named.

    Code:
    clear all
    sysuse auto
    
    *Table I want transposed
    
    estpost tabstat price mpg weight, ///
      by(foreign) stats(mean sd) listwise nototal c(stats)
    
    esttab, main(mean) aux(sd) nostar nogaps ///
      noobs nomtitle nonumber label unstack ///
      note("Standard deviations in parentheses")
    
    est clear
    *My attempt at using c(variables) does not work:
    estpost tabstat price mpg weight, ///
      by(foreign) stats(mean sd) listwise nototal c(variables)
    
    esttab, cells("price mpg weight") nostar nogaps ///
      noobs nomtitle nonumber label
    Res.:
    Code:
    . esttab, cells("price mpg weight") nostar nogaps ///
    >   noobs nomtitle nonumber label
    
    -----------------------------------------------------------
                                price          mpg       weight
    -----------------------------------------------------------
    Domestic                                                  
    mean                     6072.423     19.82692     3317.115
    sd                       3097.104     4.743297     695.3637
    -----------------------------------------------------------
    Foreign                                                    
    mean                     6384.682     24.77273     2315.909
    sd                       2621.915     6.611187     433.0035
    -----------------------------------------------------------

    To add parentheses around the SD estimates, there are a number of ways including manipulating the results' matrices or using some of estout's options. If it is my problem, I would simply deploy the estimation command mean which will transfer these results to e().

    Comment

    Working...
    X