*! 1.1.1 GML NJC 26 February 2002 * 1.1.0 GML NJC 25 February 2002 * 1.0.0 21 November 2001 program define distinct, rclass sortpreserve byable(recall) version 7.0 syntax [varlist] [if] [in] [, MISSing ] * header: di di in text " {c |} Observations" di in text " Variable {c |} total distinct" di in text "{hline 14 }{c +}{hline 22}" foreach var of local varlist { tempvar touse values mark `touse' `if' `in' * markout separately for each variable in varlist: if "`missing'" == "" { markout `touse' `var', strok } bys `touse' `var' : gen byte `values' = (_n == 1) * `touse' sum `values' if `touse', meanonly di in text %13s abbrev("`var'",13) " {c |} " /* */ as result %9.0g `r(N)' " " %9.0g `r(sum)' drop `touse' `values' } return scalar N = `r(N)' return scalar ndistinct = `r(sum)' end