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- and ratio interactions
From
Richard Williams <[email protected]>
To
[email protected], Stata List <[email protected]>
Subject
Re: st: -margins- and ratio interactions
Date
Tue, 11 Mar 2014 16:02:07 -0500
One of my ongoing wish list items for Stata is that factor variables
be expanded to include more variable functions, e.g. log of x, 1/x, ratios.
For now, the main thing I can think of is to specify specific values
you want plotted/computed. So, it might be something like mpg = 30,
m_mpg = 1/30, weight = 2000, weight_mpg = 2000/30, or whatever, i.e.
you know what the ratio term should equal so go ahead and compute it
and plug it in, and do this for several relevant values. This might
be quite tedious of course, and not having tried it I am not sure it
will work right.
At 09:56 AM 3/11/2014, Federico Belotti wrote:
Dear listers,
I'm trying to use -margins- to get marginal effects (at means) when
the model includes an interaction between two variables that is a ratio.
In the standard case (when the interaction between two variables is
a product), there are no issues thanks to the Stata -factor variables- syntax
===== code begins ====
sysuse auto, clear
**** Product
reg price mpg weight c.mpg#c.weight
sum mpg, mean
local m_mpg = r(mean)
sum weight, mean
local m_weight = r(mean)
lincom _b[weight] + _b[c.mpg#c.weight]*`m_mpg'
lincom _b[mpg] + _b[c.mpg#c.weight]*`m_weight'
margins, dydx(weight) at((mean) mpg)
margins, dydx(mpg) at((mean) weight)
===== code ends ====
On the other hand, I'm using the following code to get marginal
effects (at means) when the model includes a ratio interaction
===== code begins ====
sysuse auto, clear
**** Ratio
gen mpg_1 = 1/mpg
reg price mpg weight c.mpg_1#c.weight
sum mpg, mean
local m_mpg = r(mean)
sum weight, mean
local m_weight = r(mean)
nlcom _b[weight] + _b[c.mpg_1#c.weight]*(1/`m_mpg')
nlcom _b[mpg] + _b[c.mpg_1#c.weight]*(-`m_weight'/`m_mpg'^2)
margins, dydx(weight) at(mpg_1 = `=1/`m_mpg'')
margins, dydx(mpg) at(weight = `m_weight' mpg_1 = `=-1/`m_mpg'^2')
===== code ends ====
While it is easy to recover the correct marginal effect for the
variable at the numerator of the ratio (in this case "weight"), I'm
struggling to get the correct marginal effect for the denominator
variable (in this case "mpg"). The problem here is that Stata does
not recognize "mpg_1" as the inverse of "mpg" and -margins- forgets
the interaction term in the computation.
Am I doing something wrong? Is there a smart way to write the
-margins- syntax in order to recover mpg's marginal effect?
Any hint is really appreciated.
Thanks.
Ciao,
Federico
--
Federico Belotti, PhD
Research Fellow
Centre for Economics and International Studies
University of Rome Tor Vergata
tel/fax: +39 06 7259 5627
e-mail: [email protected]
web: http://www.econometrics.it
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/
-------------------------------------------
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/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/