Announcement

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

  • Using "dtable" to display standard deviation below mean.

    Hi,

    I want to create a table of descriptive statistics, where standard deviation (SD) is displayed below mean.

    I tried "dtable" command to do so, but it only displays SD right next to mean as below.

    Code:
    . sysuse auto, clear
    (1978 automobile data)
    
    .
    . dtable price mpg rep78
    
    ----------------------------------------
                              Summary       
    ----------------------------------------
    N                                     74
    Price              6,165.257 (2,949.496)
    Mileage (mpg)             21.297 (5.786)
    Repair record 1978         3.406 (0.990)
    ----------------------------------------
    But I need to display standard deviation below mean, just like "esttab" command does as below.

    Code:
    . eststo temp: estpost tabstat price mpg rep78, statistics(mean sd) columns(statistics)
    
    Summary statistics: mean sd
         for variables: price mpg rep78
    
                 |   e(mean)      e(sd)
    -------------+----------------------
           price |  6165.257   2949.496
             mpg |   21.2973   5.785503
           rep78 |  3.405797   .9899323
    
    . esttab temp, main(mean) aux(sd)
    
    ----------------------------
                          (1)   
                                
    ----------------------------
    price              6165.3   
                     (2949.5)   
    
    mpg                 21.30   
                      (5.786)   
    
    rep78               3.406   
                      (0.990)   
    ----------------------------
    N                      74   
    ----------------------------
    mean coefficients; sd in parentheses
    * p<0.05, ** p<0.01, *** p<0.001
    Is there a way to do this using "dtable" command? I tried "\n" as a delimiter in composite option, but it doesn't work.
    I assume it can be done using "collect", but do not know how to do this.

    Thank you.

  • #2
    Thank you for the minimal working example.

    You will need to use the collect suite of commands to change how the table is arranged. Here are the steps I took to accomplish this.
    Code:
    sysuse auto, clear
    
    dtable price mpg rep78
    
    * report the layout specification
    collect layout
    
    * look into which result levels are being shown
    collect query autolevels result
    collect levelsof result
    collect query composite
    collect query composite _dtable_stats
    * stop using the composite result, we want results to be stacked into a
    * single column
    collect style autolevels result frequency mean sd, clear
    
    * change how the cells are arranged;
    * stack the results across rows for each variable;
    * use -cmdset- for a column header
    collect layout (var#result) (cmdset)
    
    * nicer column header
    collect label levels cmdset 1 "Summary"
    
    collect preview
    
    * hide result levels in row headers
    collect style header result, level(hide)
    
    collect preview
    
    * make the sample size last
    collect style autolevels var price mpg rep78 _N, clear
    
    collect preview
    Here is the resulting table.
    Code:
    ------------------------------
                         Summary  
    ------------------------------
    Price                6,165.257
                       (2,949.496)
    Mileage (mpg)           21.297
                           (5.786)
    Repair record 1978       3.406
                           (0.990)
    N                           74
    ------------------------------

    Comment


    • #3
      Jeff Pitblado (StataCorp) Thank you so much!

      Comment

      Working...
      X