Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: running marginsplots without rerunning margins again


From   Doug Hess <douglasrhess@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: running marginsplots without rerunning margins again
Date   Fri, 12 Aug 2011 11:10:37 -0400

discussion. Also, if you have a solution and can cc me on your email
to the list, that would be great:  douglasrhess@gmail.com ]

Ok. I couldn't get Scott's suggestion to work with -marginsplot- if I
had commands in between running the margin and running the
marginsplot.  The following produces the "previous command was not
margins
r(301); " statement:

clear*
webuse nhanes2
regress bpsystol agegrp##sex if region ==4
margins agegrp, saving(mymargins,replace)
tab agegrp /* do something in between -margins- and -marginsplot-;
ideally exiting and restarting Stata even */
use mymargins
marginsplot

I also couldn't get the earlier suggestion to work in the code below
(I thought I had it working the other day...so sorry for the
flip-flop...not sure what is different). This gives the same error
statement as above:

clear*
webuse nhanes2
regress bpsystol agegrp##sex if region ==4
est save filenameA, replace
_return hold filenameA
tab agegrp /* do something in between margins and marginsplot*/
est use filenameA
estimates esample:
_return restore filenameA
marginsplot

Recall that the goal is to run -margins-, do something else, and then
be able to run -marginsplot- without having to rerun the margins
again.  Note bien: Ideally that something else should even be exiting
Stata and restarting since the point is to not have to run complex
marginal analysis all over (the dydx option, for instance, can take 40
minutes on my one year old laptop with Stata 12/IC on a 100 000
household dataset).

Thanks to all for their help with this. Please bcc me on any response
as I am in the digest mode.

-Doug

Date: Thu, 11 Aug 2011 11:16:03 -0400
From: Richard Williams <richardwilliams.ndu@gmail.com>
Subject: Re: st: running marginsplots without rerunning margins again

At 10:39 AM 8/11/2011, Scott Merryman wrote:
>There is an easier way.
>
>-margins- has an undocumented saving() option
>
>clear*
>webuse nhanes2
>regress bpsystol agegrp##sex if region ==4
>margins agegrp, saving(mymargins,replace)
>clear*
>use mymargins
>l
>line _mar _m1,  lc(black)  ///
>   || rcap _ci_u _ci_l _m1, lc(black) ///
>   ||, legend(off)  xlabel(, valuelabel) ytitle(Linear Prediction)

Interesting. You aren't using marginsplot, but I guess you have the
whole arsenal of graphics commands at your disposal.

With a little tweaking, this also works with Stata 11.2. You just
substitute agegrp for _m1.

version 11.2
clear*
webuse nhanes2
regress bpsystol agegrp##sex if region ==4
margins agegrp, saving(mymargins,replace)
clear*
use mymargins
l
line _mar agegrp,  lc(black)  ///
  || rcap _ci_u _ci_l agegrp, lc(black) ///
  ||, legend(off)  xlabel(, valuelabel) ytitle(Linear Prediction)

Run that same code under Stata 12, though, and you get an error, i.e.
it doesn't seem to respect the version control. So, this may be a use
at your own risk, i.e. the code isn't guaranteed to work the same way
in the future.
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index