Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Thomas <tpt21@cam.ac.uk> |
To | statalist@hsphsun2.harvard.edu |
Subject | Re: st: margins at every observation |
Date | Tue, 12 Oct 2010 16:47:03 +0100 |
derivate at various (virtual) cases but not for all observed cases? Thomas On 12/10/2010 16:23, Richard Williams wrote:
At 08:49 AM 10/12/2010, Thomas wrote:I want to calculate the marginal effects for all observations: sysuse auto, clear reg price c.mpg##c.mpg gen dydx = _b[mpg]+2*_b[ c.mpg#c.mpg]*mpg I thought I would get the same using: margins, dydx(mpg) at((asobserved) mpg) but I only get a single value at the mean of mpg.How can I get the marginal effect at each observation from -margins- (if at all)?Both approaches are giving you the same result. You aren't getting a single value at the mean of mpg, you are getting the average marginal effect. Tweaking your code slightly,sysuse auto, clear reg price c.mpg##c.mpg gen dydx = _b[mpg]+2*_b[ c.mpg#c.mpg]*mpg sum dydx margins, dydx(mpg) at((asobserved) mpg) The last command can be simplified to margins, dydx(mpg)Unfortunately, margins does not have a way to generate new variables, so if you want a marginal effect for each case (rather than just the average of those marginal effects) you have to do something like what you did.------------------------------------------- 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 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/
* * 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/