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]

st: Ploting marginal effects extracted with -nlcom- when -margins- isn't an option (and therefore marginsplot as well)


From   Suyin Chang <[email protected]>
To   [email protected], [email protected]
Subject   st: Ploting marginal effects extracted with -nlcom- when -margins- isn't an option (and therefore marginsplot as well)
Date   Thu, 16 Jan 2014 02:50:21 -0500

Dear Statalist,

In the last days I've found a past reply from Mark Schaffer (and I've
asked some follo-ups myself) on how to extract marginal effects of
interactions in models fitted with -ivreg2-, as this command is not
yet integrated to -margins-.

So, Mark gave an easy workaround with -nlcom- that may be quite useful
in many cases of commands that do not work with -margins-:

   sysuse auto, clear
   gen mpgturn=mpg*turn

   regress price mpg turn mpgturn
   forvalues x=31(1)51 {
           nlcom _b[mpg] + _b[mpgturn]*(`x')
   }

The only problem is while -margins- makes it very straight-forward to
plot the marginal effects through -marginsplot-, the above solution
using -nlcom- of course does not have such facility.

In that case, would any of you have a clean suggestion on how to
transform those individually extracted marginal effects into a nice
marginal effects plot? I really do think that such a graphical
solution, together with simple workarounds as this from Mark's, would
improve quite a bit the usage of many models and commands, as well as
save a lot of trouble from people in many different situations.

I thank you in advance for any effort you may put on this.

Suyin




2014/1/14 Schaffer, Mark E <[email protected]>:
> Suyin,
>
>> -----Original Message-----
>> From: Suyin Chang [mailto:[email protected]]
>> Sent: 14 January 2014 06:19
>> To: [email protected]; Schaffer, Mark E
>> Subject: Re: st: RE: Re: Marginal effects after ivreg2
>>
>> Dears Jana and Mark,
>>
>> Very interesting question, followed by a promising reply.
>> However, I would like to ask two quick follow-up questions, if I may.
>>
>> The first problem is I don't get how to mimic -margins- with -nlcom- after
>> ivreg2 in case we want a linear plot. For instance, how to mimic something
>> like margins, dydx(mgp) at(turn=(start(by)end)), where start is the first value
>> and end is the last value of the variable turn to be considered? That appears
>> to me as something less intuitive to achieve.
>
> This is also easy to do - all you need to do is loop through the values and apply -nlcom- each time.  Here is a modified version of my original example with -regress-:
>
> sysuse auto, clear
> gen mpgturn=mpg*turn
>
> regress price mpg turn mpgturn
> forvalues x=31(1)51 {
>         nlcom _b[mpg] + _b[mpgturn]*(`x')
> }
>
> regress price mpg turn c.mpg#c.turn
> margins, dydx(mpg) at(turn=(31(1)51))
>
>> And the second thing is to ask if there is a way to easily plot those results
>> such as marginsplot does with margins saved output.
>
> Maybe someone else has some suggestions here...?
>
> --Mark
>
>
>> Any suggestions would be very much appreciated, as I am facing the same
>> need as Jana in the original question, i.e. I need to generate a marginal
>> effects plot for an interaction between the endogenous explanatory variable
>> and a exogenous explanatory variable (both continuous).
>>
>> Thanks,
>>
>> Suyin
>>
>>
>>
>>
>>
>> 2013/12/26 Schaffer, Mark E <[email protected]>:
>> > Jana,
>> >
>> > -ivreg2- doesn't (yet - we really need to add this in!) support -margins-.  But
>> an easy workaround is to use -nlcom- with -ivreg2-.
>> >
>> > Below is an example of how to use -nlcom- to mimic -margins- to calculate
>> marginal effects and CIs when you have an interaction.
>> >
>> > HTH,
>> > Mark
>> >
>> > sysuse auto, clear
>> > gen mpgturn=mpg*turn
>> > regress price mpg turn mpgturn
>> > qui sum turn, meanonly
>> > nlcom _b[mpg] + _b[mpgturn]*(`r(mean)') qui sum mpg, meanonly nlcom
>> > _b[turn] + _b[mpgturn]*(`r(mean)') regress price mpg turn c.mpg#c.turn
>> > margins, atmeans dydx(*)
>> >
>> >> -----Original Message-----
>> >> From: [email protected] [mailto:owner-
>> >> [email protected]] On Behalf Of Jana von Stein
>> >> Sent: 26 December 2013 01:59
>> >> To: <[email protected]>
>> >> Subject: st: Re: Marginal effects after ivreg2
>> >>
>> >> Hello,
>> >>
>> >> I need to run margins (or calculate marginal effects with ci's) after
>> >> ivreg2. I have an endogenous interaction and want to calculate the
>> >> marginal effect (w/
>> >> ci's) after ivreg2. Does anyone know how to do this? Margins did not
>> >> seem to work after ivreg2.
>> >>
>> >> Thanks, and happy holidays.
>> >> Jana
>> >>
>> >>
>> >>
>> >>
>> >> *
>> >> *   For searches and help try:
>> >> *   http://www.stata.com/help.cgi?search
>> >> *   http://www.stata.com/support/faqs/resources/statalist-faq/
>> >> *   http://www.ats.ucla.edu/stat/stata/
>> >
>> >
>> > -----
>> > Sunday Times Scottish University of the Year 2011-2013 Top in the UK
>> > for student experience Fourth university in the UK and top in Scotland
>> > (National Student Survey 2012)
>> >
>> > We invite research leaders and ambitious early career researchers to
>> > join us in leading and driving research in key inter-disciplinary themes.
>> > Please see www.hw.ac.uk/researchleaders for further information and
>> > how to apply.
>> >
>> > Heriot-Watt University is a Scottish charity registered under charity
>> > number SC000278.
>> >
>> >
>> > *
>> > *   For searches and help try:
>> > *   http://www.stata.com/help.cgi?search
>> > *   http://www.stata.com/support/faqs/resources/statalist-faq/
>> > *   http://www.ats.ucla.edu/stat/stata/
>
>
> -----
> Sunday Times Scottish University of the Year 2011-2013
> Top in the UK for student experience
> Fourth university in the UK and top in Scotland (National Student Survey 2012)
>
>
> We invite research leaders and ambitious early career researchers to
> join us in leading and driving research in key inter-disciplinary themes.
> Please see www.hw.ac.uk/researchleaders for further information and how
> to apply.
>
> Heriot-Watt University is a Scottish charity
> registered under charity number SC000278.
>
>
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/statalist-faq/
> *   http://www.ats.ucla.edu/stat/stata/
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index