program define z_r *! version 1.1.1 02Feb96 version 4.0 if "`1'" == "" { z_rvrfy S_1 S_2 S_3 } else { local varlist "req ex min(2)" local if "opt" local in "opt" local weight "aweight fweight" local options "Level(real .95) NOCorr NOLimit" parse "`*'" parse "`varlist'", parse(" ") tempvar touse mark `touse' `if' `in' markout `touse' `varlist' qui count if `touse' if _result(1) < 4 { error 2001 } if `level' > 1 { local level = `level'/100 } if `level'*(1-`level') < 0 { di in red "invalid confidence level" error 499 } if "`weight'" != "" { local weight "[`weight'`exp']" } qui matrix accum S_1 = `varlist' `weight' if `touse', dev nocon matrix S_3 = J(1,3,0) matrix rownames S_3 = z_r matrix colnames S_3 = n p level matrix S_3[1,1] = _result(1) matrix S_3[1,2] = rowsof(S_1) matrix S_3[1,3] = `level' matrix S_1 = corr(S_1) } if "`nocorr'" == "" { di in green "(sample correlations, n=" S_3[1,1] ")" matrix list S_1, format(%9.4f) noheader noblank } if "`1'" != "" { matrix S_2 = S_1 tempname tt1 tt2 d scalar `d' = invnorm(.5*(1+S_3[1,3]))/sqrt(S_3[1,1]-3) local i = 1 while `i' < S_3[1,2] { local i = `i' + 1 local j = 1 while `j' < `i' { scalar `tt1' = .5*log( (1+S_1[`i',`j'])/(1-S_1[`i',`j']) ) scalar `tt2' = exp(2*(`tt1'-`d')) matrix S_2[`i',`j'] = (`tt2'-1)/(`tt2'+1) scalar `tt2' = exp(2*(`tt1'+`d')) matrix S_2[`j',`i'] = (`tt2'-1)/(`tt2'+1) local j = `j' + 1 } } global S_1 "z_r" global S_2 "`if' `in'" } if "`nolimit'" != "" { exit } di "" di in green "(lower\upper " 100*S_3[1,3] "% confidence limits)" matrix list S_2, format(%9.4f) noheader noblank end