Hi there
I am working with an imputed dataset (mlong) and I would like to produce a 'tab' of a variable called 'ccsubscale2_y2cm'.
I can't find a command from the mi estimation commands that supports this.
In more detail:
The ccsubscale2_y2cm variable is an ordinal numeric variable which notes the number of chronic conditions that a person has: 0 , 1, 2, 3, 4, or 5 (I've taken a screenshot).
It is calculated passively as the sum of disease indicators (see code below). Some of these indicators - such as obesecc_y2cm (an indicator for obesity) have had missing values in m=0 (36% were missing). The missing values were imputed in Stata and are complete in the resulting 20 imputed datasets.
// Recreate ccsubscale_y2cm with obesity indicator
mi passive: gen ccsubscale2_y2cm = asthmacc_2_y2cm + ///
eczemacc_2_y2cm + ///
birthcc_y2cm + ///
epilepsycc_y2cm + ///
hearingcc_y2cm + ///
visioncc_y2cm + ///
cci_total_y2cm + ///
obesecc_y2cm
mi xeq: lab var ccsubscale2_y2cm "chronic conditions subscale score at 2 yrs"
Now I would like to look at this variable in the imputed datasets.
I try to use the 'mi estimate' command:
// Attempt 1
mi estimate: mean ccsubscale2_y2cm, over(ccsubscale2_y2cm, nolabel)
// Attempt 2
mi estimate: mean ccsubscale2_y2cm if (ccsubscale2_y2cm == 1)
This didn't work.
What I actually want is something like:
mi estimate: tab ccsubscale2_y2cm
in order to get a count of the number of people having 0, 1, 2, 3, 4, or 5 chronic conditions across the imputed datasets.
A laborious solution that I have found is to do this (doing each value of ccsubscale2_y2cm separately):
// calculate prevalences of ccsubscale2_y2cm by creating 0/1 indicators for each value of ccsubscale2_y2cm
mi passive: gen ccsubscale2_y2cm_0 = 0
mi xeq: replace ccsubscale2_y2cm_0 = 1 if (ccsubscale2_y2cm == 0)
mi xeq: replace ccsubscale2_y2cm_0 = . if (ccsubscale2_y2cm == . )
mi estimate: mean ccsubscale2_y2cm_0 // prevalence 0.587, 58.7% have 0 chronic conditions
mi estimate: total ccsubscale2_y2cm_0 // total 3368.95 have 0 chronic conditions
...
But I wonder if there is a better way?
Any advice would be appreciated!
Warmly
Jin
I am working with an imputed dataset (mlong) and I would like to produce a 'tab' of a variable called 'ccsubscale2_y2cm'.
I can't find a command from the mi estimation commands that supports this.
In more detail:
The ccsubscale2_y2cm variable is an ordinal numeric variable which notes the number of chronic conditions that a person has: 0 , 1, 2, 3, 4, or 5 (I've taken a screenshot).
It is calculated passively as the sum of disease indicators (see code below). Some of these indicators - such as obesecc_y2cm (an indicator for obesity) have had missing values in m=0 (36% were missing). The missing values were imputed in Stata and are complete in the resulting 20 imputed datasets.
// Recreate ccsubscale_y2cm with obesity indicator
mi passive: gen ccsubscale2_y2cm = asthmacc_2_y2cm + ///
eczemacc_2_y2cm + ///
birthcc_y2cm + ///
epilepsycc_y2cm + ///
hearingcc_y2cm + ///
visioncc_y2cm + ///
cci_total_y2cm + ///
obesecc_y2cm
mi xeq: lab var ccsubscale2_y2cm "chronic conditions subscale score at 2 yrs"
Now I would like to look at this variable in the imputed datasets.
I try to use the 'mi estimate' command:
// Attempt 1
mi estimate: mean ccsubscale2_y2cm, over(ccsubscale2_y2cm, nolabel)
// Attempt 2
mi estimate: mean ccsubscale2_y2cm if (ccsubscale2_y2cm == 1)
This didn't work.
What I actually want is something like:
mi estimate: tab ccsubscale2_y2cm
in order to get a count of the number of people having 0, 1, 2, 3, 4, or 5 chronic conditions across the imputed datasets.
A laborious solution that I have found is to do this (doing each value of ccsubscale2_y2cm separately):
// calculate prevalences of ccsubscale2_y2cm by creating 0/1 indicators for each value of ccsubscale2_y2cm
mi passive: gen ccsubscale2_y2cm_0 = 0
mi xeq: replace ccsubscale2_y2cm_0 = 1 if (ccsubscale2_y2cm == 0)
mi xeq: replace ccsubscale2_y2cm_0 = . if (ccsubscale2_y2cm == . )
mi estimate: mean ccsubscale2_y2cm_0 // prevalence 0.587, 58.7% have 0 chronic conditions
mi estimate: total ccsubscale2_y2cm_0 // total 3368.95 have 0 chronic conditions
...
But I wonder if there is a better way?
Any advice would be appreciated!
Warmly
Jin