Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

RE: st: running marginsplots without rerunning margins again


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   RE: st: running marginsplots without rerunning margins again
Date   Fri, 12 Aug 2011 16:58:38 +0100

The aim is one we can sympathise with, but broadly "do something else in between" cannot include running an estimation command. So, either don't do that, or store the results. Just the way that Stata works! 

Nick 
[email protected] 


-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Doug Hess
Sent: 12 August 2011 16:11
To: [email protected]
Subject: Re: st: running marginsplots without rerunning margins again

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

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 <[email protected]>
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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index