Announcement

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

  • Descriptive statistics

    Hey, I hope someone could help me with this.

    I would like to get a descriptive statistic by category (race) and import it into Word. However, I do not like how the table is currently organised, as each race should form a column and other variables should be in rows. Can this be done like in a picture below?
    Code:
    . estpost tabstat W1ExcludeYP W1truantYP substance_use delinquency in_poverty W1hiqualgP W1SOCMajorP monitoring discussion W1englangYP school_disengagement W1hwndayYP W1heposs9YP W1ssclubfYP W1ssportf
    > YP IndSchool, by(W1ethgrpYP) statistics(mean sd) columns (statistics)
    
    Summary statistics: mean sd
         for variables: W1ExcludeYP W1truantYP substance_use delinquency in_poverty W1hiqualgP W1SOCMajorP monitoring discussion W1englangYP school_disengagement W1hwndayYP W1heposs9YP W1ssclubfYP W1sspor
    > tfYP IndSchool
      by categories of: W1ethgrpYP
    
      W1ethgrpYP |   e(mean)      e(sd)
    -------------+----------------------
    White        |                      
     W1ExcludeYP |  .1118524   .3152003
      W1truantYP |  .1586002   .3653216
    substance_~e |  .2177842   .5299686
     delinquency |  2.356779   .7499987
      in_poverty |  .0048318   .0693465
      W1hiqualgP |  2.264974   .9610805
     W1SOCMajorP |  2.386501   .6329816
      monitoring |  2.909013   .2967229
      discussion |   2.27758   .7624536
     W1englangYP |  1.030288   .2237949
    school_dis~t |  2.763921    .607164
      W1hwndayYP |   2.90455   1.392042
     W1heposs9YP |  2.186284   1.021123
     W1ssclubfYP |  .4179721   .4932516
     W1ssportfYP |  .5468292   .4978314
       IndSchool |  .0457603   .2089747
    -------------+----------------------
    Mixed        |                      
     W1ExcludeYP |  .1619171   .3686136
      W1truantYP |  .2069892   .4054203
    substance_~e |  .2722372   .5750176
     delinquency |  2.561111   .8756568
      in_poverty |   .008589   .0923344
      W1hiqualgP |  2.259446   1.051363
     W1SOCMajorP |  2.410458   .6483127
      monitoring |  2.859559    .361713
      discussion |  2.329139   .7797665
     W1englangYP |  1.156446   .5147502
    school_dis~t |  2.751781   .5856526
      W1hwndayYP |  2.925501   1.344592
     W1heposs9YP |  1.939511   .9566351
     W1ssclubfYP |  .4497937   .4978154
     W1ssportfYP |  .6049767   .4892363
       IndSchool |  .0184049    .134493
    -------------+----------------------
    Indian       |                      
     W1ExcludeYP |  .0502392    .218569
      W1truantYP |  .0894569   .2855542
    substance_~e |  .0384615   .2177764
     delinquency |  2.165605   .5298383
      in_poverty |  .0029441   .0542059
      W1hiqualgP |  1.997994   1.030653
     W1SOCMajorP |  2.296875   .6164166
      monitoring |  2.904692   .2988106
      discussion |  2.395747   .7378455
     W1englangYP |   2.17078   .8582632
    school_dis~t |   3.00696   .5144446
      W1hwndayYP |  3.402477   1.323279
     W1heposs9YP |  1.523422   .7016518
     W1ssclubfYP |  .4512326   .4978829
     W1ssportfYP |  .5990099   .4904026
       IndSchool |  .0078508   .0882998
    -------------+----------------------
    Pakistani    |                      
     W1ExcludeYP |  .0812721   .2734942
      W1truantYP |  .1470588   .3543731
    substance_~e |  .0406321   .2243314
     delinquency |  2.205128   .5201847
      in_poverty |  .0083074   .0908126
      W1hiqualgP |  1.610695   .9462498
     W1SOCMajorP |  2.204852   .6001153
      monitoring |  2.879139   .3399277
      discussion |  2.416287    .732529
     W1englangYP |  2.438298   .8392789
    school_dis~t |   3.00031   .5514661
      W1hwndayYP |  3.113938   1.341585
     W1heposs9YP |  1.719278   .7943795
     W1ssclubfYP |  .4632972   .4989514
     W1ssportfYP |   .625171   .4844102
       IndSchool |  .0062305   .0787283
    -------------+----------------------
    Bangladeshi  |                      
     W1ExcludeYP |   .058104   .2342985
      W1truantYP |  .1512195   .3585543
    substance_~e |  .0583832   .2757654
     delinquency |  2.209302   .5326953
      in_poverty |  .0067295    .081812
      W1hiqualgP |  1.284123   .6805107
     W1SOCMajorP |  1.973737   .6309471
      monitoring |  2.846154    .365888
      discussion |  2.281818   .7737948
     W1englangYP |  2.695712   .7973786
    school_dis~t |    2.9425   .5751406
      W1hwndayYP |  3.188707   1.354575
     W1heposs9YP |  1.755952   .8097544
     W1ssclubfYP |  .4180064   .4936282
     W1ssportfYP |  .5551664   .4973831
       IndSchool |         0          0
    -------------+----------------------
    Black Cari~n |                      
     W1ExcludeYP |  .2289803   .4205529
      W1truantYP |  .2032967   .4028205
    substance_~e |  .1992687   .4903458
     delinquency |   2.54409   .8629965
      in_poverty |  .0167785   .1285486
      W1hiqualgP |  2.240137   .9510175
     W1SOCMajorP |  2.257713   .6344715
      monitoring |    2.7537   .4627113
      discussion |  2.369318   .7626019
     W1englangYP |  1.036458   .2293066
    school_dis~t |   2.80835   .5833853
      W1hwndayYP |  2.969697   1.339458
     W1heposs9YP |  1.772563   .8304152
     W1ssclubfYP |  .5183044   .5001469
     W1ssportfYP |   .646789   .4785166
       IndSchool |  .0016779   .0409616
    -------------+----------------------
    Black Afri~n |                      
     W1ExcludeYP |  .1086957    .311565
      W1truantYP |  .1194853   .3246572
    substance_~e |  .0721649   .3075892
     delinquency |  2.353153   .7417196
      in_poverty |  .0096154   .0976638
      W1hiqualgP |  2.280788   1.213266
     W1SOCMajorP |  2.372951   .6537256
      monitoring |  2.847188   .3576861
      discussion |  2.361261   .7843426
     W1englangYP |  1.990212   .9599337
    school_dis~t |  2.978178   .5900378
      W1hwndayYP |  3.332765   1.332122
     W1heposs9YP |  1.375209   .6019447
     W1ssclubfYP |  .5626168   .4965279
     W1ssportfYP |  .6985138   .4593913
       IndSchool |  .0016026    .040032
    -------------+----------------------
    Other        |                      
     W1ExcludeYP |  .1153846   .3199592
      W1truantYP |  .1078947   .3106564
    substance_~e |  .0805195   .3326969
     delinquency |  2.301047   .6447437
      in_poverty |   .006993   .0834286
      W1hiqualgP |  2.063981   1.125469
     W1SOCMajorP |  2.394595   .6633846
      monitoring |  2.837413   .3778503
      discussion |    2.3219   .7795811
     W1englangYP |  2.050239   .9915047
    school_dis~t |   2.92094   .5647214
      W1hwndayYP |   3.25187    1.32812
     W1heposs9YP |  1.588384   .7728077
     W1ssclubfYP |  .5040431   .5006589
     W1ssportfYP |   .570122   .4958149
       IndSchool |   .037296   .1897075
    -------------+----------------------
    Total        |                      
     W1ExcludeYP |  .1130817   .3167039
      W1truantYP |  .1544715   .3614127
    substance_~e |  .1803459    .485988
     delinquency |  2.344026   .7309498
      in_poverty |   .005907   .0766322
      W1hiqualgP |  2.155957   1.006774
     W1SOCMajorP |  2.353549   .6383658
      monitoring |  2.893458   .3183876
      discussion |  2.304282   .7630238
     W1englangYP |  1.341788   .7338761
    school_dis~t |  2.815642   .6000604
      W1hwndayYP |  2.997781   1.383062
     W1heposs9YP |  2.016896   .9858111
     W1ssclubfYP |  .4360789    .495915
     W1ssportfYP |  .5679367   .4953829
       IndSchool |  .0336636   .1803675
    
    .
    .
    .
    . esttab using "EEC_table4.rtf", main(mean) aux(sd) wide label nostar title("Descriptives by Group")
    (tabulating estimates stored by eststo; specify "." to tabulate the active results)
    (output written to EEC_table4.rtf)
    Click image for larger version

