Announcement

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

  • univar results into one table

    Hello,

    I am wondering if anyone knows a way to generate Univar results into one table? In my example below, I would want "White", "Black" and "Other" to be rows in a table, while columns would be N Mean S.D. Min .25 Mdn .75 and Max. Would the best way to do this be to use the table command?

    Thank you for any help.

    sysuse nlsw88.dta
    univar tenure if grade==18, by(race)

    -> race=white
    -------------- Quantiles --------------
    Variable n Mean S.D. Min .25 Mdn .75 Max

    tenure 126 6.60 5.70 0.00 2.00 4.21 9.83 20.42


    -> race=black
    -------------- Quantiles --------------
    Variable n Mean S.D. Min .25 Mdn .75 Max

    tenure 27 9.98 6.34 0.00 3.83 9.67 15.83 21.75


    -> race=other
    -------------- Quantiles --------------
    Variable n Mean S.D. Min .25 Mdn .75 Max

    tenure 1 6.75 . 6.75 6.75 6.75 6.75 6.75


  • #2
    Advice in the FAQ, which you were asked to read before posting, includes this (Section 12):

    If you are using user-written commands, explain that and say where where they came from: the Stata Journal, SSC, or other archives. This helps (often crucially) in explaining your precise problem, and it alerts readers to commands that may be interesting or useful to them.
    univar is a user-written program from the Stata Technical Bulletin, last updated in 1999. Manifestly, it still works, but its functionality here has largely been overtaken by tabstat.

    Here is an approach to your problem:


    Code:
    . sysuse nlsw88.dta
    (NLSW, 1988 extract)
    
    . tabstat tenure if grade==18, by(race) s(n mean sd min p25 p50 p75 max) format(%3.2f)
    
    Summary for variables: tenure
         by categories of: race (race)
    
      race |         N      mean        sd       min       p25       p50       p75
    -------+----------------------------------------------------------------------
     white |    126.00      6.60      5.70      0.00      2.00      4.21      9.83
     black |     27.00      9.98      6.34      0.00      3.83      9.67     15.83
     other |      1.00      6.75         .      6.75      6.75      6.75      6.75
    -------+----------------------------------------------------------------------
     Total |    154.00      7.19      5.92      0.00      2.50      5.04     11.08
    ------------------------------------------------------------------------------
    
      race |       max
    -------+----------
     white |     20.42
     black |     21.75
     other |      6.75
    -------+----------
     Total |     21.75
    ------------------
    That said, tabstat is a little dopey in blindly using the same format for integer sample sizes as for the other sample statistics.


    Comment


    • #3
      Thank you Nick; this is just what I needed.

      Comment

      Working...
      X