Hello everyone,
I am looking for a way to create one categorical variable out of multiple dummy variables. More specifically, I have ten dummy variables indicating whether a person remembered a certain word named co07_1 co07_2 co07_3 co07_4 co07_5 co07_6 co07_7 co07_8 co07_9 co07_10. They are =1 if the respondent remembered the word and =3 otherwise.
I want to create a categorical variable that tells me how many words a person remembered ranging from 0 to 10.
If I were to do this by hand, this would require a lot of coding. Here an example of what this would look like for the values 9 and 10.
gen co07count = 10 if co07_1==1 & co07_2==1 & co07_3==1 & co07_4==1 & co07_5==1 & co07_6==1 & co07_7==1 & co07_8==1 & co07_9==1 & co07_10==1
replace co07count = 9 if co07_1==3 & co07_2==1 & co07_3==1 & co07_4==1 & co07_5==1 & co07_6==1 & co07_7==1 & co07_8==1 & co07_9==1 & co07_10==1 | co07_1==1 & co07_2==3 & co07_3==1 & co07_4==1 & co07_5==1 & co07_6==1 & co07_7==1 & co07_8==1 & co07_9==1 & co07_10==1 | co07_1==1 & co07_2==1 & co07_3==3 & co07_4==1 & co07_5==1 & co07_6==1 & co07_7==1 & co07_8==1 & co07_9==1 & co07_10==1 | co07_1==1 & co07_2==1 & co07_3==1 & co07_4==3 & co07_5==1 & co07_6==1 & co07_7==1 & co07_8==1 & co07_9==1 & co07_10==1 | co07_1==1 & co07_2==1 & co07_3==1 & co07_4==1 & co07_5==3 & co07_6==1 & co07_7==1 & co07_8==1 & co07_9==1 & co07_10==1 | co07_1==1 & co07_2==1 & co07_3==1 & co07_4==1 & co07_5==1 & co07_6==3 & co07_7==1 & co07_8==1 & co07_9==1 & co07_10==1 | co07_1==1 & co07_2==1 & co07_3==1 & co07_4==1 & co07_5==1 & co07_6==1 & co07_7==3 & co07_8==1 & co07_9==1 & co07_10==1 | co07_1==1 & co07_2==1 & co07_3==1 & co07_4==1 & co07_5==1 & co07_6==1 & co07_7==1 & co07_8==3 & co07_9==1 & co07_10==1 co07_1==1 & co07_2==1 & co07_3==1 & co07_4==1 & co07_5==1 & co07_6==1 & co07_7==1 & co07_8==1 & co07_9==3 & co07_10==1 | co07_1==1 & co07_2==1 & co07_3==1 & co07_4==1 & co07_5==1 & co07_6==1 & co07_7==1 & co07_8==1 & co07_9==1 & co07_10==3
Is there any way that one can use a loop for this that would (i) speed up the process and (ii) reduce the possibility that any errors occur?
Somebody's help with this would be very much appreciated!
Related Posts with Creating a categorical variable with multiple dummy variables
Changing a binary policy variable shifting it to next year for repeated cross section data I've enlisted policy as a binary variable which I need to take 1 year forward. Like in my data for …
generate a value indicating how many time a situation happens before the specific dateHello everyone in the community! Sorry to have some problems with the same data again , thanks agai…
rename variablesI am poor at Stata coding. I would like to rename from "logind1-logind84" to " logcoefstandind101, l…
Interval censored survival using aggregate dataHello, I've got data on vials of drosophila infected with a virus. Then at each time point, I recor…
Kaplan Meier survival description output - no median resulthi all, I am using Stat 16 on Mac. I am calculating Kaplan Meier survival curves for 2 groups of pat…
Subscribe to:
Post Comments (Atom)
0 Response to Creating a categorical variable with multiple dummy variables
Post a Comment