Stata tip: Bar charts

To make a chart of regional differences in GDP per capita in China, download data from China Statistical Yearbook. My final chart looks like this:


Getting there takes a few steps that I show in this post . If you have a wide dataset where each row gives you a region and each column tells you GDP in that year, run the code below.

Step 1: Create a basic bar chart.

graph hbar y2009 y2013, over(region)

Step 2: Re-size the chart:

graph hbar y2009 y2013, over(region, sort(1)) ///

xsize(8) ysize(12)

Step 3: Improve the legend (label the years, choose an appropriate position).

Step 4: Label the chart.

Step 5: Get rid of the greyish background color

graph hbar y2009 y2013, over(region, sort(1)) ///

legend(label(1 "2009") label(2 "2013") rows(2) ring(0) pos(2)) ///

xsize(8) ysize(12) ///

graphregion(color(white)) ///

title("Regional GDP per capita across China")

graph hbar y2009 y2013, over(region, sort(1)) ///

legend(label(1 "2009") label(2 "2013") rows(2) ring(0) pos(2)

region(lcolor(white))) ///

xsize(8) ysize(12) ///

graphregion(color(white)) ///

title("Regional GDP per capita across China", size(*.7)) ///

bar(1, color(ebblue*0.4)) bar(2, color(midblue))

Step 6: Adjust the font size of the title.

Step 7: Improve the legend, removing the box.

Step 8: Label the horizontal axis.

Step 9: Choose bar colors that you like.

Step 10: Modify color intensity using the "*" operator.

graph hbar y2009 y2013, over(region, sort(1)) ///

legend(label(1 "2009") label(2 "2013") rows(2) ring(0) pos(2) region(lcolor(white))) ///

xsize(8) ysize(12) ///

graphregion(color(white)) ///

title("Regional GDP per capita across China", size(*.7)) ///

ytitle("Yuan") ///

bar(1, color(ebblue*0.3)) bar(2, color(midblue*1.1))

Step 11: Move the "Yuan" label to the right.

Step 12: Sort regions by latest GDP, rather than initial GDP.

graph hbar y2009 y2013, over(region, sort(2)) ///

legend(label(1 "2009") label(2 "2013") rows(2) ring(0) pos(2) region(lcolor(white))) ///

xsize(8) ysize(12) ///

graphregion(color(white)) ///

title("Regional GDP per capita across China", size(*.7)) ///

ytitle("Yuan", placement(e)) ///

bar(1, color(ebblue*0.3)) bar(2, color(midblue*1.1))

Done.