I have a cause of death data set as follows:
Id | Diabetes | CVD | Cancer | Kidneyfailure |
A | 1 | 1 | ||
B | 1 | |||
C | 1 | 1 | ||
D | 1 | 1 | ||
E | 1 | 1 | 1 | |
F | 1 | |||
G | 1 | |||
H | 1 | |||
1 | 1 | 1 |
I want to create separate variables with an outcome of 1 for all possible combinations.
for example, something like the below.
Id | Diabetes | CVD | Cancer | Kidneyfailure | diabetes&cvd | diabetes&cancer | diabetes&kidneyfailure | cvd&cancer | cancer&kidneyfailure |
A | 1 | 1 | 1 | ||||||
B | 1 | ||||||||
C | 1 | 1 | 1 | ||||||
D | 1 | 1 | 1 | ||||||
E | 1 | 1 | 1 | 1 | 1 | 1 | |||
F | 1 | ||||||||
G | 1 | ||||||||
H | 1 | ||||||||
I | 1 | 1 | 1 |
I have tried writing this manually so for example
* gen diabetes&cvd=1 if diabetes==1 & cvd==1
But this becomes tedious because the actual data set has many causes of deaths. Therefore, appreciate if there is an easier way of doing this.
Thank you
0 Response to Please help: How to create all possible combinations of several variables?
Post a Comment