*! version 1.1  mh 5/5/98  arb 20/8/98
program define longch

local options "Cond(string)"
local varlist "req ex min(1)"
local if "opt"
local in "opt"
parse "`*'"
tempvar all yes first nif touse recnum
local sort : sortedby
mark `touse' `if' `in'
qui gen `recnum' = _n
cap drop _some _none _every
qui count if `cond' & `touse'
di _result(1) "  records fulfill the condition `cond'" _n
* No. records which meet condition and if clause:
sort `varlist'
qui by `varlist': gen byte `yes' = sum(`cond' & `touse')
qui by `varlist': replace `yes' = `yes'[_N]
* No. records which meet if clause:
qui by `varlist': gen byte `nif' = sum(`touse')
qui by `varlist': replace `nif' = `nif'[_N]
qui by `varlist': gen byte `first' = (_n==1)
qui by `varlist': gen byte `all' = (`yes'==`nif')
qui count if `yes'>0 & `first'
di in gr "some : " in ye _result(1) in gr "  subjects in at least one record"
qui gen byte _some = `yes'>0 if `touse'
qui count if `all' & `first' & `nif'>0
di in gr "every: of which " in ye _result(1) in gr "  subjects in every record"
qui gen byte _every = `all' if `touse'
qui count if `yes'==0 & `first' & `nif'>0
di in gr "none : " in ye _result(1) in gr "  subjects in no records"
qui gen byte _none = (`yes'==0 & `nif'>0) if `touse'
* Restore original sort order:
sort `sort' `recnum'
end