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   Steve Samuels <[email protected]>
To   [email protected]
Subject   Re: st: predicted marginal effects for sample
Date   Sun, 4 Dec 2011 21:49:29 -0500

Your example makes your request clearer.  I'm not sure, but maybe something like this:

***************************
sysuse auto, clear
gen obs = _n
reg mpg c.weight##c.price
margins, dydx(price) over(obs) post
****************************

I think the quantities you want will be in e(b), and you will have to convert these to Stata variables with -getmata- and -merge- them back into your data set.


Steve



On Dec 4, 2011, at 9:18 PM, 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.




On Sun, Dec 4, 2011 at 8:29 PM, Steve Samuels <[email protected]> wrote:
> No, it is not possible with -predict-, at least not without a lot of work.  Yes it is possible with -margins-. The -help- and manual will show you how.
> 
> Steve
> 
> On Dec 4, 2011, at 6:31 PM, john sanders wrote:
> 
> I am running a simple linear regression model with some interaction
> terms of the following nature:
> 
> reg demand c.distance##c.price##c.price
> 
> I want to use the model parameters to predict the marginal effect of a
> price change for every observation in the data (i.e. instead of the
> linear prediction, I want the marginal effect for each observation).
> 
> Is this possible using the margins command? I could certainly code
> this up, but I was wondering if there was a "predict" analogue to the
> margins command.
> *
> *   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/
> 
> 
> *
> *   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/

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


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