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.