I have three categorical variables i.e. stroke, MI and BP with values of 0 = yes and 1= No. I want to merge them to make a new variable "cvd" out of these three variables where each row with 0 gets 0 values in new cardiovascular variable. For example:
Stroke MI BP CVD
0 1 1 0
1 1 1 1
1 1 0 0
I tried the following code but this is not what i want
transform(koratest, cvd=paste(stroke,MI, BP))
Can someone please help what could be the script for this?
Best,
Thank you for all the solutions. What to do if there is missing values in any of the values to be merged. I want missing values to be labelled as 1 but if there is 0 with missing value, i want cvd variable to have value of 1. For example:
Stroke MI BP CVD
0 1 1 0
1 NA NA 1
0 NA 1 0
How could i achieve such output?