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
Post-estimation test of the reg3 commandHi, I have been grappling with -reg3- command which implements 3SLS for a system of equations. Tryi…
Invalid Syntax r(198)Hi everyone, I was wondering if I could get help to figure out the problem with one of my commands.…
Statalist reputation bars under nameUsually very active members on Statalist have orange bars under their name. I noticed some orange ba…
Margins Error - Delta Ordered Probit RegressionHello Statalst, Has anyone experienced an error like this or know what it means? I lagged and diffe…
Invalid Syntax r(198)Hi everyone, I was wondering if I could get help to figure out the problem with one of my commands.…
Subscribe to:
Post Comments (Atom)
0 Response to Creating a categorical variable with multiple dummy variables
Post a Comment