Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: tau-c on Stata


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: tau-c on Stata
Date   Wed, 30 May 2012 08:53:57 +0100

Some refinements:

program define tauc, rclass
syntax varlist(numeric min=2 max=2) [if] [in]

quietly {
	marksample touse
	count if `touse'
	if r(N) == 0 error 2000
	if r(N) < 3  error 2001
	local N = r(N)

	tokenize "`varlist'"
	if "`1'" == "`2'" {
	    di as err "two different variables required"
	    exit 102
	}

	tab `1' if `touse'
	local m1 = r(r)
	tab `2' if `touse'
	local m2 = r(r)
	local m = min(`m1', `m2')
	ktau `1' `2' if `touse'
}

tempname tauc
scalar `tauc' = r(score) * (2 * `m'/(`N'^2 * (`m' - 1)))
di _n as txt " tau_c = " as res %8.4f `tauc'

return scalar tau_c = `tauc'
end

Main changes:

1. Steve's program allows -if- and -in-, but ignores them.

2. If the varlist is a wildcard, arguments `1' and `2' will not be as desired.

3. Some checking for inadequate sample size. Should probably go further.

Nick

On Wed, May 30, 2012 at 4:01 AM, Steve Samuels <[email protected]> wrote:

> The post you referred to was from Roger Newson.
> Here's a bootstrapped version of Roger's code.
>
> **************CODE BEGINS*************
> capture program drop _all
> program define tauc, rclass
> syntax varlist(min=2 max=2) [if] [in]
> if  `"`1'"'== `"`2'"' {
>     di as error "Error: Two different variables required"
>     exit 102
> }
> tempname v1 v2 m1 m2 m score N tauc
> gen `v1' = `1'
> gen `v2' = `2'
> sum `v1'
> tab `v1' if !missing(`v2')
> scal `m1'=r(r)
> tab `v2' if !missing(`v1')
> scal `m2'=r(r)
> scal `m'=min(`m1',`m2')
> qui ktau `v1' `v2'
> return list
> scalar `score'=r(score)
> scal `N'=r(N)
> local tauc= `score'*(2*`m'/(`N'^2*(`m'-1)))
> return scalar tau_c = `tauc'
> end
>
> sysuse auto, clear
> bootstrap tau_c = r(tau_c), reps(50): tauc trunk foreign
> estat bootstrap, all
>
> ***************CODE ENDS************
>

 On May 29, 2012, at 8:53 PM, Thomas Didier wrote:

Is there a command or a plug-in for Stata to estimate Kendall tau-c? A
response to a 2008 question
(http://www.stata.com/statalist/archive/2008-08/msg00300.html)
provided a "manual" way to make the calculation; this works but takes
some time and doesn't provide a level of statistical significance
(ASE). Apparently tau-c is a routine estimation on SPSS and I hope I
can find an equivalent on Stata.

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index