Announcement

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

  • esttab summary statistics table with sample sizes for by() subgroups

    I am trying to create a summary statistics table using esttab that includes the sample size when using the by() option. I can't find a way to include the sample size for each by() subgroup. I can only get the total observations listed at the bottom of the table. Is there a way to get the sample size for each subgroup to show in a table?


    This is my current code:

    estpost tabstat $cont if age>=18, by(raceth) statistics(mean sd) columns(statistics)

    eststo sumstat2

    esttab sumstat2 using "H:\Thesis_data\Tables_Figures\Table1.rtf", append compress cells(mean(label(Mean) fmt(2)) sd(label(SD) fmt(2) par)) label varwidth(30) unstack title(Table 2: Summary Statistics by Race/Ethnicity) nonumber

    And it gives me this output:
    Table 2: Summary Statistics by Race/Ethnicity
    NH White NH Black Hispanic NH AI/AN NH Other Total
    Mean/SD Mean/SD Mean/SD Mean/SD Mean/SD Mean/SD
    Age 37.60 35.02 34.34 36.39 35.70 35.85
    (11.22) (9.80) (10.05) (10.58) (10.63) (10.50)
    Male 0.75 0.82 0.80 0.74 0.75 0.79
    (0.43) (0.39) (0.40) (0.44) (0.43) (0.41)
    US Citizen 0.99 0.99 0.71 1.00 0.89 0.93
    (0.08) (0.12) (0.45) (0.00) (0.32) (0.25)
    Veteran 0.14 0.08 0.03 0.12 0.11 0.09
    (0.35) (0.26) (0.17) (0.33) (0.31) (0.29)
    Any Mental Health Diagnosis 1.61 1.80 1.81 1.71 1.65 1.73
    (0.49) (0.40) (0.39) (0.45) (0.48) (0.45)
    Number of MH Dx 0.83 0.40 0.37 0.64 0.80 0.57
    (1.32) (0.99) (0.93) (1.24) (1.38) (1.15)
    Any History of Treatment 0.98 0.98 0.98 1.00 0.98 0.98
    (0.13) (0.15) (0.14) (0.00) (0.14) (0.14)
    HX of Comorbidity 0.75 0.69 0.67 0.76 0.75 0.71
    (0.43) (0.46) (0.47) (0.43) (0.43) (0.45)
    Number of HX Comorbid 1.56 1.24 1.14 1.64 1.58 1.36
    (1.50) (1.32) (1.35) (1.65) (1.64) (1.42)
    Current Comorbidity 1.00 1.00 1.00 1.00 1.00 1.00
    (0.00) (0.00) (0.00) (0.00) (0.00) (0.00)
    Current Number Comorbid 1.68 1.55 1.60 1.67 1.74 1.62
    (0.98) (0.90) (0.99) (1.08) (1.06) (0.96)
    Any Substance Use Disorder 0.80 0.74 0.75 0.78 0.77 0.76
    (0.40) (0.44) (0.43) (0.41) (0.42) (0.42)
    Any drug use 0.84 0.82 0.75 0.87 0.77 0.81
    (0.37) (0.38) (0.44) (0.34) (0.42) (0.39)
    Phone calls from friends/family 0.87 0.88 0.79 0.90 0.87 0.86
    (0.33) (0.32) (0.41) (0.30) (0.34) (0.35)
    Number of phone calls in last week 2.35 2.46 2.19 1.68 2.53 2.36
    (4.59) (4.58) (3.81) (3.06) (5.27) (4.48)
    Had visits in past month 0.34 0.27 0.29 0.25 0.29 0.30
    (0.47) (0.45) (0.46) (0.44) (0.45) (0.46)
    Number of visits in last month 2.59 2.42 2.38 2.33 2.73 2.49
    (2.52) (2.63) (2.39) (1.71) (3.91) (2.61)
    Total hours spent in cell last 24hrs 23.45 23.47 23.38 23.49 23.32 23.44
    (2.85) (2.85) (3.02) (2.74) (3.20) (2.90)
    Hx of Any Abuse 0.76 0.67 0.55 0.76 0.73 0.68
    (0.42) (0.47) (0.50) (0.43) (0.44) (0.47)
    Has work assignment 0.72 0.73 0.67 0.73 0.71 0.71
    (0.45) (0.44) (0.47) (0.44) (0.46) (0.45)
    Less than High School 0.21 0.39 0.47 0.30 0.28 0.34
    (0.41) (0.49) (0.50) (0.46) (0.45) (0.47)
    High School/GED 0.57 0.47 0.39 0.58 0.50 0.50
    (0.49) (0.50) (0.49) (0.49) (0.50) (0.50)
    Some College 0.17 0.11 0.09 0.11 0.16 0.13
    (0.38) (0.31) (0.28) (0.31) (0.37) (0.33)
    College or Higher 0.04 0.03 0.05 0.01 0.05 0.04
    (0.20) (0.16) (0.22) (0.12) (0.23) (0.19)
    Married 0.19 0.15 0.25 0.15 0.21 0.19
    (0.39) (0.36) (0.43) (0.36) (0.41) (0.39)
    Widowed 0.03 0.02 0.02 0.03 0.03 0.02
    (0.17) (0.13) (0.15) (0.18) (0.17) (0.15)
    Divorced 0.32 0.11 0.16 0.25 0.21 0.20
    (0.47) (0.32) (0.36) (0.44) (0.41) (0.40)
    Separated 0.05 0.05 0.08 0.08 0.06 0.06
    (0.22) (0.22) (0.27) (0.28) (0.23) (0.23)
    Single 0.40 0.67 0.49 0.48 0.49 0.53
    (0.49) (0.47) (0.50) (0.50) (0.50) (0.50)
    Facility Type 1.83 1.80 1.74 1.70 1.78 1.80
    (0.37) (0.40) (0.44) (0.46) (0.41) (0.40)
    Violent Offense 0.45 0.47 0.40 0.60 0.52 0.45
    (0.50) (0.50) (0.49) (0.49) (0.50) (0.50)
    Property Offense 0.30 0.21 0.25 0.16 0.24 0.25
    (0.46) (0.41) (0.43) (0.37) (0.43) (0.43)
    Drug Offense 0.21 0.29 0.30 0.16 0.20 0.26
    (0.40) (0.45) (0.46) (0.37) (0.40) (0.44)
    Public Order Offense 0.05 0.04 0.05 0.08 0.03 0.05
    (0.22) (0.19) (0.23) (0.27) (0.18) (0.21)
    Specialty Facility 0.05 0.04 0.03 0.03 0.04 0.04
    (0.22) (0.20) (0.16) (0.17) (0.19) (0.20)
    Months served at Date of Interview 52.53 59.29 46.81 53.81 52.34 54.15
    (63.76) (63.91) (53.52) (63.79) (56.91) (61.91)
    Observations 18147


  • #2
    Welcome to Statlist.

    I think the following example is the best one can do with estpost tabstat.
    Code:
    clear all
    sysuse auto
    estpost tabstat weight length rep78, by(foreign) statistics(mean sd n) columns(statistics)
    eststo cars
    esttab cars, 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)))
    Code:
    Cars
    ---------------------------------------------------------------------
                                                                        
                                       Domestic      Foreign        Total
                                      Mean/SD/N    Mean/SD/N    Mean/SD/N
    ---------------------------------------------------------------------
    Weight (lbs.)                       3317.12      2315.91      3019.46
                                       (695.36)     (433.00)     (777.19)
                                             52           22           74
    Length (in.)                         196.13       168.55       187.93
                                        (20.05)      (13.68)      (22.27)
                                             52           22           74
    Repair Record 1978                     3.02         4.29         3.41
                                         (0.84)       (0.72)       (0.99)
                                             48           21           69
    ---------------------------------------------------------------------
    The problem is that, because tabstat does not necessarily do casewise deletion for missing values, the variables need not have the same value for N within a by-group, as this example demonstrates. So instead of a single N row at bottom of the table, there is one N row for each variable.

    Comment

    Working...
    X