Name:	picture.png
Views:	1
Size:	83.2 KB
ID:	1733096
    Last edited by Sofiya Volvakova; 07 Nov 2023, 13:06.

  • #2
    If you have Stata 18, dtable can do this. Here is an example
    using some survey data.

    Code:
    webuse nhanes2l
    
    local cvars height weight bpsystol bpdiast tcresult tgresult hdresult ///
        iron zinc copper lead 
    
    local fvars hlthstat heartatk diabetes rural agegrp highlead highbp
    
    dtable, by(race) ///
        continuous( `cvars' ) ///
        factor( `fvars', statistic(fvproportion) ) ///
        nosample
    The resulting table is
    Code:
    -----------------------------------------------------------------------------------------------
                                                                Race                               
                                      White            Black            Other            Total     
    -----------------------------------------------------------------------------------------------
    Height (cm)                  167.760 (9.648)  167.811 (9.548)  161.843 (8.833)  167.651 (9.656)
    Weight (kg)                  71.708 (15.096)  75.092 (16.929)  63.158 (13.755)  71.898 (15.356)
    Systolic blood pressure     130.582 (22.813) 133.775 (26.418) 128.755 (27.412) 130.882 (23.333)
    Diastolic blood pressure     81.403 (12.604)  84.385 (15.077)  81.345 (13.141)  81.715 (12.927)
    Serum cholesterol (mg/dL)   218.252 (49.261) 213.516 (51.474) 213.845 (41.914) 217.670 (49.387)
    Serum triglycerides (mg/dL) 147.135 (98.716) 115.904 (70.995) 142.021 (85.694) 143.896 (96.496)
    High-density lipids (mg/dL)  49.014 (13.902)  55.005 (16.690)  50.465 (13.451)  49.643 (14.312)
    Serum iron (mcg/dL)         100.234 (33.752)  92.180 (35.258) 103.190 (37.685)  99.446 (34.083)
    Serum zinc (mcg/dL)          86.761 (14.419)  84.809 (14.607)  83.429 (15.605)  86.507 (14.478)
    Serum copper (mcg/dL)       124.474 (32.057) 138.620 (34.048) 113.669 (30.078) 125.609 (32.522)
    Lead (mcg/dL)                 14.073 (5.968)   16.524 (7.309)   13.925 (6.176)   14.320 (6.166)
    Health status                                                                                  
      Excellent                            0.245            0.134            0.210            0.233
      Very good                            0.260            0.180            0.230            0.251
      Good                                 0.276            0.330            0.390            0.284
      Fair                                 0.155            0.223            0.125            0.162
      Poor                                 0.064            0.133            0.045            0.071
    Prior heart attack                                                                             
      No heart attack                      0.953            0.957            0.975            0.954
      Had heart attack                     0.047            0.043            0.025            0.046
    Diabetes status                                                                                
      Not diabetic                         0.955            0.921            0.955            0.952
      Diabetic                             0.045            0.079            0.045            0.048
    Rural                                                                                          
      Urban                                0.598            0.891            0.805            0.633
      Rural                                0.402            0.109            0.195            0.367
    Age group                                                                                      
      20–29                                0.218            0.263            0.295            0.224
      30–39                                0.156            0.165            0.160            0.157
      40–49                                0.124            0.114            0.140            0.123
      50–59                                0.125            0.129            0.110            0.125
      60–69                                0.282            0.239            0.240            0.276
      70+                                  0.097            0.089            0.055            0.095
    High lead level                                                                                
      lead<25                              0.948            0.881            0.943            0.941
      lead>=25                             0.052            0.119            0.057            0.059
    High blood pressure                                                                            
      0                                    0.587            0.502            0.565            0.577
      1                                    0.413            0.498            0.435            0.423
    -----------------------------------------------------------------------------------------------
    You can separate the statistics into 2 columns, and move the overall
    statistics to be first and labeled "Pooled".
    Code:
    * separate statistics into 2 columns
    collect composite define col1 = mean fvproportion
    collect composite define col2 = sd
    collect style autolevels result col1 col2, clear
    collect label levels result col1 "Mean/Proportion" col2 "SD"
    collect style header result[col1 col2], level(label)
    * put the totals first, and relabel to Pooled
    collect levelsof race
    collect style autolevels race .m `s(levels)', clear
    collect label levels race .m "Pooled", modify
    collect layout
    Here is the resulting table.
    Code:
    -------------------------------------------------------------------------------------------------------------------------------
                                                                                Race                                               
                                         Pooled                    White                    Black                    Other         
                                Mean/Proportion    SD    Mean/Proportion    SD    Mean/Proportion    SD    Mean/Proportion    SD   
    -------------------------------------------------------------------------------------------------------------------------------
    Height (cm)                         167.651  (9.656)         167.760  (9.648)         167.811  (9.548)         161.843  (8.833)
    Weight (kg)                          71.898 (15.356)          71.708 (15.096)          75.092 (16.929)          63.158 (13.755)
    Systolic blood pressure             130.882 (23.333)         130.582 (22.813)         133.775 (26.418)         128.755 (27.412)
    Diastolic blood pressure             81.715 (12.927)          81.403 (12.604)          84.385 (15.077)          81.345 (13.141)
    Serum cholesterol (mg/dL)           217.670 (49.387)         218.252 (49.261)         213.516 (51.474)         213.845 (41.914)
    Serum triglycerides (mg/dL)         143.896 (96.496)         147.135 (98.716)         115.904 (70.995)         142.021 (85.694)
    High-density lipids (mg/dL)          49.643 (14.312)          49.014 (13.902)          55.005 (16.690)          50.465 (13.451)
    Serum iron (mcg/dL)                  99.446 (34.083)         100.234 (33.752)          92.180 (35.258)         103.190 (37.685)
    Serum zinc (mcg/dL)                  86.507 (14.478)          86.761 (14.419)          84.809 (14.607)          83.429 (15.605)
    Serum copper (mcg/dL)               125.609 (32.522)         124.474 (32.057)         138.620 (34.048)         113.669 (30.078)
    Lead (mcg/dL)                        14.320  (6.166)          14.073  (5.968)          16.524  (7.309)          13.925  (6.176)
    Health status                                                                                                                  
      Excellent                           0.233                    0.245                    0.134                    0.210         
      Very good                           0.251                    0.260                    0.180                    0.230         
      Good                                0.284                    0.276                    0.330                    0.390         
      Fair                                0.162                    0.155                    0.223                    0.125         
      Poor                                0.071                    0.064                    0.133                    0.045         
    Prior heart attack                                                                                                             
      No heart attack                     0.954                    0.953                    0.957                    0.975         
      Had heart attack                    0.046                    0.047                    0.043                    0.025         
    Diabetes status                                                                                                                
      Not diabetic                        0.952                    0.955                    0.921                    0.955         
      Diabetic                            0.048                    0.045                    0.079                    0.045         
    Rural                                                                                                                          
      Urban                               0.633                    0.598                    0.891                    0.805         
      Rural                               0.367                    0.402                    0.109                    0.195         
    Age group                                                                                                                      
      20–29                               0.224                    0.218                    0.263                    0.295         
      30–39                               0.157                    0.156                    0.165                    0.160         
      40–49                               0.123                    0.124                    0.114                    0.140         
      50–59                               0.125                    0.125                    0.129                    0.110         
      60–69                               0.276                    0.282                    0.239                    0.240         
      70+                                 0.095                    0.097                    0.089                    0.055         
    High lead level                                                                                                                
      lead<25                             0.941                    0.948                    0.881                    0.943         
      lead>=25                            0.059                    0.052                    0.119                    0.057         
    High blood pressure                                                                                                            
      0                                   0.577                    0.587                    0.502                    0.565         
      1                                   0.423                    0.413                    0.498                    0.435         
    -------------------------------------------------------------------------------------------------------------------------------
    Here is how to add super header "Depenedent variables" to the continuous
    variables.
    Code:
    * add a super header for the continuous variables
    collect addtags vartype["Dependent variables"], ///
        fortags(var[ `cvars' ])
    collect addtags vartype[_hide], ///
        fortags(var[ `fvars' ])
    collect layout (vartype#var) (race#result)
    Resulting in this table.
    Code:
    ---------------------------------------------------------------------------------------------------------------------------------
                                                                                  Race                                               
                                           Pooled                    White                    Black                    Other         
                                  Mean/Proportion    SD    Mean/Proportion    SD    Mean/Proportion    SD    Mean/Proportion    SD   
    ---------------------------------------------------------------------------------------------------------------------------------
    Dependent variables                                                                                                              
      Height (cm)                         167.651  (9.656)         167.760  (9.648)         167.811  (9.548)         161.843  (8.833)
      Weight (kg)                          71.898 (15.356)          71.708 (15.096)          75.092 (16.929)          63.158 (13.755)
      Systolic blood pressure             130.882 (23.333)         130.582 (22.813)         133.775 (26.418)         128.755 (27.412)
      Diastolic blood pressure             81.715 (12.927)          81.403 (12.604)          84.385 (15.077)          81.345 (13.141)
      Serum cholesterol (mg/dL)           217.670 (49.387)         218.252 (49.261)         213.516 (51.474)         213.845 (41.914)
      Serum triglycerides (mg/dL)         143.896 (96.496)         147.135 (98.716)         115.904 (70.995)         142.021 (85.694)
      High-density lipids (mg/dL)          49.643 (14.312)          49.014 (13.902)          55.005 (16.690)          50.465 (13.451)
      Serum iron (mcg/dL)                  99.446 (34.083)         100.234 (33.752)          92.180 (35.258)         103.190 (37.685)
      Serum zinc (mcg/dL)                  86.507 (14.478)          86.761 (14.419)          84.809 (14.607)          83.429 (15.605)
      Serum copper (mcg/dL)               125.609 (32.522)         124.474 (32.057)         138.620 (34.048)         113.669 (30.078)
      Lead (mcg/dL)                        14.320  (6.166)          14.073  (5.968)          16.524  (7.309)          13.925  (6.176)
    Health status                                                                                                                    
      Excellent                             0.233                    0.245                    0.134                    0.210         
      Very good                             0.251                    0.260                    0.180                    0.230         
      Good                                  0.284                    0.276                    0.330                    0.390         
      Fair                                  0.162                    0.155                    0.223                    0.125         
      Poor                                  0.071                    0.064                    0.133                    0.045         
    Prior heart attack                                                                                                               
      No heart attack                       0.954                    0.953                    0.957                    0.975         
      Had heart attack                      0.046                    0.047                    0.043                    0.025         
    Diabetes status                                                                                                                  
      Not diabetic                          0.952                    0.955                    0.921                    0.955         
      Diabetic                              0.048                    0.045                    0.079                    0.045         
    Rural                                                                                                                            
      Urban                                 0.633                    0.598                    0.891                    0.805         
      Rural                                 0.367                    0.402                    0.109                    0.195         
    Age group                                                                                                                        
      20–29                                 0.224                    0.218                    0.263                    0.295         
      30–39                                 0.157                    0.156                    0.165                    0.160         
      40–49                                 0.123                    0.124                    0.114                    0.140         
      50–59                                 0.125                    0.125                    0.129                    0.110         
      60–69                                 0.276                    0.282                    0.239                    0.240         
      70+                                   0.095                    0.097                    0.089                    0.055         
    High lead level                                                                                                                  
      lead<25                               0.941                    0.948                    0.881                    0.943         
      lead>=25                              0.059                    0.052                    0.119                    0.057         
    High blood pressure                                                                                                              
      0                                     0.577                    0.587                    0.502                    0.565         
      1                                     0.423                    0.413                    0.498                    0.435         
    ---------------------------------------------------------------------------------------------------------------------------------
    Once you are happy with the table's style and arrangement, you can publish it
    to MS Word, MS Excel, HTML, or LaTeX with collect export.
    Code:
    collect export dtable.docx, replace
    collect export dtable.html, replace
    Here is a partial screenshot of the HTML document viewed thru my browser.
    Click image for larger version

Name:	Screenshot 2023-11-07 at 3.42.52 PM.png
Views:	1
Size:	102.1 KB
ID:	1733113

    Comment


    • #3
      Originally posted by Jeff Pitblado (StataCorp) View Post
      If you have Stata 18, dtable can do this. Here is an example
      using some survey data.

      Code:
      webuse nhanes2l
      
      local cvars height weight bpsystol bpdiast tcresult tgresult hdresult ///
      iron zinc copper lead
      
      local fvars hlthstat heartatk diabetes rural agegrp highlead highbp
      
      dtable, by(race) ///
      continuous( `cvars' ) ///
      factor( `fvars', statistic(fvproportion) ) ///
      nosample
      The resulting table is
      Code:
      -----------------------------------------------------------------------------------------------
      Race
      White Black Other Total
      -----------------------------------------------------------------------------------------------
      Height (cm) 167.760 (9.648) 167.811 (9.548) 161.843 (8.833) 167.651 (9.656)
      Weight (kg) 71.708 (15.096) 75.092 (16.929) 63.158 (13.755) 71.898 (15.356)
      Systolic blood pressure 130.582 (22.813) 133.775 (26.418) 128.755 (27.412) 130.882 (23.333)
      Diastolic blood pressure 81.403 (12.604) 84.385 (15.077) 81.345 (13.141) 81.715 (12.927)
      Serum cholesterol (mg/dL) 218.252 (49.261) 213.516 (51.474) 213.845 (41.914) 217.670 (49.387)
      Serum triglycerides (mg/dL) 147.135 (98.716) 115.904 (70.995) 142.021 (85.694) 143.896 (96.496)
      High-density lipids (mg/dL) 49.014 (13.902) 55.005 (16.690) 50.465 (13.451) 49.643 (14.312)
      Serum iron (mcg/dL) 100.234 (33.752) 92.180 (35.258) 103.190 (37.685) 99.446 (34.083)
      Serum zinc (mcg/dL) 86.761 (14.419) 84.809 (14.607) 83.429 (15.605) 86.507 (14.478)
      Serum copper (mcg/dL) 124.474 (32.057) 138.620 (34.048) 113.669 (30.078) 125.609 (32.522)
      Lead (mcg/dL) 14.073 (5.968) 16.524 (7.309) 13.925 (6.176) 14.320 (6.166)
      Health status
      Excellent 0.245 0.134 0.210 0.233
      Very good 0.260 0.180 0.230 0.251
      Good 0.276 0.330 0.390 0.284
      Fair 0.155 0.223 0.125 0.162
      Poor 0.064 0.133 0.045 0.071
      Prior heart attack
      No heart attack 0.953 0.957 0.975 0.954
      Had heart attack 0.047 0.043 0.025 0.046
      Diabetes status
      Not diabetic 0.955 0.921 0.955 0.952
      Diabetic 0.045 0.079 0.045 0.048
      Rural
      Urban 0.598 0.891 0.805 0.633
      Rural 0.402 0.109 0.195 0.367
      Age group
      20–29 0.218 0.263 0.295 0.224
      30–39 0.156 0.165 0.160 0.157
      40–49 0.124 0.114 0.140 0.123
      50–59 0.125 0.129 0.110 0.125
      60–69 0.282 0.239 0.240 0.276
      70+ 0.097 0.089 0.055 0.095
      High lead level
      lead<25 0.948 0.881 0.943 0.941
      lead>=25 0.052 0.119 0.057 0.059
      High blood pressure
      0 0.587 0.502 0.565 0.577
      1 0.413 0.498 0.435 0.423
      -----------------------------------------------------------------------------------------------
      You can separate the statistics into 2 columns, and move the overall
      statistics to be first and labeled "Pooled".
      Code:
      * separate statistics into 2 columns
      collect composite define col1 = mean fvproportion
      collect composite define col2 = sd
      collect style autolevels result col1 col2, clear
      collect label levels result col1 "Mean/Proportion" col2 "SD"
      collect style header result[col1 col2], level(label)
      * put the totals first, and relabel to Pooled
      collect levelsof race
      collect style autolevels race .m `s(levels)', clear
      collect label levels race .m "Pooled", modify
      collect layout
      Here is the resulting table.
      Code:
      -------------------------------------------------------------------------------------------------------------------------------
      Race
      Pooled White Black Other
      Mean/Proportion SD Mean/Proportion SD Mean/Proportion SD Mean/Proportion SD
      -------------------------------------------------------------------------------------------------------------------------------
      Height (cm) 167.651 (9.656) 167.760 (9.648) 167.811 (9.548) 161.843 (8.833)
      Weight (kg) 71.898 (15.356) 71.708 (15.096) 75.092 (16.929) 63.158 (13.755)
      Systolic blood pressure 130.882 (23.333) 130.582 (22.813) 133.775 (26.418) 128.755 (27.412)
      Diastolic blood pressure 81.715 (12.927) 81.403 (12.604) 84.385 (15.077) 81.345 (13.141)
      Serum cholesterol (mg/dL) 217.670 (49.387) 218.252 (49.261) 213.516 (51.474) 213.845 (41.914)
      Serum triglycerides (mg/dL) 143.896 (96.496) 147.135 (98.716) 115.904 (70.995) 142.021 (85.694)
      High-density lipids (mg/dL) 49.643 (14.312) 49.014 (13.902) 55.005 (16.690) 50.465 (13.451)
      Serum iron (mcg/dL) 99.446 (34.083) 100.234 (33.752) 92.180 (35.258) 103.190 (37.685)
      Serum zinc (mcg/dL) 86.507 (14.478) 86.761 (14.419) 84.809 (14.607) 83.429 (15.605)
      Serum copper (mcg/dL) 125.609 (32.522) 124.474 (32.057) 138.620 (34.048) 113.669 (30.078)
      Lead (mcg/dL) 14.320 (6.166) 14.073 (5.968) 16.524 (7.309) 13.925 (6.176)
      Health status
      Excellent 0.233 0.245 0.134 0.210
      Very good 0.251 0.260 0.180 0.230
      Good 0.284 0.276 0.330 0.390
      Fair 0.162 0.155 0.223 0.125
      Poor 0.071 0.064 0.133 0.045
      Prior heart attack
      No heart attack 0.954 0.953 0.957 0.975
      Had heart attack 0.046 0.047 0.043 0.025
      Diabetes status
      Not diabetic 0.952 0.955 0.921 0.955
      Diabetic 0.048 0.045 0.079 0.045
      Rural
      Urban 0.633 0.598 0.891 0.805
      Rural 0.367 0.402 0.109 0.195
      Age group
      20–29 0.224 0.218 0.263 0.295
      30–39 0.157 0.156 0.165 0.160
      40–49 0.123 0.124 0.114 0.140
      50–59 0.125 0.125 0.129 0.110
      60–69 0.276 0.282 0.239 0.240
      70+ 0.095 0.097 0.089 0.055
      High lead level
      lead<25 0.941 0.948 0.881 0.943
      lead>=25 0.059 0.052 0.119 0.057
      High blood pressure
      0 0.577 0.587 0.502 0.565
      1 0.423 0.413 0.498 0.435
      -------------------------------------------------------------------------------------------------------------------------------
      Here is how to add super header "Depenedent variables" to the continuous
      variables.
      Code:
      * add a super header for the continuous variables
      collect addtags vartype["Dependent variables"], ///
      fortags(var[ `cvars' ])
      collect addtags vartype[_hide], ///
      fortags(var[ `fvars' ])
      collect layout (vartype#var) (race#result)
      Resulting in this table.
      Code:
      ---------------------------------------------------------------------------------------------------------------------------------
      Race
      Pooled White Black Other
      Mean/Proportion SD Mean/Proportion SD Mean/Proportion SD Mean/Proportion SD
      ---------------------------------------------------------------------------------------------------------------------------------
      Dependent variables
      Height (cm) 167.651 (9.656) 167.760 (9.648) 167.811 (9.548) 161.843 (8.833)
      Weight (kg) 71.898 (15.356) 71.708 (15.096) 75.092 (16.929) 63.158 (13.755)
      Systolic blood pressure 130.882 (23.333) 130.582 (22.813) 133.775 (26.418) 128.755 (27.412)
      Diastolic blood pressure 81.715 (12.927) 81.403 (12.604) 84.385 (15.077) 81.345 (13.141)
      Serum cholesterol (mg/dL) 217.670 (49.387) 218.252 (49.261) 213.516 (51.474) 213.845 (41.914)
      Serum triglycerides (mg/dL) 143.896 (96.496) 147.135 (98.716) 115.904 (70.995) 142.021 (85.694)
      High-density lipids (mg/dL) 49.643 (14.312) 49.014 (13.902) 55.005 (16.690) 50.465 (13.451)
      Serum iron (mcg/dL) 99.446 (34.083) 100.234 (33.752) 92.180 (35.258) 103.190 (37.685)
      Serum zinc (mcg/dL) 86.507 (14.478) 86.761 (14.419) 84.809 (14.607) 83.429 (15.605)
      Serum copper (mcg/dL) 125.609 (32.522) 124.474 (32.057) 138.620 (34.048) 113.669 (30.078)
      Lead (mcg/dL) 14.320 (6.166) 14.073 (5.968) 16.524 (7.309) 13.925 (6.176)
      Health status
      Excellent 0.233 0.245 0.134 0.210
      Very good 0.251 0.260 0.180 0.230
      Good 0.284 0.276 0.330 0.390
      Fair 0.162 0.155 0.223 0.125
      Poor 0.071 0.064 0.133 0.045
      Prior heart attack
      No heart attack 0.954 0.953 0.957 0.975
      Had heart attack 0.046 0.047 0.043 0.025
      Diabetes status
      Not diabetic 0.952 0.955 0.921 0.955
      Diabetic 0.048 0.045 0.079 0.045
      Rural
      Urban 0.633 0.598 0.891 0.805
      Rural 0.367 0.402 0.109 0.195
      Age group
      20–29 0.224 0.218 0.263 0.295
      30–39 0.157 0.156 0.165 0.160
      40–49 0.123 0.124 0.114 0.140
      50–59 0.125 0.125 0.129 0.110
      60–69 0.276 0.282 0.239 0.240
      70+ 0.095 0.097 0.089 0.055
      High lead level
      lead<25 0.941 0.948 0.881 0.943
      lead>=25 0.059 0.052 0.119 0.057
      High blood pressure
      0 0.577 0.587 0.502 0.565
      1 0.423 0.413 0.498 0.435
      ---------------------------------------------------------------------------------------------------------------------------------
      Once you are happy with the table's style and arrangement, you can publish it
      to MS Word, MS Excel, HTML, or LaTeX with collect export.
      Code:
      collect export dtable.docx, replace
      collect export dtable.html, replace
      Here is a partial screenshot of the HTML document viewed thru my browser.
      [ATTACH=CONFIG]n1733113[/ATTACH]
      Dear Jeff, thank you! However, I am using Stata 16. Is there a solution for me, except the dtable command, which is unfortunately not available on Stata 16.0?

      Comment


      • #4
        I tried this. However, when I export it to Word, it is just blank so no values appear at all:
        Code:
        . ssc install dataex
        checking dataex consistency and verifying not already installed...
        all files already exist and are up to date.
        
        . estpost tabstat W1ExcludeYP W1truantYP substance_use delinquency in_poverty W1hiqual
        > gP W1SOCMajorP monitoring discussion W1englangYP school_disengagement W1hwndayYP W1h
        > eposs9YP W1ssclubfYP W1ssportfYP IndSchool, by(W1ethgrpYP) statistics(mean sd n) col
        > umns(statistics)
        
        Summary statistics: mean sd count
             for variables: W1ExcludeYP W1truantYP substance_use delinquency in_poverty W1hiqu
        > algP W1SOCMajorP monitoring discussion W1englangYP school_disengagement W1hwndayYP W
        > 1heposs9YP W1ssclubfYP W1ssportfYP IndSchool
          by categories of: W1ethgrpYP
        
          W1ethgrpYP |   e(mean)      e(sd)   e(count) 
        -------------+---------------------------------
        White        |                                 
         W1ExcludeYP |  .1118524   .3152003      10192 
          W1truantYP |  .1586002   .3653216       9773 
        substance_~e |  .2177842   .5299686       9739 
         delinquency |  2.356779   .7499987       9611 
          in_poverty |  .0048318   .0693465      10555 
          W1hiqualgP |  2.264974   .9610805      10318 
         W1SOCMajorP |  2.386501   .6329816      10238 
          monitoring |  2.909013   .2967229       9386 
          discussion |   2.27758   .7624536       9853 
         W1englangYP |  1.030288   .2237949      10334 
        school_dis~t |  2.763921    .607164       9105 
          W1hwndayYP |   2.90455   1.392042       9209 
         W1heposs9YP |  2.186284   1.021123       9872 
         W1ssclubfYP |  .4179721   .4932516       9448 
         W1ssportfYP |  .5468292   .4978314       8531 
           IndSchool |  .0457603   .2089747      10555 
        -------------+---------------------------------
        Mixed        |                                 
         W1ExcludeYP |  .1619171   .3686136        772 
          W1truantYP |  .2069892   .4054203        744 
        substance_~e |  .2722372   .5750176        742 
         delinquency |  2.561111   .8756568        720 
          in_poverty |   .008589   .0923344        815 
          W1hiqualgP |  2.259446   1.051363        794 
         W1SOCMajorP |  2.410458   .6483127        765 
          monitoring |  2.859559    .361713        680 
          discussion |  2.329139   .7797665        755 
         W1englangYP |  1.156446   .5147502        799 
        school_dis~t |  2.751781   .5856526        702 
          W1hwndayYP |  2.925501   1.344592        698 
         W1heposs9YP |  1.939511   .9566351        777 
         W1ssclubfYP |  .4497937   .4978154        727 
         W1ssportfYP |  .6049767   .4892363        643 
           IndSchool |  .0184049    .134493        815 
        -------------+---------------------------------
        Indian       |                                 
         W1ExcludeYP |  .0502392    .218569        836 
          W1truantYP |  .0894569   .2855542        939 
        substance_~e |  .0384615   .2177764        962 
         delinquency |  2.165605   .5298383        942 
          in_poverty |  .0029441   .0542059       1019 
          W1hiqualgP |  1.997994   1.030653        997 
         W1SOCMajorP |  2.296875   .6164166        960 
          monitoring |  2.904692   .2988106        682 
          discussion |  2.395747   .7378455        964 
         W1englangYP |   2.17078   .8582632       1013 
        school_dis~t |   3.00696   .5144446        898 
          W1hwndayYP |  3.402477   1.323279        969 
         W1heposs9YP |  1.523422   .7016518        982 
         W1ssclubfYP |  .4512326   .4978829        933 
         W1ssportfYP |  .5990099   .4904026        808 
           IndSchool |  .0078508   .0882998       1019 
        -------------+---------------------------------
        Pakistani    |                                 
         W1ExcludeYP |  .0812721   .2734942        566 
          W1truantYP |  .1470588   .3543731        850 
        substance_~e |  .0406321   .2243314        886 
         delinquency |  2.205128   .5201847        858 
          in_poverty |  .0083074   .0908126        963 
          W1hiqualgP |  1.610695   .9462498        935 
         W1SOCMajorP |  2.204852   .6001153        742 
          monitoring |  2.879139   .3399277        604 
          discussion |  2.416287    .732529        878 
         W1englangYP |  2.438298   .8392789        940 
        school_dis~t |   3.00031   .5514661        806 
          W1hwndayYP |  3.113938   1.341585        904 
         W1heposs9YP |  1.719278   .7943795        887 
         W1ssclubfYP |  .4632972   .4989514        831 
         W1ssportfYP |   .625171   .4844102        731 
           IndSchool |  .0062305   .0787283        963 
        -------------+---------------------------------
        Bangladeshi  |                                 
         W1ExcludeYP |   .058104   .2342985        327 
          W1truantYP |  .1512195   .3585543        615 
        substance_~e |  .0583832   .2757654        668 
         delinquency |  2.209302   .5326953        645 
          in_poverty |  .0067295    .081812        743 
          W1hiqualgP |  1.284123   .6805107        718 
         W1SOCMajorP |  1.973737   .6309471        495 
          monitoring |  2.846154    .365888        442 
          discussion |  2.281818   .7737948        660 
         W1englangYP |  2.695712   .7973786        723 
        school_dis~t |    2.9425   .5751406        600 
          W1hwndayYP |  3.188707   1.354575        673 
         W1heposs9YP |  1.755952   .8097544        672 
         W1ssclubfYP |  .4180064   .4936282        622 
         W1ssportfYP |  .5551664   .4973831        571 
           IndSchool |         0          0        743 
        -------------+---------------------------------
        Black Cari~n |                                 
         W1ExcludeYP |  .2289803   .4205529        559 
          W1truantYP |  .2032967   .4028205        546 
        substance_~e |  .1992687   .4903458        547 
         delinquency |   2.54409   .8629965        533 
          in_poverty |  .0167785   .1285486        596 
          W1hiqualgP |  2.240137   .9510175        583 
         W1SOCMajorP |  2.257713   .6344715        551 
          monitoring |    2.7537   .4627113        473 
          discussion |  2.369318   .7626019        528 
         W1englangYP |  1.036458   .2293066        576 
        school_dis~t |   2.80835   .5833853        497 
          W1hwndayYP |  2.969697   1.339458        528 
         W1heposs9YP |  1.772563   .8304152        554 
         W1ssclubfYP |  .5183044   .5001469        519 
         W1ssportfYP |   .646789   .4785166        436 
           IndSchool |  .0016779   .0409616        596 
        -------------+---------------------------------
        Black Afri~n |                                 
         W1ExcludeYP |  .1086957    .311565        506 
          W1truantYP |  .1194853   .3246572        544 
        substance_~e |  .0721649   .3075892        582 
         delinquency |  2.353153   .7417196        555 
          in_poverty |  .0096154   .0976638        624 
          W1hiqualgP |  2.280788   1.213266        609 
         W1SOCMajorP |  2.372951   .6537256        488 
          monitoring |  2.847188   .3576861        409 
          discussion |  2.361261   .7843426        555 
         W1englangYP |  1.990212   .9599337        613 
        school_dis~t |  2.978178   .5900378        527 
          W1hwndayYP |  3.332765   1.332122        586 
         W1heposs9YP |  1.375209   .6019447        597 
         W1ssclubfYP |  .5626168   .4965279        535 
         W1ssportfYP |  .6985138   .4593913        471 
           IndSchool |  .0016026    .040032        624 
        -------------+---------------------------------
        Other        |                                 
         W1ExcludeYP |  .1153846   .3199592        338 
          W1truantYP |  .1078947   .3106564        380 
        substance_~e |  .0805195   .3326969        385 
         delinquency |  2.301047   .6447437        382 
          in_poverty |   .006993   .0834286        429 
          W1hiqualgP |  2.063981   1.125469        422 
         W1SOCMajorP |  2.394595   .6633846        370 
          monitoring |  2.837413   .3778503        286 
          discussion |    2.3219   .7795811        379 
         W1englangYP |  2.050239   .9915047        418 
        school_dis~t |   2.92094   .5647214        351 
          W1hwndayYP |   3.25187    1.32812        401 
         W1heposs9YP |  1.588384   .7728077        396 
         W1ssclubfYP |  .5040431   .5006589        371 
         W1ssportfYP |   .570122   .4958149        328 
           IndSchool |   .037296   .1897075        429 
        -------------+---------------------------------
        Total        |                                 
         W1ExcludeYP |  .1130817   .3167039      14096 
          W1truantYP |  .1544715   .3614127      14391 
        substance_~e |  .1803459    .485988      14511 
         delinquency |  2.344026   .7309498      14246 
          in_poverty |   .005907   .0766322      15744 
          W1hiqualgP |  2.155957   1.006774      15376 
         W1SOCMajorP |  2.353549   .6383658      14609 
          monitoring |  2.893458   .3183876      12962 
          discussion |  2.304282   .7630238      14572 
         W1englangYP |  1.341788   .7338761      15416 
        school_dis~t |  2.815642   .6000604      13486 
          W1hwndayYP |  2.997781   1.383062      13968 
         W1heposs9YP |  2.016896   .9858111      14737 
         W1ssclubfYP |  .4360789    .495915      13986 
         W1ssportfYP |  .5679367   .4953829      12519 
           IndSchool |  .0336636   .1803675      15744 
        
        . 
        . eststo discipline
        
        . 
        . esttab discipline, label varwidth(30) unstack title(Cars) nonumber noobs cells(mean(
        > label(Mean) fmt(2)) sd(label(SD) fmt(2) par) count(label(N) fmt(0)))
        
        Cars
        --------------------------------------------------------------------------------------
        > -------------------------------------------------------------
                                                                                              
        >                                                              
                                              White        Mixed       Indian    Pakistani  Ba
        > ngladeshi Black Cari~n Black Afri~n        Other        Total
                                          Mean/SD/N    Mean/SD/N    Mean/SD/N    Mean/SD/N    
        > Mean/SD/N    Mean/SD/N    Mean/SD/N    Mean/SD/N    Mean/SD/N
        --------------------------------------------------------------------------------------
        > -------------------------------------------------------------
        W1ExcludeYP                            0.11         0.16         0.05         0.08    
        >      0.06         0.23         0.11         0.12         0.11
                                             (0.32)       (0.37)       (0.22)       (0.27)    
        >    (0.23)       (0.42)       (0.31)       (0.32)       (0.32)
                                              10192          772          836          566    
        >       327          559          506          338        14096
        YP: Whether played truant in~s         0.16         0.21         0.09         0.15    
        >      0.15         0.20         0.12         0.11         0.15
                                             (0.37)       (0.41)       (0.29)       (0.35)    
        >    (0.36)       (0.40)       (0.32)       (0.31)       (0.36)
                                               9773          744          939          850    
        >       615          546          544          380        14391
        substance_use                          0.22         0.27         0.04         0.04    
        >      0.06         0.20         0.07         0.08         0.18
                                             (0.53)       (0.58)       (0.22)       (0.22)    
        >    (0.28)       (0.49)       (0.31)       (0.33)       (0.49)
                                               9739          742          962          886    
        >       668          547          582          385        14511
        delinquency                            2.36         2.56         2.17         2.21    
        >      2.21         2.54         2.35         2.30         2.34
                                             (0.75)       (0.88)       (0.53)       (0.52)    
        >    (0.53)       (0.86)       (0.74)       (0.64)       (0.73)
                                               9611          720          942          858    
        >       645          533          555          382        14246
        in_poverty                             0.00         0.01         0.00         0.01    
        >      0.01         0.02         0.01         0.01         0.01
                                             (0.07)       (0.09)       (0.05)       (0.09)    
        >    (0.08)       (0.13)       (0.10)       (0.08)       (0.08)
                                              10555          815         1019          963    
        >       743          596          624          429        15744
        W1hiqualgP                             2.26         2.26         2.00         1.61    
        >      1.28         2.24         2.28         2.06         2.16
                                             (0.96)       (1.05)       (1.03)       (0.95)    
        >    (0.68)       (0.95)       (1.21)       (1.13)       (1.01)
                                              10318          794          997          935    
        >       718          583          609          422        15376
        W1SOCMajorP                            2.39         2.41         2.30         2.20    
        >      1.97         2.26         2.37         2.39         2.35
                                             (0.63)       (0.65)       (0.62)       (0.60)    
        >    (0.63)       (0.63)       (0.65)       (0.66)       (0.64)
                                              10238          765          960          742    
        >       495          551          488          370        14609
        monitoring                             2.91         2.86         2.90         2.88    
        >      2.85         2.75         2.85         2.84         2.89
                                             (0.30)       (0.36)       (0.30)       (0.34)    
        >    (0.37)       (0.46)       (0.36)       (0.38)       (0.32)
                                               9386          680          682          604    
        >       442          473          409          286        12962
        discussion                             2.28         2.33         2.40         2.42    
        >      2.28         2.37         2.36         2.32         2.30
                                             (0.76)       (0.78)       (0.74)       (0.73)    
        >    (0.77)       (0.76)       (0.78)       (0.78)       (0.76)
                                               9853          755          964          878    
        >       660          528          555          379        14572
        YP: Whether English is first~          1.03         1.16         2.17         2.44    
        >      2.70         1.04         1.99         2.05         1.34
                                             (0.22)       (0.51)       (0.86)       (0.84)    
        >    (0.80)       (0.23)       (0.96)       (0.99)       (0.73)
                                              10334          799         1013          940    
        >       723          576          613          418        15416
        school_disengagement                   2.76         2.75         3.01         3.00    
        >      2.94         2.81         2.98         2.92         2.82
                                             (0.61)       (0.59)       (0.51)       (0.55)    
        >    (0.58)       (0.58)       (0.59)       (0.56)       (0.60)
                                               9105          702          898          806    
        >       600          497          527          351        13486
        YP: Number of evenings do ho~o         2.90         2.93         3.40         3.11    
        >      3.19         2.97         3.33         3.25         3.00
                                             (1.39)       (1.34)       (1.32)       (1.34)    
        >    (1.35)       (1.34)       (1.33)       (1.33)       (1.38)
                                               9209          698          969          904    
        >       673          528          586          401        13968
        YP: Likelihood of YP applyin~o         2.19         1.94         1.52         1.72    
        >      1.76         1.77         1.38         1.59         2.02
                                             (1.02)       (0.96)       (0.70)       (0.79)    
        >    (0.81)       (0.83)       (0.60)       (0.77)       (0.99)
                                               9872          777          982          887    
        >       672          554          597          396        14737
        YP: How many times per week ~a         0.42         0.45         0.45         0.46    
        >      0.42         0.52         0.56         0.50         0.44
                                             (0.49)       (0.50)       (0.50)       (0.50)    
        >    (0.49)       (0.50)       (0.50)       (0.50)       (0.50)
                                               9448          727          933          831    
        >       622          519          535          371        13986
        YP: How many times per week ~a         0.55         0.60         0.60         0.63    
        >      0.56         0.65         0.70         0.57         0.57
                                             (0.50)       (0.49)       (0.49)       (0.48)    
        >    (0.50)       (0.48)       (0.46)       (0.50)       (0.50)
                                               8531          643          808          731    
        >       571          436          471          328        12519
        DV: Whether YP was at an ind~n         0.05         0.02         0.01         0.01    
        >      0.00         0.00         0.00         0.04         0.03
                                             (0.21)       (0.13)       (0.09)       (0.08)    
        >    (0.00)       (0.04)       (0.04)       (0.19)       (0.18)
                                              10555          815         1019          963    
        >       743          596          624          429        15744
        --------------------------------------------------------------------------------------
        > -------------------------------------------------------------
        
        . 
        . 
        . 
        . esttab discipline using name.rft, replace
        (output written to name.rft)

        Comment

        Working...
        X