Dear all,
I am trying to create dummy variables under certain conditions. Every time that a certain variable takes value 1 I want to start a new dummy category, until this variable takes value 1 again. My data looks the following. The variables Number and R are the ones that I have in my data right now, the dummies are the ones that I wish to create. Every time the variable R takes value1 I want to switch to a new dummy. I really can't figure out how to get this done so any help would be highly appreciated!!
I am trying to create dummy variables under certain conditions. Every time that a certain variable takes value 1 I want to start a new dummy category, until this variable takes value 1 again. My data looks the following. The variables Number and R are the ones that I have in my data right now, the dummies are the ones that I wish to create. Every time the variable R takes value1 I want to switch to a new dummy. I really can't figure out how to get this done so any help would be highly appreciated!!
Number | R | dummy1 | dummy2 | dummy3 | dummy4 |
1 | 0 | 1 | 0 | 0 | 0 |
2 | 0 | 1 | 0 | 0 | 0 |
3 | 0 | 1 | 0 | 0 | 0 |
4 | 0 | 1 | 0 | 0 | 0 |
5 | 1 | 0 | 1 | 0 | 0 |
6 | 0 | 0 | 1 | 0 | 0 |
7 | 1 | 0 | 0 | 1 | 0 |
8 | 0 | 0 | 0 | 1 | 0 |
9 | 0 | 0 | 0 | 1 | 0 |
10 | 1 | 0 | 0 | 0 | 1 |
Comment