I don't immediately see where the problem is in your example, but I had
another simulation of -ice- hanging around, which does work. It is
below:
*------------- begin example ------------------
set seed 12345
capture program drop sim
program define sim, rclass
drop _all
tempfile temp
set obs 500
gen x1 = invnorm(uniform())
gen x2 = x1 + 2*invnorm(uniform())
gen y = x1 + x2 + invnorm(uniform())
gen Px1 = invlogit(-3 + y)
gen Px2 = invlogit(-3 + y)
replace x1 = . if Px1 > uniform()
replace x2 = . if Px2 > uniform()
reg y x1 x2
return scalar b0cc = _b[_cons]
return scalar b1cc = _b[x1]
return scalar b2cc = _b[x2]
ice y x1 x2 using `temp', m(5)
use `temp', clear
micombine regress y x1 x2
return scalar b0mi = _b[_cons]
return scalar b1mi = _b[x1]
return scalar b2mi = _b[x2]
end
simulate sim b0cc=r(b0cc) b1cc=r(b1cc) b2cc=r(b2cc) b0mi=r(b0mi)
b1mi=r(b1mi) b2mi=r(b2mi), reps(100) dots
sum
twoway kdensity b0cc || kdensity b0mi, xline(0) name(cons)
twoway kdensity b1cc || kdensity b1mi, xline(1) name(b1)
twoway kdensity b2cc || kdensity b2mi, xline(1) name(b2)
*--------------- end example ------------
--- Eugenia Priedane <[email protected]> wrote:
> 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,
> Eugenia
>
> set more off
> set seed 10
> program define montecarlo, rclass
> version 9
> args c
> clear
> 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
> */
>
> end
> montecarlo 1
> simulate "montecarlo 1" trum=r(trum) truse=r(truse)
> marcmean=r(marcmean) marcse=r(marcse), reps(10)
> sum
> 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
> Email: [email protected]
>
> *
> * For searches and help try:
> * http://www.stata.com/support/faqs/res/findit.html
> * http://www.stata.com/support/statalist/faq
> * http://www.ats.ucla.edu/stat/stata/
>
-----------------------------------------
Maarten L. Buis
Department of Social Research Methodology
Vrije Universiteit Amsterdam
Boelelaan 1081
1081 HV Amsterdam
The Netherlands
visiting address:
Buitenveldertselaan 3 (Metropolitan), room Z434
+31 20 5986715
http://home.fsw.vu.nl/m.buis/
-----------------------------------------
___________________________________________________________
Yahoo! Mail is the world's favourite email. Don't settle for less, sign up for
your free account today http://uk.rd.yahoo.com/evt=44106/*http://uk.docs.yahoo.com/mail/winter07.html
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/