Dear All,
I'm trying to create a new variable in my dataset that is derived from multiple other variables.
chadsvasc can be a score out of 9. Each of the other variables can have scores of 0 or 1, with chadsage having a score of 0,1, or 2. Chadsvasc is simply the sum of all the components, with strokeorembolism being assigned double points. Under normal circmstances, generate would work perfectly well.
however, when some of the component varibles have missing data, missing values are generated.
egen would avoid this, but doesn't seem to allow more complex mathematical equations. I could easily get around this of course by doing something like:
then use
Another solution would be to create new variables and replace the missing data with zeros to generate chadsvasc.
But, I wanted to know if there was some way to use egen with more complex mathematical combinations when some missing values are present.
Thanks for the input.
Chris
Using stata version 13
I'm trying to create a new variable in my dataset that is derived from multiple other variables.
chadsvasc can be a score out of 9. Each of the other variables can have scores of 0 or 1, with chadsage having a score of 0,1, or 2. Chadsvasc is simply the sum of all the components, with strokeorembolism being assigned double points. Under normal circmstances, generate would work perfectly well.
Code:
generate chadsvasc = female + chadsage + congestiveheartfailure + 2*strokeorembolism + diabetes + vasculardisease + hypertension
egen would avoid this, but doesn't seem to allow more complex mathematical equations. I could easily get around this of course by doing something like:
Code:
generate doublestroke= 2*strokeorembolism
Code:
egen chadsvasc = rowtotal(female chadsage congestiveheartfailure doublestroke diabetes vasculardisease hypertension), missing
But, I wanted to know if there was some way to use egen with more complex mathematical combinations when some missing values are present.
Thanks for the input.
Chris
Using stata version 13
Comment