Hi Statalist,
I very much appreciate your help with my question.
I have hundreds of dummy variables that I would like to group together and then create new variables of these groups. I can do this successfully using the following code. For instance:
gen OSB6_Sci = 1 if ( SB6_42_Sci == 1 | SB6_20_Sci == 1 | SB6_13_Sci == 1 | SB6_11_Sci == 1)
gen OSB6_Vol = 1 if (SB6_42_Vol == 1 | SB6_13_Vol == 1)
gen OSB5_Sci = 1 if ( SB5_42_Sci == 1 | SB5_13_Sci == 1 | SB5_11_Sci == 1)
gen OSB4_Vol = 1 if ( SB4_20_Vol == 1 | SB4_13_Vol == 1 | SB6_5_Vol == 1)
As you can see there are many combinations and this is a very time consuming method. Is there any code that would enable me to do this more efficiently?
(I have tried using a loop command but I am unsure how to do this because I am creating the new variable for all of the dummy variables in that group not foreach of them.)
Thank you very much for all your time and help. If you required further detail or clarification I can provide more information.
Best regards
Seren
Related Posts with Aggregating Dummy Variables Efficiently
Order Coefficients in coefplotHi all, I am trying to produce a coefplot, and for some reason, the baseline year is showing up fir…
How to create matrix from a vector?Hi, given the following: . mat i = (1, 2, 3) . mat lis i i[1,3] c1 c2 c3 r1 1 2 3 . . mat N = i…
Coding for medication dataHello! I am using medication data for thousands of observations. I have calculated the total daily …
Distribution of gender within subgroups of a groupHi! I want to do demographics on my data. I have an outcome variable called hypertension (0/1). If …
ivprobit reports first stage results even w/o `first` optionI'm using ivprobit with Stata 14 and I think I discovered a bug. There is the option "first" to disp…
Subscribe to:
Post Comments (Atom)
0 Response to Aggregating Dummy Variables Efficiently
Post a Comment