*! version 4.0.3  July 12, 2000 @ 09:45:49
program define spearwt, rclass
	version 6
	syntax varlist(min=2 max=2) [if] [in] [aweight]
	marksample touse
	tokenize `varlist'
	tempname N pval rho
	tempvar r1 r2
	quietly {
		egen `r1' = rank(`1') if `touse'
		egen `r2' = rank(`2') if `touse'
		if "`weight'"!="" {
			local theWt "[`weight' `exp']"
			}
		corr `r1' `r2' `theWt'
		scalar `N' = r(N)
		scalar `rho' = r(rho)
		if (`rho' == 1) { scalar `pval' = 0 }
		else scalar `pval' = tprob(`N'-2, `rho'*sqrt((`N'-2)/(1-`rho'^2)))
	}
/* Print results */
	#delimit ;
       	di _n
		in gr " Number of obs = " in ye  %7.0f `N' _n
        	in gr "Spearman's rho = " in ye %12.4f `rho' _n(2)
		in gr "Test of Ho: `1' and `2' independent" _n
       		in gr "      Pr > |t| = " in ye %12.4f `pval' ;
	#delimit cr

	ret scalar N   = `N'
	ret scalar rho = `rho'
	ret scalar p   = `pval'

	/* Double saves */
	global S_1 = `return(N)'
	global S_4 = `return(rho)'
	global S_6 = `return(p)'
end