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
[email protected] (Jeff Pitblado, StataCorp LP)
To
[email protected]
Subject
Re: st: running marginsplots without rerunning margins again
Date
Fri, 12 Aug 2011 15:05:35 -0500
Doug Hess <[email protected]> is using -margins- and -marginsplot-, and
has some questions about working with -margins- results.
> I just installed Stata 12 and am playing with the "marginsplot"
> command. I am wondering how to run margins plot on a restored margins?
> Can it? Complex margins commands can take a long time to run. Is there
> a way to restore or use saved results from a complex running of
> margins so that I can fiddle with the graph later?
>
> Come to think of it, how do I redisplay results from a margins command
> after "restoring" a stored file or "using" a saved file. For
> regression estimates you just type regress and it shows it. How is
> this done for other saved files.
Scott Merryman <[email protected]> mentioned using -_return hold- and
-_return restore- which solved Doug's orginial question.
Richard Williams <[email protected]> also had a solution, but it
didn't work as expected.
> I thought it would simply be a matter of using the -post- option of
> margins and the -est store- and -est restore- commands. To my
> surprise, though, the following produces an error at the end:
>
> clear all
> sysuse auto
> reg price mpg i.foreign
> margins foreign, post
> est store margins1
> marginsplot
> reg price mpg i.foreign weight
> est restore margins1
> margins
> marginsplot
>
> The error is "previous command was not margins." But if you do
> -ereturn list-, it does say the last command was -margins-. I am
> surprised it doesn't work, and I wonder if this is a bug or if there
> is some good reason for this.
We agree with Richard on this and plan to make -marginsplot- recognize the
-e()- results posted by -margins, post- in a future ado-file update.
Later in the thread, Richard wrote:
> Personally, my wish would be (for Stata 12.1?) that when you use the -post-
> option on -margins-, you would be able to use the ereturned results the same
> way as you can with any estimation command. e.g. replay them, save them,
> restore them, run post-estimation commands after restoring. I can't think of
> another command that requires you to store or save the returned results as
> well.
We are not sure which features Richard feels are missing.
When the -post- opton is used with -margins-, the following standard
estimation command features are also available for -margins-:
* replay -margins- results
* -estimates store- and -estimates restore- works
* -estimates save- and -estimates use- works
* -test-, -lincom-, -testnl-, -nlcom-, and all other standard
postestimation commands work with the posted -margins- results
The following example works in Stata 11 and Stata 12:
Load some data:
. sysuse auto
Fit a model, compute some margins with -post-, and store the margins results:
. regress mpg i.foreign
. margins for, post
. est store margins1
Do it again with a different model:
. regress mpg i.rep78
. margins rep, post
. est store margins2
Restore the first set of -margins- results, replay them, then use -test-:
. est restore margins1
. margins
. test 0.for = 1.for
--Jeff
[email protected]
*
* 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/