Announcement

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

  • Help with combining Tabstat and ttest by using esttab

    Hi everyone,
    I'm here to ask your help as I'm having a hard time replicating the following table: https://i.imgur.com/AbDL7IR.png

    In order to do so, I thought about storing a tabstat and a ttest command:

    Code:
    ​sysuse auto, clear
    eststo a: quietly estpost tabstat price - gear_ratio, stat(count mean sd p25 median p75) columns(stat)
    eststo diff: quietly estpost ttest price - gear_ratio, by(foreign) unequal
    esttab a diff, cells("count (pattern(1 0) fmt(0)) mean(pattern(1 0) fmt(2)) sd(pattern(1 0)fmt(2)) p25(pattern(1 0) fmt(2)) p50(pattern(1 0)fmt(2)) p75(pattern(1 0) fmt(2)) b( pattern(0 1)fmt(2))" p(par pattern(0 1)fmt(2))) ///
    nonumbers noobs
    But as you can see, the result is not really the same. I can manage to place the tabstat statistics and the mean difference of the t-test on the same line, but as I try to add the p-value beneath the mean difference (and ONLY beneath it, not under the other stats) the lines get messed up. Substantially, my question is: is there a way to work with cells() in such a way I can place p-values under only a column's value?

    Thank you in advance.

  • #2
    I forgot about posting the current table:
    Code:
    sysuse auto, clear
    
    eststo a: quietly estpost tabstat price - gear_ratio, stat(count mean sd p25 median p75) columns(stat)
    
    eststo diff: quietly estpost ttest price - gear_ratio, by(foreign) unequal
    
    esttab a diff, cells("count (pattern(1 0) fmt(0)) mean(pattern(1 0) fmt(2)) sd(pattern(1 0)fmt(2)) p25(pattern(1 0) fmt(2)) p50(pattern(1 0)fmt(2)) p75(pattern(1 0) fmt(2)) b( pattern(0 1)fmt(2))" p(par pattern(0 1)fmt(2))) ///
    nonumbers noobs
    
                     
    
    
                                                                                                       
                      count/p         mean           sd          p25          p50          p75      count/p            b
    --------------------------------------------------------------------------------------------------------------------
    price                  74      6165.26      2949.50      4195.00      5006.50      6342.00                   -312.26
                                                                                                     (0.66)             
    mpg                    74        21.30         5.79        18.00        20.00        25.00                     -4.95
                                                                                                     (0.00)             
    rep78                  69         3.41         0.99         3.00         3.00         4.00                     -1.26
                                                                                                     (0.00)             
    headroom               74         2.99         0.85         2.50         3.00         3.50                      0.54
                                                                                                     (0.00)             
    trunk                  74        13.76         4.28        10.00        14.00        17.00                      3.34
                                                                                                     (0.00)             
    weight                 74      3019.46       777.19      2240.00      3190.00      3600.00                   1001.21
                                                                                                     (0.00)             
    length                 74       187.93        22.27       170.00       192.50       204.00                     27.59
                                                                                                     (0.00)             
    turn                   74        39.65         4.40        36.00        40.00        43.00                      6.03
                                                                                                     (0.00)             
    displacement           74       197.30        91.84       119.00       196.00       250.00                    122.48
                                                                                                     (0.00)             
    gear_ratio             74         3.01         0.46         2.73         2.96         3.37                     -0.70
                                                                                                     (0.00)             
    --------------------------------------------------------------------------------------------------------------------

    Comment

    Working...
    X