Hi there,
Is there any way of forcing Stata to accommodate imputed variables in the model specification of other (to-be) imputed variables in a single "mi impute chained" command? To illustrate, consider a scenario where you have repeated measures data with three follow-ups, a1, a2 and a3, where the latter two are incomplete. If, in each imputation, you want to adjust for the previous one, Stata doesn't allow you to perform imputations in a single command, throwing an "imputation variable cannot be also specified as independent variable" error. Of course, you can simply perform the imputations separately, but with more follow-ups (for example) this would be rather cumbersome. The code below demonstrates this issue:
The only workaround I can find is to use "twofold" imputation command, although it is rather limited in terms of available models. Any advice on this would be greatly appreciated!
Many thanks,
Dylan
Is there any way of forcing Stata to accommodate imputed variables in the model specification of other (to-be) imputed variables in a single "mi impute chained" command? To illustrate, consider a scenario where you have repeated measures data with three follow-ups, a1, a2 and a3, where the latter two are incomplete. If, in each imputation, you want to adjust for the previous one, Stata doesn't allow you to perform imputations in a single command, throwing an "imputation variable cannot be also specified as independent variable" error. Of course, you can simply perform the imputations separately, but with more follow-ups (for example) this would be rather cumbersome. The code below demonstrates this issue:
Code:
set seed 1234 clear set obs 50 gen id = _n gen trt = rbinomial(1,0.5) gen a1 = rnormal(50,10) + 2*trt /// 1st follow-up variable gen a2 = a1 + rnormal(5,5) + 2*trt /// 2nd follow-up variable gen b2 = rbinomial(1,0.25) /// variable to impute missingness into 2nd follow-up variable gen a3 = a2 + rnormal(5,5) + 2*trt /// 3rd follow-up variable gen b3 = rbinomial(1,0.3) /// variable to impute missingness into 3rd follow-up variable replace a2 = . if b2 replace a3 = . if b3 drop b* mi set flong mi register imputed a2 a3 preserve mi impute regress a2 = a1 i.trt, add(1) mi impute regress a3 = a2 i.trt, replace list, separator(50) /// specifying separate imputation models works restore mi impute chained (regress, include(a1)) a2 (regress, include(a2)) a3 = i.trt, add(1) orderasis /// but doing it all in one does not
Many thanks,
Dylan
Comment