Hi Statalist,
I've been puzzling over “mi” commands today, trying to understand what I can and can't do with imputed data, and would very much appreciate any insight into mean centering a predictor using imputed data. The model will examine predictors for work-related injuries, and the variable "day hours" (hours worked per day) was has 36% missing. My code is -
mi set wide
mi register imputed dayhours
mi register regular daysweek injuries ohr Cash_y threats vio sector Fluent Nodoc agecentred age2 monthscentred months3 Exp dsm_symptomatic sit_break any_memprob
mi impute chained (truncreg, ul(24) ll(1)) dayhours = daysweek injuries ohr Cash_y threats vio sector Fluent Nodoc agecentred age2 monthscentred months3 Exp dsm_symptomatic sit_break any_memprob, add(20) rseed(4409) force
**Create new var "day2" to create new hours worked/week var based on daysweek (days worked/week)
mi passive: gen day2=dayhours
mi passive: gen hoursweek2=.
mi xeq: replace hoursweek2=day2*5 if daysweek==1
mi xeq: replace hoursweek2=day2*6 if daysweek==2
mi xeq: replace hoursweek2=day2*7 if daysweek==3
mi xeq: replace hoursweek2=day2*7 if daysweek==4
**Rescale hours worked/week to 10
mi passive: gen hour10mi=hoursweek2/10
Now, I would like to create a variable, "c_hour10mi", that is mean centered, for each dataset. This is where I run into a problem -
mi xeq: sum hour10mi, meanonly
mi passive: gen c_hour10mi = hour10mi - r(mean)
When I try to create the mean centered variable, the command above generates all missing observations for “c_hour10mi” in all the imputed datasets. I’m not sure where I’m going wrong.. is there a command that works with mi suite that could take care of mean centering that works with?
With many thanks, Nicola
I've been puzzling over “mi” commands today, trying to understand what I can and can't do with imputed data, and would very much appreciate any insight into mean centering a predictor using imputed data. The model will examine predictors for work-related injuries, and the variable "day hours" (hours worked per day) was has 36% missing. My code is -
mi set wide
mi register imputed dayhours
mi register regular daysweek injuries ohr Cash_y threats vio sector Fluent Nodoc agecentred age2 monthscentred months3 Exp dsm_symptomatic sit_break any_memprob
mi impute chained (truncreg, ul(24) ll(1)) dayhours = daysweek injuries ohr Cash_y threats vio sector Fluent Nodoc agecentred age2 monthscentred months3 Exp dsm_symptomatic sit_break any_memprob, add(20) rseed(4409) force
**Create new var "day2" to create new hours worked/week var based on daysweek (days worked/week)
mi passive: gen day2=dayhours
mi passive: gen hoursweek2=.
mi xeq: replace hoursweek2=day2*5 if daysweek==1
mi xeq: replace hoursweek2=day2*6 if daysweek==2
mi xeq: replace hoursweek2=day2*7 if daysweek==3
mi xeq: replace hoursweek2=day2*7 if daysweek==4
**Rescale hours worked/week to 10
mi passive: gen hour10mi=hoursweek2/10
Now, I would like to create a variable, "c_hour10mi", that is mean centered, for each dataset. This is where I run into a problem -
mi xeq: sum hour10mi, meanonly
mi passive: gen c_hour10mi = hour10mi - r(mean)
When I try to create the mean centered variable, the command above generates all missing observations for “c_hour10mi” in all the imputed datasets. I’m not sure where I’m going wrong.. is there a command that works with mi suite that could take care of mean centering that works with?
With many thanks, Nicola
Comment