I am trying to create a single composite categorical variable from several (7) dummy variables. I exported the data from a survey software that created dummies out of a check any that apply question. I have tried gen and egen commands and every time I try to recode/replace the value it changes the original value from the dummy variable.
For example:
gen sector=.
replace sector=1 if gbcon==1
replace sector=2 if hhc==1
replace sector=3 if cm==1
replace sector=4 if engin==1
replace sector=5 if arch==1
replace sector=6 if spec==1
replace sector=7 if other_sector==1
The problem is that when I originally replace sector=1 if gbcon==1, the count is correct, however once I add the command replace sector=-2 if hhc==1, the count of gbcon changes from its original count to an inaccurate count.
when 'replace sector=1 if gbcon==1' the count is 25
after I add the code for 'replace sector=2 if hhc==1' the count for gbcon (or sector=1) changes to 19
I cannot figure out a) why this is happening as gbcon and hhc are not coming from the same variable, and b) how to stop the count from changing when adding additional dummy variables to this composite variable
For example:
gen sector=.
replace sector=1 if gbcon==1
replace sector=2 if hhc==1
replace sector=3 if cm==1
replace sector=4 if engin==1
replace sector=5 if arch==1
replace sector=6 if spec==1
replace sector=7 if other_sector==1
The problem is that when I originally replace sector=1 if gbcon==1, the count is correct, however once I add the command replace sector=-2 if hhc==1, the count of gbcon changes from its original count to an inaccurate count.
when 'replace sector=1 if gbcon==1' the count is 25
after I add the code for 'replace sector=2 if hhc==1' the count for gbcon (or sector=1) changes to 19
I cannot figure out a) why this is happening as gbcon and hhc are not coming from the same variable, and b) how to stop the count from changing when adding additional dummy variables to this composite variable
Comment