1man
1man

Reputation: 5634

Switching variables from columns to rows when using tabstat

I use the tabstat command in Stata 14 and the community-contributed latabstat command to generate the corresponding LaTeX code:

tabstat ListOfVariables, stat(count mean sd min max)

When listOfVariables includes only one variable, the variable shows up in the row and stats show up in columns. However, when there are more than a variable in listOfVariables, the variables show up in columns and stats show up in rows. this is particularly bizarre when I have many variables listed in columns.

How can I switch variables from columns to rows?

Upvotes: 0

Views: 3758

Answers (1)

user8682794
user8682794

Reputation:

You just need to use the columns(statistics) option of the tabstat command:

sysuse auto, clear

tabstat price, statistics(count mean sd min max)

    variable |         N      mean        sd       min       max
-------------+--------------------------------------------------
       price |        74  6165.257  2949.496      3291     15906
----------------------------------------------------------------

tabstat price weight mpg rep78, statistics(count mean sd min max)

   stats |     price    weight       mpg     rep78
---------+----------------------------------------
       N |        74        74        74        69
    mean |  6165.257  3019.459   21.2973  3.405797
      sd |  2949.496  777.1936  5.785503  .9899323
     min |      3291      1760        12         1
     max |     15906      4840        41         5
--------------------------------------------------

tabstat price weight mpg rep78, statistics(count mean sd min max) columns(statistics)

    variable |         N      mean        sd       min       max
-------------+--------------------------------------------------
       price |        74  6165.257  2949.496      3291     15906
      weight |        74  3019.459  777.1936      1760      4840
         mpg |        74   21.2973  5.785503        12        41
       rep78 |        69  3.405797  .9899323         1         5
----------------------------------------------------------------

Upvotes: 3

Related Questions