Dear Statalisters,
I've been trying to understand -xtmixed- and multiple imputation. Rabe-Hesketh & Skrondal's book has been really useful, but it does not address multiple imputation.
So, I've prepared a small script to make myself clearer. See it below. My questions are:
1. Is there any straightforward, non-flamboyant way to obtain predictions with both fixed and random parts after -xtmixed- and multiple imputation?
2. If I have a variable, say "weight", measured over time (week=1,2,3,4,5,6,7,8 and 9), and need that predictions for variable weight at time 2 need to be adjusted for weight at time 1 (baseline), how do I do that ?
I will be extremely thankful for any help.
All the best,
Tiago
*/ ----------------------------------------- start ------------------------------------------------------------------------
*/ Download the dataset used by Ruppert, Wand, and Carroll (2003) and Diggle et al. (2002)
*/ It is a longitudinal study. 48 pigs were followed up for 9 weeks and their weight was recorded.
set seed 2017
use http://www.stata-press.com/data/r13/pig.dta, clear
*/ reshape for multiple imputation
reshape wide weight, i(id) j(week)
*/ generate 4 hypothetical auxiliary variables, 3 continuous and 1 binary (1 = male, 0 = female)
gene cov1 = rnormal(10,3)*weight9
gene cov2 = rnormal(10,4)*weight9
gene cov3 = rnormal(10,5)*weight9
gene gender = runiform()>0.5
*/ generate 30% of missing data at random for week 9
replace weight9 = cond(runiform()<0.30,.,weight9)
*/imputation
mi set flong
mi register imputed weight9
mi impute monotone (regress) weight9 = cov1 cov2 cov3 weight8 gender, add(5)
mi reshape long weight, i(id) j(week)
*/ I would like to allow for a random slope on week, an unstructured covariance structure and that results are adjusted for gender.
*/ So, I added gender (1= male,0 = female) to the fixed part of the random-effects coefficient model
mi estimate: xtmixed weight i.week i.gender || id: week, covariance(unstructured)
mi estimate, saving(myestimates, replace): xtmixed weight week gender || id: week, covariance(unstructured)
mi predict myprediction using myestimates
mi estimate : mean weight, over(week)
mi xeq 0: mean myprediction, over(week)
*/ ----------------------------------------- end ------------------------------------------------------------------------
I've been trying to understand -xtmixed- and multiple imputation. Rabe-Hesketh & Skrondal's book has been really useful, but it does not address multiple imputation.
So, I've prepared a small script to make myself clearer. See it below. My questions are:
1. Is there any straightforward, non-flamboyant way to obtain predictions with both fixed and random parts after -xtmixed- and multiple imputation?
2. If I have a variable, say "weight", measured over time (week=1,2,3,4,5,6,7,8 and 9), and need that predictions for variable weight at time 2 need to be adjusted for weight at time 1 (baseline), how do I do that ?
I will be extremely thankful for any help.
All the best,
Tiago
*/ ----------------------------------------- start ------------------------------------------------------------------------
*/ Download the dataset used by Ruppert, Wand, and Carroll (2003) and Diggle et al. (2002)
*/ It is a longitudinal study. 48 pigs were followed up for 9 weeks and their weight was recorded.
set seed 2017
use http://www.stata-press.com/data/r13/pig.dta, clear
*/ reshape for multiple imputation
reshape wide weight, i(id) j(week)
*/ generate 4 hypothetical auxiliary variables, 3 continuous and 1 binary (1 = male, 0 = female)
gene cov1 = rnormal(10,3)*weight9
gene cov2 = rnormal(10,4)*weight9
gene cov3 = rnormal(10,5)*weight9
gene gender = runiform()>0.5
*/ generate 30% of missing data at random for week 9
replace weight9 = cond(runiform()<0.30,.,weight9)
*/imputation
mi set flong
mi register imputed weight9
mi impute monotone (regress) weight9 = cov1 cov2 cov3 weight8 gender, add(5)
mi reshape long weight, i(id) j(week)
*/ I would like to allow for a random slope on week, an unstructured covariance structure and that results are adjusted for gender.
*/ So, I added gender (1= male,0 = female) to the fixed part of the random-effects coefficient model
mi estimate: xtmixed weight i.week i.gender || id: week, covariance(unstructured)
mi estimate, saving(myestimates, replace): xtmixed weight week gender || id: week, covariance(unstructured)
mi predict myprediction using myestimates
mi estimate : mean weight, over(week)
mi xeq 0: mean myprediction, over(week)
*/ ----------------------------------------- end ------------------------------------------------------------------------
Comment