Program -selectvars- on SSC yields tuples of variable
names from a list. That's one of the parts of doing this
more generally.
One of the trickier parts is getting new varnames which not
only are new but also not too long. David's program doesn't
(really try to) tackle this. (Neither does -selectvars-.)
Anyway, he asked a question:
------------ David's code
* all two way interactions
program define atwi
syntax varlist (min 2 numeric)
local t = total number of variables <-- how do I get this?
tokenize `varlist'
for numlist j = 1(1)`t'-1 {
for numlist k = `j'+1(1)`t' {
generate ``j''x``k'' = ``j''*``k''
}
}
end
----------------------
This is a step or two further on, without
solving the naming problem:
* all two way interactions
program atwi
syntax varlist(min=2 numeric)
local t : word count `varlist'
tokenize `varlist'
forval j = 1/`=`t'-1' {
forval k = `=`j'+1'/`t' {
generate ``j''x``k'' = ``j''*``k''
}
}
end
The modified code for atwi works fine: