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: margins at every observation


From   Richard Williams <[email protected]>
To   [email protected]
Subject   Re: st: margins at every observation
Date   Tue, 12 Oct 2010 12:44:47 -0500

At 11:01 AM 10/12/2010, Maarten buis wrote:
That marginal effect only depends on the value of mpg, so
you can get a complete list of all marginal effects by typing:

margins, dydx(mpg) over(mpg)

There is no -generate- or -replace- option in -margins, so there
is no easy way to turn this into a variable (it is possible, but
your manual computations are just easier).

That is clever, but am I correct in saying that kind of trick will not work in most situations? I still want a generate option in -margins-. It is the main feature from the old -adjust- command that has not carried over to -margins-.

Cameron and Trivedi show how to compute AMEs manually. The procedure is outlined in section 10.6.10. You would have to tweak the procedure to make sure that things like interaction terms and squared terms get handled correctly. See

http://www.stata.com/bookstore/musr.html

The code (which can be downloaded from that page) is

* AME computed manually for a single regressor
use mus10data.dta, clear
keep if year02 == 1
quietly poisson docvis private chronic female income, vce(robust)
preserve
predict mu0, n
quietly replace income = income + 0.01
predict mu1, n
generate memanual = (mu1-mu0)/0.01
summarize memanual
restore

* AME computed manually for all regressors
global xlist private chronic female income
preserve
predict mu0, n
foreach var of varlist $xlist {
  quietly summarize `var'
  generate delta = r(sd)/1000
  quietly generate orig = `var'
  quietly replace `var' = `var' + delta
  predict mu1, n
  quietly generate me_`var' = (mu1 - mu0)/delta
  quietly replace `var' = orig
  drop mu1 delta orig
 }
summarize me_*
restore



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