I have a set of binary variables (n=17) for health conditions and each of them stands for a certain disease. For instance, if variable he_diabetes = 1, it means that the respondent has diabetes. If variable he_heart = 0, it means that the respondent doesn't have heart disease. It is possible that some respondents have none or more health conditions.
All these variables are included in a big database, which means it is possible that there are also other variables names begin with 'he_' but I only need to calculate with 17 health condition variables.
I wonder:
if I want to count for each respondent how many health conditions they have, is there a easier way to put the counts into one variable ? Or is it better to separate them from the dataset ?
I tried to generate a new variable to count the number of health conditions for each respondent but found it could be laborious
Code:
gen count =. replace count = 0 if he_diabetes = 0 | he_heart = 0 | he_asthma = 0 | he_leg = 0 replace count = 1 if he_diabetes = 1 & he_heart = 0 & he_asthma =0 & he_leg = 0 | he_diabetes = 0 & he_heart = 1 & he_asthma =0 & he_leg = 0 | ......
0 Response to How to count the values of a set of binary variables
Post a Comment