Dear all,
I am trying to plot marginal effects in a model with interaction terms and different groups. The easiest and fastest way is of course using -margins- and -marginsplot-. Another (much longer) way would be using -parmest- and -eclplot- (both from SSC), but then one has to compute the marginal effects and their confidence intervals by hand, build the dataset, etc.
My problem with -margins- is that when the confidence intervals of the different groups overlap, the plot become difficult to read. To solve this issue, a nice feature of -eclplot- is the suboption -spaceby()-, which allows to add space between the parameters of different groups.
In order to make my point clear, here is a small example:
*******************
*Run and store an estimation
sysuse auto
reg price c.mpg##c.weight##i.foreign
estimates store reg1
*Plot marginal effects using -margins- and -marginsplot-
margins, dydx(mpg) at(weight=(2300(100)3000) foreign=(0/1))
marginsplot, title("") name(marginsplot, replace)
*Plot marginal effects using -parmest- and -eclplot- (from ssc)
preserve
forv w=2300(100)3000 {
forv f=0/1 {
restore, preserve
est restore reg1
nlcom _b[mpg]+_b[c.mpg#c.weight]*`w'+_b[1.foreign#c.mpg]*`f'+_b[1.foreign#c.mpg#c.weight]*`w'*`f', post level(95)
parmest, saving(coef`w'`f', replace) // parmest from ssc
use coef`w'`f'
gen weight = `w'
gen foreign = `f'
save coef`w'`f', replace
}
}
clear
forv w=2300(100)3000 {
forv f=0/1 {
append using coef`w'`f'
erase coef`w'`f'.dta
}
}
*Draw the plot
#d ;
eclplot estimate min max weight,
supby(foreign, spaceby(20) offset(-10))
estopts(c(l)) ciopts(lc(gs6))
estopts1(lc(navy) mc(navy)) estopts2(lc(maroon) mc(maroon) )
ciopts1(lc(navy)) ciopts2(lc(maroon))
xlab(2300(100)3000, format(%10.0gc))
name(eclplot, replace)
;
#d cr
*******************
You can check that both graphs are identical, the only difference being that the parameters are aligned in marginsplot while they are spaced in eclplot. In my opinion, the second one is much easier to read (even though one might argue that if confidence intervals overlap, it is not obvious that the model estimated is the optimal one I admit).
Is there a possibility to space the parameters using -margins-?
Thanks.
Sylvain Weber
University of Neuchâtel, Institute of Economic Research (irene)
A.-L. Breguet 2, 2000 Neuchâtel, Switzerland
+41.32.718.14.42
[email protected]
http://sites.google.com/site/swwebpage/
I am trying to plot marginal effects in a model with interaction terms and different groups. The easiest and fastest way is of course using -margins- and -marginsplot-. Another (much longer) way would be using -parmest- and -eclplot- (both from SSC), but then one has to compute the marginal effects and their confidence intervals by hand, build the dataset, etc.
My problem with -margins- is that when the confidence intervals of the different groups overlap, the plot become difficult to read. To solve this issue, a nice feature of -eclplot- is the suboption -spaceby()-, which allows to add space between the parameters of different groups.
In order to make my point clear, here is a small example:
*******************
*Run and store an estimation
sysuse auto
reg price c.mpg##c.weight##i.foreign
estimates store reg1
*Plot marginal effects using -margins- and -marginsplot-
margins, dydx(mpg) at(weight=(2300(100)3000) foreign=(0/1))
marginsplot, title("") name(marginsplot, replace)
*Plot marginal effects using -parmest- and -eclplot- (from ssc)
preserve
forv w=2300(100)3000 {
forv f=0/1 {
restore, preserve
est restore reg1
nlcom _b[mpg]+_b[c.mpg#c.weight]*`w'+_b[1.foreign#c.mpg]*`f'+_b[1.foreign#c.mpg#c.weight]*`w'*`f', post level(95)
parmest, saving(coef`w'`f', replace) // parmest from ssc
use coef`w'`f'
gen weight = `w'
gen foreign = `f'
save coef`w'`f', replace
}
}
clear
forv w=2300(100)3000 {
forv f=0/1 {
append using coef`w'`f'
erase coef`w'`f'.dta
}
}
*Draw the plot
#d ;
eclplot estimate min max weight,
supby(foreign, spaceby(20) offset(-10))
estopts(c(l)) ciopts(lc(gs6))
estopts1(lc(navy) mc(navy)) estopts2(lc(maroon) mc(maroon) )
ciopts1(lc(navy)) ciopts2(lc(maroon))
xlab(2300(100)3000, format(%10.0gc))
name(eclplot, replace)
;
#d cr
*******************
You can check that both graphs are identical, the only difference being that the parameters are aligned in marginsplot while they are spaced in eclplot. In my opinion, the second one is much easier to read (even though one might argue that if confidence intervals overlap, it is not obvious that the model estimated is the optimal one I admit).
Is there a possibility to space the parameters using -margins-?
Thanks.
Sylvain Weber
University of Neuchâtel, Institute of Economic Research (irene)
A.-L. Breguet 2, 2000 Neuchâtel, Switzerland
+41.32.718.14.42
[email protected]
http://sites.google.com/site/swwebpage/
Comment