*! version 1.0.0 PR 05Jul95. (STB-26: ip8) program define for2 /* list [, options] : stata_cmd */ version 4.0 parse "`*'", parse(" ,:") while "`1'"!="," & "`1'"!=":" { if "`1'"=="" { error 198 } local forlist "`forlist' `1'" mac shift } if trim("`forlist'")=="" { error 198 } if "`1'"=="," { mac shift while "`1'"!=":" { if "`1'"=="" { error 198 } local optlist "`optlist' `1'" mac shift } } mac shift /* the colon */ local command "`*'" local options "Any noHeader noStop Numeric" parse ", `optlist'" if "`numeric'"!="" { local any "any" lexp `forlist' local forlist $S_1 } if "`any'"=="" { local varlist "req ex" parse "`forlist'" local forlist "`varlist'" } local nf : word count `forlist' local i 1 while `i'<=`nf' { parse "`forlist'", parse(" ") local for "``i''" parse "`command'", parse(" ") local cmd while "`1'"!="" { local cmd "`cmd'`1'#" mac shift } parse "`cmd'", parse("@#") local cmd while "`1'"!="" { if "`1'"=="#" { if "`2'"!="" { local cmd "`cmd' " } } else if "`1'"=="@" { local cmd "`cmd'`for'" } else { local cmd "`cmd'`1'" } mac shift } di if "`header'"=="" { di in bl "-> `cmd'" } if "`stop'"!="" { capture noisily `cmd' if _rc { if _rc==1 { exit 1 } di in blue "r(" _rc ");" } } else { `cmd' } local i=`i'+1 } end program define lexp /* based on modified reshape.rsgroup program */ parse "`*'", parse(" -") if "`3'"=="" { error 198 } confirm integer number `1' global S_1 `1' local last `1' mac shift local j 1 while "``j''"!="" { local arg`j' ``j'' local j=`j'+1 } local j 1 while "`arg`j''"!="" { local aj `arg`j'' if "`aj'"=="-" { local j=`j'+1 parse "`arg`j''", parse(" /") local aj `1' confirm integer number `aj' mac shift local inc 1 if "`1'"=="/" { mac shift confirm integer number `1' local inc `1' mac shift } if "`1'"!="" { error 111 } if `aj'<=`last' { error 198 } local i=`last'+`inc' while `i'<=`aj' { global S_1 "$S_1 `i'" local i=`i'+`inc' } local last `aj' } else { confirm integer number `aj' global S_1 "$S_1 `aj'" local last `aj' } local j=`j'+1 } end