Hi everyone,
I'm trying to plot margins with mplotoffset (by Nick Winter) in Stata 18.
Using auto.dta as an example, I tried to replicate my original variables in auto.dta as best as possible.
I have two questions:
I couldn't find a solution for either in the documentation, so would be very greatful for any advice.
Am I on the wrong path with mplotoffset and would coefplot from the Stata Journal be the better option?
English isn't my first language, my apologies should anything be unclear or awkwardly worded. Happy to provide further details if neccessary.
Best
Julia
I'm trying to plot margins with mplotoffset (by Nick Winter) in Stata 18.
Using auto.dta as an example, I tried to replicate my original variables in auto.dta as best as possible.
I have two questions:
- First, I'd like to offset the markers with varying distances. Ideally, I need a close distance for the two markers within each value of trunk_bin and a higher distance between the different trunk_bin values. So kind of visually clustering the markers according to the value of trunk_bin.
I.e. "0.trunk_bin#0.foreign" & "0.trunk_bin#1.foreign" close together and then a larger distance between "0.trunk_bin#1.foreign" & "1.trunk_bin#0.foreign". "1.trunk_bin#0.foreign" & "1.trunk_bin#1.foreign" close together, again larger distance between "1.trunk_bin#1.foreign" & "2.trunk_bin#0.foreign" and so on. - Secondly, I need to group my xdimension variables (since I'm using horizontal, they are shown on the yaxis) and give them headings. I'd like to have four groups, one for each value of headroom_bin:
Headroom_bin=3
3.headroom_bin#2.price_bin
3.headroom_bin#1.price_bin
Headroom_bin=2
2.headroom_bin#2.price_bin
2.headroom_bin#1.price_bin
and so on.
Code:
clear sysuse auto.dta gen trunk_bin = 0 replace trunk_bin=1 if (inrange(trunk,10,15)) replace trunk_bin=2 if (inrange(trunk,16,23)) gen headroom_bin = 0 replace headroom_bin=1 if (inrange(headroom,2.0,3.0)) replace headroom_bin=2 if (inrange(headroom,3.5,4.0)) replace headroom_bin=3 if (inrange(headroom,4.5,5.0)) gen price_bin = 1 replace price_bin=2 if (inrange(price,4000,6999)) replace price_bin=3 if (inrange(price,7000,9999)) replace price_bin=4 if (price>9999) regress mpg i.price_bin#i.trunk_bin#i.foreign i.price_bin#i.trunk_bin#i.foreign#i.headroom_bin if (price_bin==1 | price_bin==2) margins trunk_bin#foreign, at(headroom_bin=(0/3) price_bin=(1 2)) mplotoffset, horizontal nolabel recast(scatter) xdimension(headroom_bin price_bin) offset(0.10)
Am I on the wrong path with mplotoffset and would coefplot from the Stata Journal be the better option?
English isn't my first language, my apologies should anything be unclear or awkwardly worded. Happy to provide further details if neccessary.
Best
Julia
Comment