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
Steve Samuels <[email protected]>
To
[email protected]
Subject
Re: st: -margins- and ratio interactions
Date
Tue, 11 Mar 2014 20:39:55 -0400
This doesn't address the shortcomings of -margins-, but I put it out for
consideration.
Dick Kronmal (1993, p. 390) would have argued that if ratio gpm ( =
1/mpg) is in the interaction (gpm*weight), *it*, not mpg, should have be
a main effect. Compare the last two regressions. The gpm only model fits
slightly better; and the predictions are nearly identical (r = 0.9947).
I think that an analyst would require a pretty good theory to justify a
model with X and Z as main effects, but with X*(1/Z) interaction.
*********Start Code*********
sysuse auto, clear
gen gpm = 1/mpg
local m_weight = r(mean)
gen weightd = weight-`m_weight'
/* mpg and gpm */
reg price c.mpg c.weightd c.gpm#c.weightd
/* gpm only */
reg price c.gpm c.weightd c.gpm#c.weightd
********End Code**************
Reference:
Kronmal, R.A. 1993. Spurious correlation and the fallacy of the ratio standard revisited. Journal of the Royal Statistical Society. Series A (Statistics in Society) 3, no. 156: 379-392.
Steve
> margins, dydx(weight) at(mpg_1 = `=1/`m_mpg'')
> On Mar 11, 2014, at 5:02 PM, Richard Williams <[email protected]> wrote:
>
> 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
> **** 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/
*
* 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/