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 on April 23, and its replacement, is already up and running.

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

Re: st: predicted marginal effects for sample

From   Richard Williams <>
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:  Richard.A.Williams.5@ND.Edu

*   For searches and help try:

© Copyright 1996–2015 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index