Say I have a dataset with three variables a
, b
, c
, and having 5 observations. Like the following:
a b c
1 0 1
1 1 1
0 1 0
0 1 1
1 0 0
Now I want to generate a new variable called type
, which is a possible combination of variable a
, b
and c
. Specifically,
type=1
ifa=b=c=0
type=2
ifa=c=0 & b=1
type=3
ifa=b=0 & c=1
type=4
ifa=0 & b=c=1
type=5
ifa=1 & b=c=0
type=6
ifa=b=1 & c=0
type=7
ifa=c=1 & b=0
type=8
ifa=b=c=1
The new dataset I want to get is:
a b c type
1 0 1 7
1 1 1 8
0 1 0 2
0 1 1 4
1 0 0 5
Are there any general ways to realize this in Stata? It's better if this can also be extended when type
is large, say 100 types. Thx a lot.