/******************* nonnormal.do Example file demonstrating the how PMM can fit non-normal data better than regression Written by Russell Dimond, Summer 2012 for the Social Science Computing Cooperative at UW-Madison ********************/ clear all set more off // create random data set obs 10000 set seed 4409 gen x=invnorm(runiform()) gen g=(runiform()>.5) replace x=x+5 if g gen y=x+invnorm(runiform()) replace x=. if runiform()<.2 replace y=. if runiform()<.2 misstable sum, gen(m_) // complete cases analysis reg y x // distribution of observed values of x kdensity x graph export nonnormal1.png, replace preserve // impute using regression mi set wide mi register imputed x y mi impute chained (regress) y x, add(10) mi estimate: reg y x // note that x is nonnormal, but doesn't match well // it's "too normal" mi xeq 1: kdensity x if m_x graph export nonnormal2.png, replace restore preserve // impute using PMM mi set wide mi register imputed x y mi impute chained (regress) y (pmm) x, add(10) mi estimate: reg y x mi xeq 1: kdensity x if m_x graph export nonnormal3.png, replace restore preserve // impute using regression but with separate groups mi set wide mi register imputed x y mi impute chained (regress) y x, add(10) by(g) mi estimate: reg y x mi xeq 1: kdensity x if m_x graph export nonnormal4.png, replace