Hello,
I could use some help combining 9 variables into one new variable.
So, I have 9 variables vprob_financial, vprob_familial.... coded no=0 and yes = 1.
I am hoping to create a new categorical variable that will combine all these binary variables, so I can get a proportion for 0=no and 1=financial 2=familial 3=marital...ect.
Things I have tried so far with no success:
I recoded the original variables vrpob_financial is now e2financial no=0 yes=1, vprob_social is now no=0 and yes=2 ect so that all the "YES" values have a different numeric coding.
Then I tried to gen a new variable
gen prob = 0
foreach var of varlist e2financial e2social e2familial e2marital e2physical e2illspirit e2mental e2dontknow e2other {
replace prob=1 if `var'==1
replace prob=2 if `var'==2
replace prob=3 if `var'==3
replace prob=4 if `var'==4
replace prob=5 if `var'==5
replace prob=6 if `var'==6
replace prob=7 if `var'==7
replace prob=8 if `var'==8
replace prob=9 if `var'==9
}
But this leads to a lot of missing values.
-----
So I tried stacking the data instead
stack e2financial e2social e2familial e2marital e2physical e2illspirit e2mental e2dontknow e2other, into(e2) clear wide
Which achieves what I need, but while it retains the e2varaibles (clear wide), it clears all the variables I don't want to stack including demographic data and other varaibles.
So how do I either create a new variable that combines all these binary variables to only give me a categorical variable with 10 levels (0=no 1=financial....) that I can ultimately use in a linear regression.
Alternatively, how do I use the stack command and make sure none of my other variables get deleted?
Thanks for the help in advance!
I could use some help combining 9 variables into one new variable.
So, I have 9 variables vprob_financial, vprob_familial.... coded no=0 and yes = 1.
I am hoping to create a new categorical variable that will combine all these binary variables, so I can get a proportion for 0=no and 1=financial 2=familial 3=marital...ect.
Things I have tried so far with no success:
I recoded the original variables vrpob_financial is now e2financial no=0 yes=1, vprob_social is now no=0 and yes=2 ect so that all the "YES" values have a different numeric coding.
Then I tried to gen a new variable
gen prob = 0
foreach var of varlist e2financial e2social e2familial e2marital e2physical e2illspirit e2mental e2dontknow e2other {
replace prob=1 if `var'==1
replace prob=2 if `var'==2
replace prob=3 if `var'==3
replace prob=4 if `var'==4
replace prob=5 if `var'==5
replace prob=6 if `var'==6
replace prob=7 if `var'==7
replace prob=8 if `var'==8
replace prob=9 if `var'==9
}
But this leads to a lot of missing values.
-----
So I tried stacking the data instead
stack e2financial e2social e2familial e2marital e2physical e2illspirit e2mental e2dontknow e2other, into(e2) clear wide
Which achieves what I need, but while it retains the e2varaibles (clear wide), it clears all the variables I don't want to stack including demographic data and other varaibles.
So how do I either create a new variable that combines all these binary variables to only give me a categorical variable with 10 levels (0=no 1=financial....) that I can ultimately use in a linear regression.
Alternatively, how do I use the stack command and make sure none of my other variables get deleted?
Thanks for the help in advance!
Comment