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]

st: -margins- and ratio interactions


From   Federico Belotti <[email protected]>
To   Stata List <[email protected]>
Subject   st: -margins- and ratio interactions
Date   Tue, 11 Mar 2014 15:56:31 +0100

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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index