Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: RE: Nonparametric Multiple Comparison Testing

From   Raphael Fraser <>
Subject   Re: st: RE: Nonparametric Multiple Comparison Testing
Date   Wed, 4 Jan 2006 09:46:02 -0500


I had the same problem recently and was able solve my problem courtesy
of this code written by Joseph Coveney. I have tailored the code to my
specific need. It uses Stata's ranksum command to compare the groups
using holm's method. Other methods are available, type help _mtest. As
it stands this code will only work for four groups due to this line in
the code: "forvalues k = `j'/4". Therefore if you have seven groups
your code should read "forvalues k = `j'/7".

Here is the link to the original:

set more off
infile byte rctime1 byte rctime2 byte rctime3 byte rctime4 using ///
generate person = _n
reshape long rctime, i(person) j(drug)
matrix A = J(1, 3, 0)
local testno = 0
forvalues i = 1/3 {
   local j = `i' + 1
   forvalues k = `j'/4 {
       quietly ranksum rctime if (person==`i'|person==`k'), by(person)
       if r(z)>0 matrix B = (`i', `k', 2*(1-norm(r(z))))
            else matrix B = (`i', `k', 2*(norm(r(z))))
       if `testno' == 0 {
           matrix A = B
       else {
           matrix A = A \ B
       local rownamesA = "`rownamesA'" + "testpair`++testno' "
matrix rownames A = `rownamesA'
matrix colnames A = onemut othermut unadjustp
_mtest adjust A, mtest(holm) pindex(3) append
matrix list r(result)


*   For searches and help try:

© Copyright 1996–2022 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index