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

st: bug fix


From   Richard Goldstein <[email protected]>
To   statalist <[email protected]>
Subject   st: bug fix
Date   Fri, 18 Oct 2002 08:53:16 -0400

A user, Jan Lanke, found a bug in my -kornbrot- command.

I finally found the time, with the help of -pause-, to
find and fix the problem.  The problem only occurred
when there were exact ties in the data across groups.
The fixed version appears below.

Rich Goldstein

*! kornbrot -- Kornbrot's rank difference test   (STB-29: snp9)
program define kornbrot
    version 4.0
    local varlist "req ex max(1)"
    local exp "req noprefix"
    local if "opt"
    local in "opt"
    parse "`*'"
    tempvar score rank ranka rankb touse id

    if "`exp'" ~= "" {
         unabbrev `exp'
    }

    preserve

    quietly {
         mark `touse' `if' `in'
         markout `touse' `varlist' `exp'
         drop if `touse'==0
    }

    quietly {
         su `varlist'
         local en _result(1)
         gen `id'=_n
         expand=2
         gen `score'=`varlist'
         replace `score'=`exp' if _n>`en'
         egen `rank'=rank(`score')
         replace `rank'=((2*`en')+1) - `rank'
         gen `ranka'=`rank' if `varlist'==`score'
         gen `rankb'=`rank' if `exp'==`score'
         sort `id' `ranka'
         replace `rankb'=`rankb'[_n+1] if `rankb'==.
         drop if `ranka'==. | `ranka' == `ranka'[_n-1]
    }
    signrank `ranka'=`rankb'
end
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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