Announcement

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

  • Adding overall stats while using esttab after estpost ttest

    Hi,

    I'm currently using the following code:
    Code:
    est clear
    
    global vars X
    
    estpost ttest $vars, by(gender)
            
    esttab using "$output/table.tex", replace ///
        cells("mu_1(fmt(2)) mu_2  b(star)") ///
        collabels("Boys" "Girls" "Diff." ) ///
        star(* 0.10 ** 0.05 *** 0.01) ///
        label booktabs nonum gaps noobs compress ///
    I get a table in Latex format with 3 columns: "Boys", "Girls" and "Diff.", which report the mean of my X variables and the difference between boys and girls.

    I was wondering if it was possible to get, in addition to these 3 columns, an additional one "Overall", in which would be reported the mean of my X variables for the overall sample (girls and boys).

    Thanks,

  • #2
    Provide a reproducible example. estout is from SSC (FAQ Advice #12).

    Comment


    • #3
      Sorry about the incomplete post.

      I’m using estout from SSC in Stata 15.1. Here is my code for a reproducible example:
      Code:
      sysuse auto
      dataex make price mpg rep78 in 1/5
      
      est clear
      global vars price mpg 
          
      estpost ttest $vars, by(foreign)
                  
      esttab using "test.tex", replace ///
      cells("mu_1(fmt(2)) mu_2  b(star)") ///
      collabels("Domestic" "Foreign" "Diff." ) ///00.0
      star(* 0.10 ** 0.05 *** 0.01) ///
      label booktabs nonum gaps noobs compress
      As the ttest command provides the variable mean for the overall sample, I was wondering if it was possible to also get it while using the esttout command (which only provides the variable mean for each subgroup (each value of the "foreign" dummy in the example).

      Comment


      • #4
        Thanks for the reproducible example. Here is some technique.

        Code:
        sysuse auto, clear
        dataex make price mpg rep78 in 1/5
        
        est clear
        global vars price mpg 
        
            
        eststo m1: estpost ttest $vars, by(foreign)
        eststo m2: estpost sum $vars
                    
        esttab m1 m2, replace ///
        cells("mean(pattern(0 1)) mu_1(pattern(1 0) fmt(2)) mu_2(pattern(1 0)) b(pattern(1 0) star)") ///
        collabels("Overall" "Domestic" "Foreign" "Diff.") star(* 0.10 ** 0.05 *** 0.01) ///
        label nonum gaps noobs compress
        You may reorder the columns.

        Res.:

        Code:
        . esttab m1 m2, replace ///
        > cells("mean(pattern(0 1)) mu_1(pattern(1 0) fmt(2)) mu_2(pattern(1 0)) b(pattern(1 0) star)") ///
        > collabels("Overall" "Domestic" "Foreign" "Diff.") star(* 0.10 ** 0.05 *** 0.01) ///
        > label nonum gaps noobs compress
        
        -----------------------------------------------------------
                                                                   
                          Domestic   Foreign     Diff.      Overall
        -----------------------------------------------------------
        Price              6072.42  6384.682 -312.2587     6165.257
        
        Mileage (mpg)        19.83  24.77273 -4.945804***   21.2973
        -----------------------------------------------------------

        Comment

        Working...
        X