Page 1 of 1

Running margins on predictions from a runmlwin model fit

Posted: Thu Oct 28, 2021 2:07 pm
by erikruzek
Hi all,

I have been trying to figure out how to use runmlwin and Stata's margins command in combination. I know, based on reading other posts in the forum, that I can do something similar to margins by setting variables in the model to certain values and then running predict after runmlwin. This seems reasonable for many cases.

However, I am working with multiply imputed data (20 datasets) and the idea of having to do this procedure along with all the mi procedures is not terribly appealing. Although it might be easier than I am imagining! Instead, I have been playing with a workaround and wanted to get your thoughts on it. First, I run a model, then get predictions (xb) and stdps for that model (not altering the values of variables), and then I run mimrgns (user-written package for getting margins with MI data) on the xb and stdps. Below is the code I'm using:

Code: Select all

mi estimate, cmdok  saving(miest4): runmlwin enjoy year male langspan langother cons, ///
	level2(childid: year cons) level1(obs: cons) nopause 
eststo mlwin_gc_lang_sex

mi predict xb using miest4 // marginal predictions for year
mi predict xb_se using miest4, stdp // standard errors for marginal predictions 

** Margins on predictions
mi estimate: reg xb year i.homelang i.male
mimrgns i.homelang, at(year=(0(1)2)) dots cmdmargins // cmdmargins needed for marginsplot
_marg_save , saving(mimrgns_results , double) // _at with _m1 identifies unique marg effs

** Margins on standard errors
mi estimate: reg xb_se year i.homelang i.male
mimrgns i.homelang, at(year=(0(1)2)) dots cmdmargins 
_marg_save , saving(mimrgns_se_results , double replace) 

Once I have the two saved files, I can pull them into Stata for graphing.

What do you think of the validity of this approach? I can confirm that the margins I get from this are euqivalent to at least 2 decimal points to those from mimrgins after running the same model in mixed. The standard errors are also very close.

Admittedly this involves a lot of steps, so again, it might be just as easy or easier to try to get margins by creating some new observations and doing predictions for those.

Re: Running margins on predictions from a runmlwin model fit

Posted: Mon Nov 01, 2021 11:46 am
by ChrisCharlton
I showed this to George, but he wasn't able to say for sure.

His advice was that unless the models ran too slowly or couldn't be fitted with mixed you should use that. If you can't do that then he suggests initially running a subsample or simplified version of your model using both mixed and your manual method with runmlwin and checking that they give the same answers. If so you can then proceed to running the full model.

In terms of the checks you have done so far he thought they looked positive and are similar to the approach that he would take.

Re: Running margins on predictions from a runmlwin model fit

Posted: Mon Nov 01, 2021 2:20 pm
by erikruzek
Much appreciated, Chris and George. I hope you both are doing well!

Re: Running margins on predictions from a runmlwin model fit

Posted: Wed May 03, 2023 2:59 am
by Mira23ssw
ChrisCharlton wrote: Mon Nov 01, 2021 11:46 am I showed this to George, but he wasn't able to say for sure.

His advice was that unless the models ran too slowly or couldn't be fitted with mixed you should use that. If you can't do that then he suggests initially running a subsample or simplified version of your model using both mixed and your manual method with runmlwin and checking that they give the same answers. If so you can then proceed to running the full model.

In terms of the checks you have done so far he thought they looked positive and are similar to the approach that he would take.
It's very helpful, thanks

Re: Running margins on predictions from a runmlwin model fit

Posted: Wed Dec 20, 2023 4:29 am
by lisamassa
Your approach seems reasonable, especially when dealing with multiple imputed rice purity test data. It's good to hear that the margins and standard errors are close to those from the margins after running the same model in mixed. However, if the process involves a lot of steps, it might be worth considering alternative methods to achieve the same results.

Re: Running margins on predictions from a runmlwin model fit

Posted: Thu Feb 01, 2024 1:49 am
by tetroupploy
Chris and George, you are very much appreciated. I am hoping that both of you are being well :mrgreen: geometry dash lite