Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: ratio of marginal effects when using two -margins- commands

From   Mirko <>
Subject   st: ratio of marginal effects when using two -margins- commands
Date   Tue, 13 Apr 2010 13:01:34 +0100

Dear all,

I am wondering whether is possible to obtain standard errors and
confidence intervals of ratio of marginal effects when they are
obtained by running two (or more) times the command -margins-.
-margins- makes life a lot easier especially after estimating models
with interaction terms or nonlinear models:

* simple case
logistic outcome sex##group age
margins sex, post
nlcom (risk_ratio: _b[] / _b[])

However, there may be some cases in which one needs to compute two
separate -margins- commands to obtain the marginal effects of
interest. For example, after a model of Y on X, Z and the interaction
term XZ:

Y = a + bX + bZ + bXZ + e,

I'd like to obtain the statistical significance of the ratio of

(marginal effects of variable X conditional on variable Z)/ (marginal
effects of variable Z conditional on X) =


****begin example*****************************************
* -margins*

sysuse auto, clear
set more off
qui regress mpg foreign i.rep78##c.weight headroom
* ME1
margins, dydx(rep78) atmeans
* ME2
margins, dydx(weight) over(rep78)

**********end example***************************************

Is there an easy way to get standard errors and confidence intervals
of ratios of two -margins- ME1/ME2?

Or do I need to use -nlcom- like below?

****begin example********************************
* ratio of marginal effects with -nlcom-
sysuse auto, clear
set more off
qui tab rep78, gen(rep)
forval i=2/5{
	qui gen rep`i'Xweight = rep`i'*weight
regress mpg foreign rep2-rep5 rep2Xweight-rep5Xweight weight headroom
qui sum weight if e(sample)
local meanw = r(mean)
* ratio of ME1/ME2
nlcom (_b[rep2] + _b[rep2Xweight]*`meanw')/(_b[weight] + _b[rep2Xweight])
nlcom (_b[rep3] + _b[rep3Xweight]*`meanw')/(_b[weight] + _b[rep3Xweight])
nlcom (_b[rep4] + _b[rep4Xweight]*`meanw')/(_b[weight] + _b[rep4Xweight])
nlcom (_b[rep5] + _b[rep5Xweight]*`meanw')/(_b[weight] + _b[rep5Xweight])

****end example****************************************************************

I would appreciate any help on this.
Best regards,
*   For searches and help try:

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