Announcement

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

  • Exchange axes of tabstat

    Hi all, sorry for the second question today but I was wondering if anyone has managed to figure out a way to transpose or essentially flip the axes of results from tabstat? See here:

    Code:
    sysuse auto2.dta
    tabstat price mpg turn, by(foreign)
    The resulting table looks like this:

    foreign | price mpg turn
    ---------+------------------------------
    Domestic | 6072.423 19.82692 41.44231
    Foreign | 6384.682 24.77273 35.40909
    ---------+------------------------------
    Total | 6165.257 21.2973 39.64865
    ----------------------------------------


    Is it possible to make it so that "Domestic" and "Foreign" are the two columns, and price, mpg, turn values are rows?

  • #2
    You can install estout from SSC which will allow you to do this.

    Code:
    sysuse auto, clear
    tabstat price mpg turn, by(foreign)
    by foreign: eststo: qui estpost summarize price mpg turn, listwise
    esttab, cells("mean") nodepvar label nonum collab(none)
    Res.:

    Code:
    . 
    . tabstat price mpg turn, by(foreign)
    
    Summary statistics: mean
      by categories of: foreign (Car type)
    
     foreign |     price       mpg      turn
    ---------+------------------------------
    Domestic |  6072.423  19.82692  41.44231
     Foreign |  6384.682  24.77273  35.40909
    ---------+------------------------------
       Total |  6165.257   21.2973  39.64865
    ----------------------------------------
    
    
    . esttab, cells("mean") nodepvar label nonum collab(none)
    
    ----------------------------------------------
                             Domestic      Foreign
    ----------------------------------------------
    Price                    6072.423     6384.682
    Mileage (mpg)            19.82692     24.77273
    Turn Circle (ft.)        41.44231     35.40909
    ----------------------------------------------
    Observations                   52           22
    ----------------------------------------------
    
    .

    Comment


    • #3
      No, not in the way that you want. There is the option to change the display of tabstat, but that looks like this:

      Code:
      . tabstat price mpg turn, by(foreign) col(stat)
      
      
      Summary for variables: price mpg turn
      Group variable: foreign (Car origin)
      
       foreign |      Mean
      ---------+----------
      Domestic |  6072.423
               |  19.82692
               |  41.44231
      ---------+----------
       Foreign |  6384.682
               |  24.77273
               |  35.40909
      ---------+----------
         Total |  6165.257
               |   21.2973
               |  39.64865
      --------------------
      You may also consider the new -table- command in Stata 17:

      Code:
      . table (var) (foreign), statistic(mean price mpg turn)
      
      ---------------------------------------------------
                        |            Car origin          
                        |  Domestic    Foreign      Total
      ------------------+--------------------------------
      Price             |  6072.423   6384.682   6165.257
      Mileage (mpg)     |  19.82692   24.77273    21.2973
      Turn circle (ft.) |  41.44231   35.40909   39.64865
      ---------------------------------------------------

      Comment


      • #4
        Leonardo Guizzetti thanks for introducing me to -table-. Your code doesn't seem to work for me though, it says var not found. If I remove (var) I get the error "option statistic() not allowed". I'll look at the help file now though!

        Comment


        • #5
          Sounds like you are not using version 17. The syntax, and functioning, of -table- were greatly changed in version 17. If you are using any version of Stata other than the most current when posting, you are asked to say so in your post so that people will respond with code you can actually run on your installation.

          Comment

          Working...
          X