Announcement

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

  • Write an eclass program that only returns a vector of p-values

    I cross posted this to StackOverflow yesterday. http://stackoverflow.com/questions/4...or-of-p-values

    I want to write my own eclass program to work with eststo and esttab from SSC's esttab.

    I want to write a wrapper for ranksum so that I can get the p-values and add them to a table alongside the p-values from t-tests. From the ereturn help file it seems like I need to return a b matrix to comply with eclass, but I can't figure out how.

    I commented the bad calls below. Making the table with means and t-tests is no problem (i.e., first 3 columns). But my Wilcoxon3 command gives an error. I have tried with and without returning b, but I can't figure out the error, which is invalid syntax.

    I am OK with any solution that puts the ranksum p-values into an e() container.

    Code:
    capture program drop Wilcoxon3
    program define Wilcoxon3, eclass 
        version 13
    
        syntax varlist [if] [in], by(varname)
        marksample touse
    
        local names
        foreach v of varlist `varlist' {
            ranksum `v' if `touse', by(`by')
            matrix b = nullmat(b), 1
            matrix p = nullmat(p), 2*normprob(-abs(r(z)))
            local names `names' "`v'"
    
        }
        matrix colnames p = `names'
    
        // store results 
        ereturn post b
        ereturn matrix p
    
    end
    
    sysuse auto, clear
    eststo clear
    
    /* store means and t-tests */
    estpost summarize price weight if !foreign
    eststo
    
    estpost summarize price weight if foreign
    eststo
    
    estpost ttest price weight, by(foreign)
    eststo
    
    /* /1* try to store rank-sum test *1/ */
    /* Wilcoxon3 price weight, by(foreign) */
    /* eststo */
    
    
    /* table of means and t-tests */
    esttab, cells("mean(pattern(1 0 0) fmt(3) label(!Foreign)) mean(pattern(0 1 0) fmt(3) label(Foreign)) p(star pattern(0 0 1) fmt(3) label(p))")
    
    /* /1* try table of means, t-tests, and rank-sum tests *1/ */
    /* esttab, cells("mean(pattern(1 0 0 0) fmt(3) label(!Foreign)) mean(pattern(0 1 0 0) fmt(3) label(Foreign)) p(star pattern(0 0 1 0) fmt(3) label(p)) p(star pattern(0 0 0 1) fmt(3) label(p))") */

  • #2
    If you run this with trace set on, you will see that your program breaks with the statement -ereturn matrix p-, which is indeed a syntax error. See -help ereturn-. If you change it to, say, -ereturn matrix p_values = p-, you will get a matrix e(p_values) returned in e(), and no error messages.

    Comment


    • #3
      That does it. Just needed to re-read the documentation and not apply the `ereturn post` syntax to `ereturn matrix`.

      Thanks for the pointer to `trace`. I didn't know about this and see why it isn't on by default.

      Comment

      Working...
      X