*! wgap--measure the significance of gaps in a univariate distribution *! version 1.3.0 15 October 1993 Richard Goldstein sed8: STB-21 program define wgap quietly { version 3.1 local varlist "req ex min(1)" local if "opt" local in "opt" local options "Wgap(str) Z(str)" parse "`*'" if "`wgap'"=="" & "`z'"=="" { noi di in re "you must specify either wgap() or z()" exit 98 } local order: sortedby if "`order'"=="" { tempvar jorder gen long `jorder'=_n local order "`jorder'" } tempvar gap ifin lcount touse tukeyw v vcount w x mark `ifin' `if' `in' gen byte `touse' = . local nv: word count `varlist' parse "`varlist'", parse(" ") local i=0 while `i'<`nv' { local i=`i'+1 cap drop `w' tempvar w local v "``i''" local type: type `v' cap drop `x' gen `type' `x' = `v' if `ifin' sort `x' replace `touse' = `ifin' markout `touse' `x' _crcnuse `touse' local N $S_1 local first=$S_3 local last=$S_4 local in "in `first'/`last'" gen `type' `gap'=`x'-`x'[_n-1] `in' gen long `vcount'=_n-`first'+1 `in' gen float `tukeyw'=`vcount'[_n-1]*(`vcount'[`last']-`vcount'[_n-1]) `in' gen float `w'=sqrt(`tukeyw'*`gap') `in' if "`z'"!="" { local zname "`z'`i'" if `nv'==1 { local zname "`z'" } sum `w' if `vcount'>=(.25*`N') & `vcount'<=(.75*`N') gen float `zname'=`w'/_result(3) } if "`wgap'"!="" { local wname "`wgap'`i'" if `nv'==1 { local wname "`wgap'" } rename `w' `wname' } } sort `order' } /* end quietly */ end