local notimputable: subinstr global notimputable " " ", ", all

use ISO country oecd year ln_IHMEviolentdeaths i_ln_pris USA $imputable $notimputable ///
	if year==2005 & (!mi(ln_IHME) | !mi(i_ln_pris)) & !mi(`notimputable') using paneldata.dta, clear
drop year
xtset, clear
capture: stset, clear

local imputed ""
local complete ""
foreach var of varlist $imputable {
	quietly misstable sum `var'
	if r(N_eq_dot)!=. local imputed "`imputed' `var'"
	else local complete "`complete' `var'"
	}

** MULTIPLE IMPUTATION **

mi set wide
mi register imputed `imputed'
mi register regular ln_IHMEviolentdeaths i_ln_pris USA $notimputable `complete'

mi impute chained (regress) `imputed' = ln_IHMEviolentdeaths $notimputable `complete' if ISO!="USA" & mi(ln_IHME)==0, add($imputations) rseed(2138) bootstrap
mi impute chained (regress) `imputed' = i_ln_pris $notimputable `complete' if ISO!="USA" & mi(i_ln_pris)==0, add($imputations) rseed(2138) bootstrap
mi impute chained (regress) `imputed' = ln_IHMEviolentdeaths i_ln_pris $notimputable `complete' if ISO!="USA" & mi(i_ln_pris, ln_IHMEviolentdeaths)==0, add($imputations) rseed(2138) bootstrap

save MIdataset, replace
