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
Trying to run a predicted probabilities plot with a twoway scatterplot with a splineI accidentally created two threads of the same thing …
match age and genderHello, I would like to know how to match 2:1 for age and gender using same sample of individuals. I …
Tried several variations...need help with graphing a predicted probabilities plot with twoway scatter plot and splinedHi Statalist, I cannot figure out how to do this... the attached graph is exactly what we want, but …
GLS for non-linear equationln (Pit) = a*ln(Rit + b*Vit) + uit I want to estimate a, b for wide panel data (i = 1~16, t = 2007~…
data management, creating new variables in one data set based on information in another data baseHello All, I hope this email finds you well! I have two databases one includes my raw data, and th…
Subscribe to:
Post Comments (Atom)
0 Response to Creating a categorical variable with multiple dummy variables
Post a Comment