0
votes

Edit: After one day I cross-posted this Statalist.

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.

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))") */
1

1 Answers

0
votes

I received an answer on Statalist here.

This was a case of RTFM. The ereturn post syntax doesn't require rename and equal sign, but ereturn matrix does. This is clear if you focus on the syntax example provided at the top of the ereturn help page. The = is optional, but a new name is not.

The correct code is ereturn matrix p = p.