Announcement

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

  • esttab to generate summary statistics by group with column for p-value on mean difference

    I am trying to build a table that displays mean (with standard deviation in row below) by treatment group followed by a column for the p-value from a t-test for difference in mean followed by a column that has the mean of the total sample (standard deviation below). My problem is I can't get the p-value to be in the same row as the mean. It ends up in a third row below the standard deviation of the variable. The following is an example of my code currently and what it produces.

    Code:
    sysuse auto, clear
    
    eststo             forn : estpost sum price mpg if foreign == 0    
    eststo             dom : estpost sum price mpg if foreign == 1
    eststo             tot : estpost sum price mpg                         
    eststo             diff : estpost ttest price mpg, by(foreign) unequal
    
                
    esttab             forn dom diff tot,  ///
                        prehead("\begin{tabular}{l*{4}{c}} \\ [-1.8ex]\hline \hline \\[-1.8ex] " ///
                        "& \multicolumn{1}{c}{Foreign} & \multicolumn{1}{c}{Domestic} &  " ///
                        "\multicolumn{1}{c}{p-value} & \multicolumn{1}{c}{Total}  \\ ") ///
                        main(mean) aux(sd) nostar unstack label booktabs nonum ///
                        collabels(none) f noobs nomtitle nogaps ///
                        cells(mean(fmt(0 3)) sd(fmt(0 3)par)  p(fmt(3)) ) ///
                        postfoot(" \hline \hline \\[-1.8ex] \end{tabular}")
    Click image for larger version

Name:	example.PNG
Views:	1
Size:	10.4 KB
ID:	1730041

    What I want is the p-values in the same row as the means. I'm aware of the ability to use quotes or in parentheses in cells to gather elements and place them in the same row. But for whatever reason when I try to do that I end with extra columns between the columns with data.

  • #2
    Thanks for the reproducible example. You want the -pattern()- suboption to address this.

    Code:
    sysuse auto, clear
    eststo forn : estpost sum price mpg if foreign == 0   
    eststo dom : estpost sum price mpg if foreign == 1
    eststo tot : estpost sum price mpg                         
    eststo diff : estpost ttest price mpg, by(foreign) unequal
    esttab forn dom diff tot, nostar unstack label nonum f noobs  nogaps ///
    cells("mean(fmt(0 3) pattern(1 1 0 1)) p(fmt(3) pattern(0 0 1 0))"  sd(fmt(0 3)par pattern(1 1 0 1) ))
    Res.:

    Code:
    . esttab forn dom diff tot, nostar unstack label nonum f noobs  nogaps ///
    > cells("mean(fmt(0 3) pattern(1 1 0 1)) p(fmt(3) pattern(0 0 1 0))"  sd(fmt(0 3)par pattern(1 1 0 1) ))
    
                                                                            
                              mean/sd      mean/sd            p      mean/sd
    ------------------------------------------------------------------------
    Price                        6072         6385        0.660         6165
                               (3097)       (2622)                    (2949)
    Mileage (mpg)              19.827       24.773        0.003       21.297
                              (4.743)      (6.611)                   (5.786)

    Comment


    • #3
      Excellent! Thanks so much! Worked perfectly.

      Comment


      • #4
        Thank you Andrew Musau, I want to create a similar summary statistic, but my standard deviation is clustered, what can I do to include clustered p-values?

        Comment


        • #5
          Originally posted by Dana Richter View Post
          I want to create a similar summary statistic, but my standard deviation is clustered, what can I do to include clustered p-values?
          Do you mean that the tests of differences in means are conducted using regressions with clustered standard errors? If so, the regressions store these statistics. Please share your commands for any code suggestions.

          Comment

          Working...
          X