-
Login or Register
- Log in with
sysuse auto, clear
set scheme s1mono
// sensible units
replace weight = weight * 4.535924e-4
label var weight "weight (1000kg)"
replace price = price/1000
label var price "price (1000$)"
// a model
glm price c.weight##i.foreign , link(log) family(poisson) vce(robust)
// store marginal effects
tempfile tograph
margins, dydx(weight) at(weight=(.8(.05)2.2) foreign=(0/1)) saving(`tograph', replace)
use `tograph', replace
// make the graph
separate _margin, by(_at2) veryshortlabel
separate _ci_lb, by(_at2)
separate _ci_ub, by(_at2)
twoway rarea _ci_lb0 _ci_ub0 _at1 if _at1 > 1.5 , ///
astyle(ci) || ///
rarea _ci_lb1 _ci_ub1 _at1 if _at1 > 1.5 , ///
astyle(ci) || ///
line _ci_lb0 _ci_lb1 _ci_ub0 _ci_ub1 _at1, ///
lpattern(dot ..) lcolor(black ..) || ///
line _margin0 _margin1 _at1 , ///
lpattern(solid dash) lcolor(black ..) ///
legend(order(7 8) ///
pos(4) col(1) ///
region(lstyle(none))) ///
ylab(,angle(0)) ///
ytitle(marginal effect of weight)
Comment