I am trying to create a new variable out of two variables in the same dataframe (df), like those below. The categories are mutually exclusive.
VAR1 VAR2
1 1
2 2
6 6
1 = yes
2 = no
6 = did not answer
The script I have tried to get the combined variable, but is not working is below:
if (df$VAR1 == 1) {
df$combo = 1
} else if (df$VAR2 == 1) {
df$combo = 2
} else if ((df$VAR1 == 2) & (df$VAR2 == 2)) {
df$combo = 3
} else if ((df$VAR1 == 6) & (df$VAR2 == 6)) {
df$combo = 6
}
Any pointers will be appreciated.