Statalist The Stata Listserver

[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: simulation and MICE

From   "Eugenia Priedane" <>
To   <>
Subject   st: simulation and MICE
Date   Tue, 22 May 2007 15:23:59 +0100

Dear Statalisters, 
I'm having some trouble running a simulation.
I'm using the command simulate to run a series of regressions/ extract
the estimates.
The problem is I want to use the MICE command to impute some missing
data and then collect the results.
However, when I implement the MICE command (see the */ section below)
I 'lose' the simulation datasets, the only output that is kept is from
the last run of the mice imputation.

I think the problem is that because MICE requires a 'using' dataset to
be created, the simulations are over written.

I'm sure there is something to be added to tell the program to drop
the mice using dataset, and carry on with the simulation, but i can't
think what, putting clear in does not seem to work.
Any help would be greatly appreciated.

Many thanks,

set more off
set seed 10
program define montecarlo, rclass
version 9
args c
drop _all
set obs 500
matrix m=(1200,1200,0.6)
matrix sd=(200,200,0.2)
matrix c=(1,0.8,0.2\0.8,1,0.2\0.2,0.2,1)
drawnorm paccos refcos org, means (m) sds (sd) corr(c)

gen truth=`c'*paccos
summ paccos
gen meanp=_result(3)
gen paccosc=paccos-meanp
summ refcos
gen meanr=_result(3)
gen refcosc=refcos-meanr

*** sorting MAR ***
gen paccos2=paccos
gen pmar=1/(1+exp(-0.5*refcosc))
sort pmar
replace paccos2=. in 1/250
summ paccos2
gen meanar=_result(3)
gen pacosmeanar=paccos2
replace pacosmeanar=meanar if paccos2==.

*** true estimates ***
regress truth
gen true1=_b[_cons]
gen true2=_se[_cons]

*** conditional mean ***
xi: regress paccos2 refcos
predict predpacar
replace predpacar=paccos2 if paccos2~=.

summ true1
return scalar trum=r(mean)

summ true2
return scalar truse=r(mean)

*** conditional mean ***
regr predpacar
gen mar21=_b[_cons]
gen mar22=_se[_cons]

summ mar21
return scalar marcmean=r(mean)

summ mar22
return scalar marcse=r(mean)

gen pacmicear=paccos2
ice pacmicear refcos using impar, m(5) seed (10) replace
use impnar, clear
micombine regr pacmicenar 

montecarlo 1
simulate "montecarlo 1" trum=r(trum) truse=r(truse)
marcmean=r(marcmean) marcse=r(marcse), reps(10)
program drop montecarlo

Eugenia Priedane
Department of Public Health & Policy
London School of Hygiene and Tropical Medicine 
Keppel Street 
London, WC1E 7HT
Tel: (+44 or 0) 207 927 2671
Fax: (+44 or 0) 207 580 8183

*   For searches and help try:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index