*! 1.1.1 07Jan1999 Jeroen Weesie/ICS STB-50 ip28 program define bys version 6.0 * split input in bycmd : cmd pprecmd bycmd cmd : `0' if `"`cmd'"' == "" { di in re "colon with subsequent command expected" exit 198 } * parse bycmd with syntax: varlist [(varlist)], unSort Quietly gettoken vlist bycmd : bycmd, parse("(,") if `"`vlist'"' == "(" | `"`vlist'"' == "," | `"`vlist'"' == "" { di in re "varlist expected" exit 100 } unab vlist : `vlist', min(1) if substr(`"`bycmd'"',1,1) == "(" { gettoken vlist2 bycmd : bycmd, parse("(,") match(lmac) unab vlist2 : `vlist2', min(1) } local 0 `"`bycmd'"' syntax [, Unsort Quietly] * if necessary, sort ! local so : sortedby * this is not error proof with very long varlists! if index("`so'", "`vlist' `vlist2'") ~= 1 { if "`unsort'" ~= "" { tempvar n gen `n' = _n } else { di in bl "sorting on `vlist' `vlist2'" } sort `vlist' `vlist2' } * execute by: cmd * note we don't capture errors `quietly' by `vlist' : `cmd' * if necessary unsort if "`unsort'" ~= "" & "`n'" ~= "" { sort `n' if "`so'" ~= "" { sort `so' } } end exit the suggestion for the syntax of sublists is from W. Gould