I am trying to implement a two-stage imputation process described in "Harel, O., & Schafer, J. L. (2003, November). Multiple imputation in two stages." using Stata18 to account for skip logic patterns where there is missingness at the Level 1 variables (CTYPE4, CTYPE7) and Level 2 variables (e.g., CTYPEHI1) where answering Level 2 is dependent upon responding "1" to Level 1 variables.
I am using mi impute chained for all Level 1 variables to create a _mi_m = 5 dataset.
Then, I use mi extract in a loop to impute two additional imputations of Level 2 variables for each imputation of Level 1.
This creates five datasets out of the Level 1 imputations, each containing two Level 2 imputations for a total of 10 imputations. My question is about how to combine these five datasets into something that can be analyzed by mi estimates commands. I have tried using mi append to append mi_dataset1 to the original data and it works fine. However, I cannot add mi_dataset2 because both mi_dataset1 and mi_dataset two have _mi_m values equal to 1 and 2 and so I end up with only two imputations rather than four. I also try mi add, but get an error that variable _mi_m cannot be found and it has cleared out my master data so no observations are left.
Is there a way to combine the five datasets into a single file that can be mi analyzed? Or is there a better process for the two-stage imputation in Stata?
Code:
input byte(CTYPE4 CTYPEHI1 CTYPEHI2 CTYPE7 CTYPERC1 CTYPERC3) 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 . 0 0 0 . . . 1 . . 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 . . . 0 0 0 0 0 0 1 0 1 1 1 1 0 0 0 0 0 0 1 . 0 0 0 0 1 . . 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 .
Code:
mi impute chained (logit) CTYPEHI1, add(5) force noimputed rseed(2023)
Then, I use mi extract in a loop to impute two additional imputations of Level 2 variables for each imputation of Level 1.
Code:
preserve forval i=1/5 { mi extract `i', clear mi set flong mi impute chained (logit) CTYPEHI1, add(2) force noimputed rseed(2023) drop if _mi_m == 0 save mi_dataset`i' restore, preserve }
Code:
forval i = 1/5 { mi add _all using mi_dataset`i' }
Is there a way to combine the five datasets into a single file that can be mi analyzed? Or is there a better process for the two-stage imputation in Stata?