Announcement

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

  • (?ssc esttab?) table of nonparametric test results

    Hi,

    I'm trying to create a table of non-parametric test results (p-values). It seems like esttab/eststo need estimates stored and refuse to simply build a table of a few statistics:

    Code:
    sysuse auto
    
    ksmirnov gear_ratio, by(foreign)
    eststo pooled, noe add(ks r(p))
    ranksum gear_ratio, by(foreign)
    eststo pooled, noe add(rs r(p))
    
    esttab, stat(ks rs)
    Results:

    Code:
    . sysuse auto
    (1978 automobile data)
    
    .
    .
    .
    . ksmirnov gear_ratio, by(foreign)
    
    Two-sample Kolmogorov–Smirnov test for equality of distribution functions
    
    Smaller group             D     p-value  
    ---------------------------------------
    Domestic             0.7308       0.000
    Foreign              0.0000       1.000
    Combined K-S         0.7308       0.000
    
    Note: Ties exist in combined dataset;
          there are 36 unique values out of 74 observations.
    
    .
    . eststo pooled, noe add(ks r(p))
    (e(ks) = 1.350e-07 added)
    last estimates not found
    r(301);
    
    .
    . ranksum gear_ratio, by(foreign)
    
    Two-sample Wilcoxon rank-sum (Mann–Whitney) test
    
         foreign |      Obs    Rank sum    Expected
    -------------+---------------------------------
        Domestic |       52        1453        1950
         Foreign |       22        1322         825
    -------------+---------------------------------
        Combined |       74        2775        2775
    
    Unadjusted variance     7150.00
    Adjustment for ties      -31.87
                         ----------
    Adjusted variance       7118.13
    
    H0: gear_r~o(foreign==Domestic) = gear_r~o(foreign==Foreign)
             z = -5.891
    Prob > |z| = 0.0000
    Exact prob = 0.0000
    
    .
    . eststo pooled, noe add(rs r(p))
    (e(rs) = 3.844e-09 added)
    last estimates not found
    r(301);
    I'm guessing there's likely an easier way to do this. Would someone mind pointing me in a better direction?

    Thanks so much!

    Lucas

  • #2
    Using eststo, you transfer some statistics to existing estimates stored in e(). However, ksmirnov and ranksum are r-class commands, so they do not save any results in e(). One approach is to create a matrix of your results and output it with esttab.

    Code:
    sysuse auto, clear
    ksmirnov gear_ratio, by(foreign)
    mat res= r(p)
    ranksum gear_ratio, by(foreign)
    mat res= (res, r(p))'
    mat rownames res= "Kolmogorov-Smirnov" "Wilcoxon rank-sum"
    esttab mat(res),  collab(none) mlab(p-value, lhs(Test)) varwidth(20)
    esttab mat(res, fmt(3)),  collab(none) mlab(p-value, lhs(Test)) varwidth(20)
    esttab mat(res, fmt(3)),  collab(none) mlab(p-value, lhs(Test)) varwidth(20) substitute(0.000 "<0.001")
    Res.:

    Code:
    . esttab mat(res),  collab(none) mlab(p-value, lhs(Test)) varwidth(20)
    
    ---------------------------------
    Test                      p-value
    ---------------------------------
    Kolmogorov-Smirnov       1.35e-07
    Wilcoxon rank-sum        3.84e-09
    ---------------------------------
    
    .
    . esttab mat(res, fmt(3)),  collab(none) mlab(p-value, lhs(Test)) varwidth(20)
    
    ---------------------------------
    Test                      p-value
    ---------------------------------
    Kolmogorov-Smirnov          0.000
    Wilcoxon rank-sum           0.000
    ---------------------------------
    
    .
    . esttab mat(res, fmt(3)),  collab(none) mlab(p-value, lhs(Test)) varwidth(20) substitute(0.000 "<0.001")
    
    ---------------------------------
    Test                      p-value
    ---------------------------------
    Kolmogorov-Smirnov          <0.001
    Wilcoxon rank-sum           <0.001
    ---------------------------------

    Comment

    Working...
    X