Saving estimates from models (using MCMC) executed using runmlwin
Posted: Wed Nov 24, 2021 4:16 am
Hello, and apologies in advance if my query is not properly explained as this is my first time posting here. I have a query relating to the proper way to save/store results (ideally in Stata) from a model run using MCMC estimation, executed by the runmlwin command, so that I can use the results in a later Stata session. The reason I am asking is that with the syntax I am currently using, when I restore my saved estimates in a later Stata session, I notice they are different than what is displayed in my Stata log file (the original Stata session, when I ran the runmlwin command). I realise this query touches on a bit of Stata syntax, but I suspect the crux of the issue is that there is something missing from my runmlwin command, or perhaps something I am not quite grasping about how runmlwin works when retrieving estimates from a model using MCMC estimation.
Here's what I did:
Within Stata, I used the runmlwin command to run a series of multilevel models using nested loops. I started with MQL1 estimation, then PQL2, and used the PQL2 estimates as inputs for the MCMC model. After each MCMC model was run, I used Stata’s ‘estimates store’ command to store the model estimates:
I then saved the MCMC model estimates as ‘.ster’ files, by first restoring each model (using Stata’s ‘estimates restore’ command) and then saving (using Stata’s ‘estimates save’). After they were saved, I cleared the estimates.
The commands I am using to display the stored estimates in my later Stata sessions are for example:
And to display them in exponentiated form, I use ‘ereturn display’, for example:
However, ‘ereturn display’ yields different results from the estimates in my Stata log file (which are also in exponentiated/odds ratio form). I manually exponentiated the results from ‘estimates replay’ and the results are the same as those from ‘ereturn display’ – but therefore, also don’t match the log file results. Interestingly though, all of the other details (e.g., run time, dbar, thetabar, effective no. of parameters, Bayesian DIC) are identical across the stored estimates and log file estimates.
Is this the proper way to go about saving the results from an MCMC model executed using runmlwin, so that I can retrieve them in later Stata sessions (or, is there another way to do this)? Have I missed something important about how MCMC estimates retrieved by runmlwin need to be saved?
Thanks very much for your advice, it is much appreciated.
Amanda
Here's what I did:
Within Stata, I used the runmlwin command to run a series of multilevel models using nested loops. I started with MQL1 estimation, then PQL2, and used the PQL2 estimates as inputs for the MCMC model. After each MCMC model was run, I used Stata’s ‘estimates store’ command to store the model estimates:
Code: Select all
foreach y of varlist EX IN CO {
foreach x of varlist pos4 pos8 {
forvalues i = 1/8 {
runmlwin `y' cons i.`x' gender01 i.langcat atsi specialneeds i.m_educat3 if capcity==`i', ///
level2(sa1_maincode_2016:cons) ///
level1(record_id) discrete(distribution(binomial) link(logit) denom(cons) ///
mql1) igls nopause or mlwinpath("C:\Program Files\MLwiN v3.04\mlwin.exe")
runmlwin `y' cons i.`x' gender01 i.langcat atsi specialneeds i.m_educat3 if capcity==`i', ///
level2(sa1_maincode_2016:cons) ///
level1(record_id) discrete(distribution(binomial) link(logit) denom(cons) ///
pql2) initsprevious igls nopause or mlwinpath("C:\Program Files\MLwiN v3.04\mlwin.exe")
runmlwin `y' cons i.`x' gender01 i.langcat atsi specialneeds i.m_educat3 if capcity==`i', ///
level2(sa1_maincode_2016:cons) ///
level1(record_id) discrete(distribution(binomial) link(logit) denom(cons)) ///
mcmc(chain(20000)) initsprevious igls nopause or mlwinpath("C:\Program Files\MLwiN v3.04\mlwin.exe")
estimates store Ch_`x'_`y'_`i'
mcmcsum, detail
mcmcsum, trajectories
graph export Ch_`x'_`y'_`i'.png, as(png) replace
}
}
}
Code: Select all
foreach y of varlist EX IN CO {
foreach x of varlist pos4 pos8 {
forvalues i = 1/8 {
estimates restore Ch_`x'_`y'_`i'
estimates save Ch_`x'_`y'_`i', replace
}
}
}
estimates clear
Code: Select all
estimates use Ch_pos8_EX_3
estimates store Ch_pos8_EX_3
estimates restore Ch_pos8_EX_3
estimates replay
Code: Select all
ereturn display, eform(_2_pos8 _3_pos8)
Is this the proper way to go about saving the results from an MCMC model executed using runmlwin, so that I can retrieve them in later Stata sessions (or, is there another way to do this)? Have I missed something important about how MCMC estimates retrieved by runmlwin need to be saved?
Thanks very much for your advice, it is much appreciated.
Amanda