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
using factor score as dependend variableHi all, I tried to run an OLS regression (using reg) with a factor score as dependent variable. But…
Panel Data Question I could not find in any bookHi All, I have read several manuals on panel data econometrics but I never found the answer to thes…
how to count the distribution of industry in the sampleHi, I would like to have an overview of the industry distribution in my sample to see which industr…
Manual SE adjustment for 2SLS with clusteringHello, I'd like to manually estimate a two-stage least squares regression, first running the first …
Help with Summary stats dummy variableHello all, I'm looking to see if there is a command that I can easily get the summary stats. BA_St…
Subscribe to:
Post Comments (Atom)
0 Response to Creating a categorical variable with multiple dummy variables
Post a Comment