/******************* nonlinear.do Example file demonstrating the difficulties of imputing variables that enter the analysis non-linearly. 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 1000 set seed 4409 gen x=(invnorm(runiform())) gen y=x+x^2+(invnorm(runiform())) // drop values at random replace x=. if runiform()<.1 replace y=. if runiform()<.1 // complete cases analysis reg y c.x##c.x // imputation model for x is mispecified reg x y rvfplot graph export nonlinear.png, replace preserve // impute x, treat x^2 as passive function of x // result would be same if we actually used mi passive mi set wide mi register imputed x y mi impute chained (regress) x y, add(10) mi estimate: reg y c.x##c.x restore preserve // impute x with pmm, treat x^2 as passive mi set wide mi register imputed x y mi impute chained (pmm) x (regress) y, add(10) mi estimate: reg y c.x##c.x restore preserve // impute x, add x^2 term to imputation model for y // note that imputation model for x is still linear mi set wide mi register imputed x y mi impute chained (regress) x (regress, include((x^2))) y, add(10) mi estimate: reg y c.x##c.x restore preserve // Create x2 variable and impute it sepately from x gen x2=x^2 mi set wide mi register imputed x y x2 mi impute chained (regress) x x2 y, add(10) mi estimate: reg y x x2 restore // Create x2 variable and impute it sepately from x using PMM gen x2=x^2 mi set wide mi register imputed x y x2 mi impute chained (pmm) x x2 (regress) y, add(10) mi estimate: reg y x x2