Hello Statalist community,
I'm encountering an issue with generating a bar chart using the marginsplot command after recasting it to a bar chart (recast(bar)). Specifically, I'm trying to display the bars for two different treatment groups (e.g., foreign in the auto dataset) side by side at specific values of another variable (e.g., mpg), but the bars appear on top of one another rather than side by side.
To illustrate the problem, consider the following example using Stata's built-in auto dataset:
In this case, I would like the bars for foreign and domestic cars to be displayed next to each other for each value of mpg (20, 30, 40). However, the bars currently overlap, and I haven't been able to control the spacing between them effectively.
I understand that the bargap() option within plotopts() might be a potential solution to adjust the gap between the bars. I've tried using the following command:
While this does adjust the spacing, I'm still having trouble achieving the desired result of side-by-side bars. If anyone has experience with this issue or suggestions on how to properly configure the bargap() or other relevant options, I would greatly appreciate your help.
Thanks!
CJ
I'm encountering an issue with generating a bar chart using the marginsplot command after recasting it to a bar chart (recast(bar)). Specifically, I'm trying to display the bars for two different treatment groups (e.g., foreign in the auto dataset) side by side at specific values of another variable (e.g., mpg), but the bars appear on top of one another rather than side by side.
To illustrate the problem, consider the following example using Stata's built-in auto dataset:
Code:
sysuse auto, clear reg price i.foreign##c.mpg margins foreign, at(mpg=(20 30 40)) marginsplot, recast(bar)
I understand that the bargap() option within plotopts() might be a potential solution to adjust the gap between the bars. I've tried using the following command:
Code:
marginsplot, recast(bar) plotopts(barw(0.4) bargap(20))
Thanks!
CJ
Comment