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 at the end of May, 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   Nick Cox <n.j.cox@durham.ac.uk>
Subject   Re: st: running marginsplots without rerunning margins again
Date   Fri, 12 Aug 2011 12:43:12 -0400

Actually, my lack of sleep is the cause of the fuzziness I fear. I
should come back to this later, but I  did want to note that I screwed
up Scott's code. It does work, see below.

Perhaps what I am really asking for is a way to permanently save the
information that is stored in the line - _return hold foo -. The
manual says that - _return hold -  saves the information, but I was
hoping it could be restored at a future date and pick up where one
stopped. I don't see why that is such a complex thing, but perhaps it
is just not there yet, or I don't understand what I am asking for.


clear*
webuse nhanes2
regress bpsystol agegrp##sex
estimates save foo,replace
margins agegrp
_return hold foo

	sysuse auto ,clear /* something else*/
	regress price i.rep
	margins rep

webuse nhanes2,clear
est use foo
estimates esample:
_return restore foo
marginsplot

- Doug

On Fri, Aug 12, 2011 at 12:28 PM, Nick Cox <n.j.cox@durham.ac.uk> wrote:
> I am still a bit fuzzy on what you are seeking. It is a bit of a tall order for any  command (plotting or otherwise) that depends on saved results to expect it to work again if the same saved results are not present when it is invoked. If this is arranged for one command, then why not for all such? The solution would be unbearable, I suspect.
>
> Whether there is a way to make this work for -marginsplot- is I think a question for StataCorp. In practice users (me too) might often want what you want, but I don't think  the principle is good.
>
> Nick
> n.j.cox@durham.ac.uk
>
> Doug Hess
>
> Obviously, I thought, I didn't mean that you should not store or save
> the results. I show in the examples that I am using the two techniques
> suggested so far for storing or saving (ideally saving for the reasons
> give). I just show that I cannot get the stored or save results to be
> re-used by marginsplot (althought as Scott demonstrated, you can use
> other graphing commands...just less elegant and I was hoping to  us
> the marginsplot commands). See what I mean? Sorry if I was not clear.
>
> On Fri, Aug 12, 2011 at 11:58 AM, Nick Cox <n.j.cox@durham.ac.uk> wrote:
>
>> 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
>> n.j.cox@durham.ac.uk
>>
>>
>> -----Original Message-----
>> From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Doug Hess
>> Sent: 12 August 2011 16:11
>> To: statalist@hsphsun2.harvard.edu
>> 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:  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