* results for each n-tuple of values from Cartesian product program define cp *! 1.2.0 NJC 12 June 1998 STB-45 ip27 * 1.1.0 NJC 4 June 1998 version 5.0 parse "`*'", parse(" \:,") local args "`*'" local nargs : word count `args' local nocolon = 1 local i = 1 while `i' <= `nargs' { local arg : word `i' of `args' if "`arg'" == ":" { local nocolon = 0 } local i = `i' + 1 } if `nocolon' { di in r "invalid syntax" exit 198 } local i = 0 /* indexes argument in list */ local j = 1 /* indexes lists */ while "`1'" != ":" { if "`1'" == "\" { local n`j' = `i' local i = 0 local j = `j' + 1 mac shift } else if "`1'" == "," { while "`1'" != ":" { mac shift if substr("`1'",1,1) == "p" { global pause "pause" } else if substr("`1'",1,3) == "noh" { global header "no" } else if substr("`1'",1,3) == "nos" { global stop "no" } else if "`1'" != ":" { di in r "invalid syntax" exit 198 } } } else { if `j' == 6 { di in r "6 or more lists not supported" exit 198 } local i = `i' + 1 local a`j'`i' `1' mac shift } } mac shift local n`j' = `i' if "`n2'" == "" | "`n2'" == "0" { local n2 = 1 } if "`n3'" == "" | "`n3'" == "0" { local n3 = 1 } if "`n4'" == "" | "`n4'" == "0" { local n4 = 1 } if "`n5'" == "" | "`n5'" == "0" { local n5 = 1 } di global cmd "`*'" local i = 1 while `i' <= `n1' { local j = 1 while `j' <= `n2' { local k = 1 while `k' <= `n3' { local l = 1 while `l' <= `n4' { local m = 1 while `m' <= `n5' { Doit `a1`i'' `a2`j'' `a3`k'' `a4`l'' `a5`m'' local m = `m' + 1 } local l = `l' + 1 } local k = `k' + 1 } local j = `j' + 1 } local i = `i' + 1 } global pause global header global stop end program def Doit local A1 `1' local A2 `2' local A3 `3' local A4 `4' local A5 `5' parse "$cmd", parse(" ") while "`1'" != "" { local incmd "`incmd'`1'" if "`2'" != "" { local incmd "`incmd'#" } mac shift } local length = length("`incmd'") local i = 1 while `i' <= `length' { local char = substr("`incmd'",`i',1) if "`char'" == "@" { local i = `i' + 1 local char = substr("`incmd'",`i',1) if "`char'" >= "1" & "`char'" <= "5" { local outcmd "`outcmd'`A`char''" } } else if "`char'" == "#" { local outcmd "`outcmd' " } else { local outcmd "`outcmd'`char'" } local i = `i' + 1 } if "$header" != "no" { di in bl "-> `outcmd'" } if "$stop" == "no" { local nostop "capture noi" } `nostop' `outcmd' if "$stop" == "no" & _rc { if _rc == 1 { global pause global header global stop exit 1 } di in bl "r(" _rc ");" } if "$pause" == "pause" { more } di end