*! version 6.0.0  30jul1999
program define _rocsen, rclass
	version 6.0

	/* Parse and generate `touse', `p' (predicted probabilities),
	   and `w' (weights) when all probabilities are equal.
	*/
	tempvar touse p w sens spec
	lfit_p `touse' `p' `w' `0'
	local y "`s(depvar)'"
	return scalar N = `s(N)'
	global S_1 `s(N)'
	/* Parse other options. */
	local 0 `", `s(options)'"'
	sret clear
	syntax [,GENSPec(string) GENSEns(string) /*
	*/ GENProb(string)  Class(string) ]

	tempvar C
	gen `C'=`class'

	/* FIX PROBABILITIES */
	tempvar order
	sort `C'
	qui by `C':gen long `order'=1 if _n==1
	qui replace `order'=sum(`order')
	qui  replace `p'=`p'+0.0000001*(`order'-1)
	sort  `p'
	if `"`genspec'"' != `""' { confirm new variable `genspec' }
	if `"`gensens'"' != `""' { confirm new variable `gensens' }
	if `"`gensp'"'   != `""' { confirm new variable `genprob' }
	local old_N = _N
	nobreak {
		capture noisily break {
			lsens_x `touse' `p' `w' `y' `sens' `spec'
		}
		local rc = _rc

		if _N > `old_N' /*
		*/ & (`rc' | `"`genspec'`gensens'`genprob'"'==`""') {
			qui drop if `touse' == .
		}
		if `rc' { exit `rc' }
	}
	if _N > `old_N' & `"`genspec'`gensens'`genprob'"'!=`""' {
		di in blu `"obs was `old_N', now "' _N
	}
	if `"`genprob'"' != `""' {
		qui gen float `genprob' = `p'
		label variable `genprob' `"Probability cutoff"'
		format `genprob' %9.6f
	}
	if `"`gensens'"' != `""' {
		rename `sens' `gensens'
		format `gensens' %9.6f
	}
	if `"`genspec'"' != `""' {
		rename `spec' `genspec'
		format `genspec' %9.6f
	}
end