Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.

st: generating variable from combination of three categorical variable

 From prakash singh <[email protected]> To statalist <[email protected]> Subject st: generating variable from combination of three categorical variable Date Wed, 18 May 2011 05:10:56 -0700

```Hello all

In my survey data, I have three categorical variable with 0, 1 and 2 as
three category.
Now I want to make a variable using combination of these three
variables.

The combination is such that generated variable var4 == 0 if
var1==0 & var2==0 & var3==0,
var4=1 if var1==1 & var2==1 & var3==1,
var4=2 if var1==2 & var2==2 & var3==2,
var4=1 if var1|var2|var3 is having 0 and 1 only
var4=2 if var1|var2|var3 is having 0 and 2 only
var4 is 3 if var1|var2|var3 is 0,1 and 2

for exmple (see below)

var1 var2 var3 var4
0     0     0      0
1    1     1       1
2    2      2      2
0    1     2       3
0    1      1      1
1    2      0      3

I am using stata10.

Regards
Prakash
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```

• Follow-Ups: