Announcement

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

  • Table of summary statistics - count per category using esttab

    Hi all,

    I have created a table reporting the mean and SE across treatments for two variables.

    I would like to include the number of observations per treatment in the last row.

    I am aware of the obslast command for the esttab command, however, this does not seem to report per category?

    If anyone can pick up my error regarding this, I would greatly appreciate any hints.

    ------------------------------------------------------------------------
    Control Social Environmen~l Soc*Env
    ------------------------------------------------------------------------
    Stated WTP for OE 57.71 65.09 64.50 7.0.08
    (32.69) (38.11) (45.86) (38.29)

    Stated WTP for DC 11.29 12.63 12.17 22.55
    (29.13) (32.59) (29.21) (36.27)
    ------------------------------------------------------------------------
    Observations 362 (this is total) I need per category X X X
    ------------------------------------------------------------------------



    Here is my command

    Code:
    est clear
    estpost tabstat P_OE P_DC, by(Treatment_Group) ///
    c(stat) stat(mean sd count) nototal
     
     ereturn list
    esttab, main(mean %8.2fc) aux(sd  %8.2fc) nostar nonumber unstack ///
       nonote label ///
       collabels(none) ///
       eqlabels("Control" "Social" "Environmental" "Soc*Env") ///
       nomtitles
      
      
       esttab using "table1.tex", replace ///
      main(mean %8.2fc) aux(sd %8.2fc) nostar nonumber unstack ///
       compress nonote gap label booktabs   ///
       collabels(none) ///
       eqlabels("Control" "Social" "Environmental" "Soc*Env") ///  
       nomtitles
    an here is some sample data

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input int(P_OE P_DC) byte Treatment_Group
    10  0 1
    10  0 3
     2  0 2
    25  0 4
    11  0 1
    15  0 3
    15  0 2
    25  0 4
    15  0 1
    20  0 3
    15  0 2
    25  0 4
    20 49 1
    20  0 3
    20  0 2
    20  0 1
    30  0 4
    20  0 3
    20  0 2
    25  0 1
    20  0 3
    25  0 2
    30 59 4
    25  0 1
    20  0 3
    25  0 2
    30  0 4
    25  0 1
    22  0 3
    25  0 2
    25  0 1
    35  0 4
    22  0 3
    25  0 2
    30  0 1
    35  0 4
    24  0 3
    30  0 2
    30  0 1
    25  0 3
    30  0 2
    35  0 4
    30  0 1
    25  0 3
    30  0 2
    35  0 4
    30  0 1
    25  0 3
    30  0 2
    30  0 1
    35  0 4
    30  0 3
    35  0 2
    30  0 1
    40  0 4
    30  0 3
    35  0 2
    30  0 1
    30  0 3
    40  0 4
    35  0 2
    30  0 1
    30  0 3
    35  0 2
    32  0 1
    40  0 4
    30  0 3
    35  0 2
    35  0 1
    40  0 4
    30  0 3
    35  0 1
    35  0 2
    40 39 4
    32  0 3
    35  0 1
    35  0 2
    33  0 3
    40 59 4
    35  0 1
    40  0 2
    33 39 3
    35  0 1
    40  0 2
    40 89 4
    35  0 3
    35  0 1
    40  0 2
    40  0 4
    35  0 1
    35 69 3
    40  0 2
    45  0 4
    35  0 1
    35  0 3
    40  0 2
    35  0 1
    45 39 4
    35  0 3
    40  0 2
    end
    label values Treatment_Group Treatment_labels
    label def Treatment_labels 1 "1. Control", modify
    label def Treatment_labels 2 "2. SOC", modify
    label def Treatment_labels 3 "3. ENV", modify
    label def Treatment_labels 4 "4. SOC*ENV", modify

  • #2
    estout is from SSC, as you are asked to explain (FAQ Advice #12). You need to do a tabulation for each category separately.

    Code:
    est clear
    levelsof Treatment_Group, local(tgs)
    local i 0
    foreach g of local tgs{
        local ++i
        eststo m`i': estpost tabstat P_OE P_DC if Treatment_Group==`g', ///
        by(Treatment_Group) c(stat) stat(mean sd count) nototal
    }
    esttab m*, main(mean %8.2fc) aux(sd  %8.2fc) nostar nonumber unstack ///
       nonote label ///
       collabels(none) ///
       eqlabels("Control" "Social" "Environmental" "Soc*Env") ///
       nomtitles
    Res.:

    Code:
    . esttab m*, main(mean %8.2fc) aux(sd  %8.2fc) nostar nonumber unstack ///
    >    nonote label ///
    >    collabels(none) ///
    >    eqlabels("Control" "Social" "Environmental" "Soc*Env") ///
    >    nomtitles
    
    ------------------------------------------------------------------------
                              Control       Social Environmen~l      Soc*Env
    ------------------------------------------------------------------------
    P_OE                        28.26        29.88        26.38        35.71
                               (7.42)       (9.61)       (6.77)       (6.18)
    
    P_DC                         1.81         0.00         4.15        13.57
                               (9.43)       (0.00)      (15.28)      (26.51)
    ------------------------------------------------------------------------
    Observations                   27           26           26           21
    ------------------------------------------------------------------------

    Comment


    • #3
      Hi Andrew,

      this is brilliant! Thank you so much.

      One last question, I now have a problem when inserting the (esttab using "TESTING.docx") command.
      Would you happen to know why this is? Does it have something to do with m*?

      Thanks

      Comment


      • #4
        esttab does not support the .docx format. Save the file as an rtf file which you can open in MS Word.

        Code:
        esttab m* using TESTING.rtf, main(mean %8.2fc) aux(sd %8.2fc) ///
            nostar nonumber unstack nonote label collabels(none) ///
            eqlabels("Control" "Social" "Environmental" "Soc*Env") ///
            nomtitles replace

        Comment

        Working...
        X