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: predicted marginal effects for sample


From   Richard Williams <[email protected]>
To   [email protected], [email protected]
Subject   Re: st: predicted marginal effects for sample
Date   Sun, 04 Dec 2011 21:50:18 -0500

At 09:18 PM 12/4/2011, john sanders wrote:
Thank you Steve,

Unfortunately, I was not able to find a solution in the help file or
manual, which is why I am asking here.

I simply want to generate a variable which contains the predicted
marginal effect of model.

For the linear prediction, I would simply type:
reg demand c.distance##c.price##c.price
predict demand_hat, xb

I want to do something similar for the marginal effect of price:
reg demand c.distance##c.price##c.price
margins , dydx(price)

To calculate the predictive margins, I could simply generate a new variable:
gen demand_change=distance*_b[c.distance#c.price]+2*price*_b[c.price#c.price]+2*distance*price*_b[c.distance#c.price#c.price]

I was simply wondering if margins had this automated.

Not automated, but not hard.

webuse auto, clear
clonevar xmpg = mpg
sum xmpg
gen delta = r(sd)/1000
reg price c.trunk##c.weight##c.xmpg
margins, dydx(xmpg)
predict p1
replace xmpg = xmpg + delta
predict p2
gen mfxmpg = (p2-p1)/delta
sum mfxmpg

Tweak the code a little if missing data is an issue.


-------------------------------------------
Richard Williams, Notre Dame Dept of Sociology
OFFICE: (574)631-6668, (574)631-6463
HOME:   (574)289-5227
EMAIL:  [email protected]
WWW:    http://www.nd.edu/~rwilliam

*
*   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