Hi Stata Users,
I'm using a graph hbar to make a graph that illustrates results from a difference-in-differences estimation. I'm using the auto data set to illustrate. In the example, I estimate the car price as a function of an indicator for foreign and for a large car. I'm saving the estimated means and standard errors using lincom. Then I make one plot for domestic cars, one for foreign cars and one for the difference. Each plot has the same principle:
I'm plotting 3 horizontal bars, one for small cars, one for large cars and one showing the difference. Each bar has a label giving the estimated mean for each group (i.e. the height of the bar). I want to make two modifications:
1. I want to add a second bar label that gives the estimated standard error (saved as variables se_*). This should be displayed under the mean in parentheses. How can I add this? I saw the advice of combining a scatterplot with a twoway bar. But this doesn't work here, since scatter does not allow the option "horizontal". I want a horizontal bar chart to illustrate the difference-in-difference by combining all three plots.
2. I want to move the horizontal axis (y-axis in the hbargraph) up along the vertical axis, such that it runs between the bar for large and the difference.
Here is my code using the auto data set for illustration:
Thanks in advance!
I'm using a graph hbar to make a graph that illustrates results from a difference-in-differences estimation. I'm using the auto data set to illustrate. In the example, I estimate the car price as a function of an indicator for foreign and for a large car. I'm saving the estimated means and standard errors using lincom. Then I make one plot for domestic cars, one for foreign cars and one for the difference. Each plot has the same principle:
I'm plotting 3 horizontal bars, one for small cars, one for large cars and one showing the difference. Each bar has a label giving the estimated mean for each group (i.e. the height of the bar). I want to make two modifications:
1. I want to add a second bar label that gives the estimated standard error (saved as variables se_*). This should be displayed under the mean in parentheses. How can I add this? I saw the advice of combining a scatterplot with a twoway bar. But this doesn't work here, since scatter does not allow the option "horizontal". I want a horizontal bar chart to illustrate the difference-in-difference by combining all three plots.
2. I want to move the horizontal axis (y-axis in the hbargraph) up along the vertical axis, such that it runs between the bar for large and the difference.
Here is my code using the auto data set for illustration:
Code:
sysuse auto, clear gen large = weight>3000 gen foreign_large = foreign* large *Diff-in-diff regression reg price large foreign foreign_large *Calculate means and standard errors for domestic cars: *small lincom _cons gen mean_small_dom = r(estimate) gen se_small_dom=r(se) *large lincom _cons +large gen mean_large_dom = r(estimate) gen se_large_dom =r(se) *difference lincom -large gen diff_small_large_dom = r(estimate) gen se_small_large_dom = r(se) keep mean* se* diff* duplicates drop *Make graph graph hbar mean_small_dom mean_large_dom diff_small_large_dom , /// bargap(5) blabel(bar ,pos(outside) format(%5.2f) color(black) size(medium)) /// showyvars yvaroptions(relabel (1 "Small" 2 "Large" 3 "Difference")) /// legend(off) /// title("Average Price by Size and Origin - Domestic Cars") /// yscale(range(-5000 (1000) 9000)) ylabel(-4000 (2000) 8000)
Comment