Using -egen-'s -group()- function in every case might help.
In Stata local macros are not regarded as variables.
Nick
On 23 Nov 2012, at 18:28, Pradipto Banerjee <pradipto.banerjee@adainvestments.com
> wrote:
Hi,
Suppose I have a set of variables v1, v2, v3, ..., vn where each
variable takes a value equal to 0, 1, 2. I want to write a program
that can do the following:
1. If the program is supplied with v1, then it loops over v1 = 0, 1,
2 and does some operation for each value of v1 . Here I can achieve
it with a single - forvalues - loop
2. If the program is supplied with v1 & v2, then it loops over v1 =
0,1,2 and v2=0,1,2 (i.e. a total of 9 loops), and does some
operation for each combination of v1 & v2. Here I can achieve it
with two nested -forvalues- loops
3. Similarly, if v1, v2, v3 are supplied, I can achieve it with
three nested -forvalues- loops
The problem can get out of hand if v1, v2, v3, ..., vn is supplied
to the program as I need to hard-code the nested loops structures up
to a large value of n.
An alternative is to run one - forvalues - or -forvalues- loop with
all permutations of v1, v2, v3,..., vn already determined in a local
macro variable.
Is there way / function that can return all permutations of v1, v2,
v3 ..., vn in a local macro variable(s) ?