program def collfreq *! 1.1.0 NJC 22 April 1998 STB-44 dm59 * 1.0.0 NJC 5 October 1997 * based on WWG suggestion 3 October 1997 version 5.0 local if "opt" local in "opt" local weight "fweight" local options "Freq(string) Zero NOMISS" local varlist "req ex" parse "`*'" if "`freq'" == "" { capture confirm new variable freq if _rc == 0 { local freq "freq" } else { capture confirm new variable _freq if _rc == 0 { local freq "_freq" } else { di in r /* */ "freq and _freq already defined: " /* */ "use freq( ) to specify frequency variable" exit 198 } } } else { confirm new variable `freq' } tempvar touse mark `touse' `if' `in' if "`nomiss'" == "nomiss" { markout `touse' `varlist' } qui keep if `touse' if "`exp'" != "" { qui expand `exp' } keep `varlist' sort `varlist' qui by `varlist': gen long `freq' = _N label var `freq' "Frequency" qui by `varlist': keep if _n == _N if "`zero'" != "" { fillin `varlist' qui replace `freq' = 0 if `freq' == . qui drop _fillin } qui compress `freq' end