Feb 14, 2018

Handling missing values in Stata

This allows replicating the analyses in Allison (2002, pp. 68-73).
// MI example 2
use spanking age educ income91 sex race marital region childs god using "C:\Users\User\Dropbox (FAMSIZEMATTERS)\methods and data\GSS1994.dta", clear
recode spanking (1 = 4) (2 = 3) (3 = 2) (4 = 1)
generate female  = (sex == 2)
generate black   = (race == 2)
recode income91 ( 1 =   500) ( 2 =  2000) ( 3 =  3500) ( 4 =  4500) ( 5 =  5500) /// 
                ( 6 =  6500) ( 7 =  7500) ( 8 =  9000) ( 9 = 11250) (10 = 13750) ///
                (11 = 16250) (12 = 18750) (13 = 21250) (14 = 23750) (15 = 27500) ///
                (16 = 32500) (17 = 37500) (18 = 45000) (19 = 55000) (20 = 67500) ///
                (21 = 75000), gen(income)
replace income = income / 1000

generate nochild = (childs == 0)         if !missing(childs)
generate nodoubt = (god == 6)            if !missing(god)
generate nevmar  = (marital == 5)        if !missing(marital)
generate divsep  = inlist(marital, 3, 4) if !missing(marital)
generate widow   = (marital == 2)        if !missing(marital)
generate east    = inlist(region, 1, 2)
generate midwest = inlist(region, 3, 4)
generate south   = inlist(region, 5, 6, 7)

misschk spanking female black income educ nodoubt nochild age east midwest south nevmar divsep widow

eststo clear
eststo: ologit spanking female black income educ nodoubt nochild age east midwest south nevmar divsep widow

drop if missing(marital)

preserve
recode educ (.d .n = .) 
recode spanking (.d .i .n = .)

mi set mlong
mi register imputed spanking female black income educ nodoubt nochild age east midwest south nevmar divsep widow

mi impute mvn spanking female black income educ nodoubt nochild age east midwest south nevmar divsep widow, ///
   add(5) burnin(500) burnbetween(200) emlog emoutput

foreach x of varlist female black nodoubt nochild east midwest south nevmar divsep widow {
   replace `x' = 0 if `x'  < .5 & _mi_m != 0
   replace `x' = 1 if `x' >= .5 & _mi_m != 0
}

replace spanking = 1 if                   spanking < 1.5 & _mi_m != 0
replace spanking = 2 if spanking >= 1.5 & spanking < 2.5 & _mi_m != 0
replace spanking = 3 if spanking >= 2.5 & spanking < 3.5 & _mi_m != 0
replace spanking = 4 if spanking >= 3.5                  & _mi_m != 0

eststo: mi estimate, post: ologit spanking female black income educ nodoubt nochild age east midwest south nevmar divsep widow
restore

preserve
recode educ (.d .n = .) 
recode spanking (.d .i .n = .)

mi set mlong
mi register imputed spanking female black income educ nodoubt nochild age east midwest south nevmar divsep widow

mi impute chained (mlogit) spanking (regress) income educ (logit) nodoubt nochild = female black age east midwest south nevmar divsep widow, ///
   add(5) burnin(20) force

eststo: mi estimate, post: ologit spanking female black income educ nodoubt nochild age east midwest south nevmar divsep widow
restore

preserve
mi set mlong
mi register imputed spanking female black income educ nodoubt nochild age east midwest south nevmar divsep widow

drop if missing(spanking)
mi impute chained (mlogit) spanking (regress) income educ (logit) nodoubt nochild = female black age east midwest south nevmar divsep widow, ///
   add(5) burnin(20) force

eststo: mi estimate, post: ologit spanking female black income educ nodoubt nochild age east midwest south nevmar divsep widow
restore

esttab, wide se keep(spanking:) nonumbers modelwidth(15) ///
  mtitle("Listwise deletion" "Normal data augmentation" "Sequential regression" "Seq. regression w/out missings") ///
  title(Coefficient estimates and standatd errors for cumulative logit models predicting SPANKING)

Reference

Allison, Paul D. 2002. Missing Data. Sage. doi: 10.4135/9781412985079