Hello Statalist users,
Using Stata 13.1, I am trying to create a bar chart with specific bars highlighted. However, most documentation I have looked at (help barlook_options & "Stata tip 102: Highlighting specific bars" by Nick Cox) explain how to do this with a single bar chart. I am working with a two way bar graph to create a population pyramid and cannot figure out where to put the
in the code.
Here is an excerpt of my data:
Here are two codes I tried. Both incur an "invalid 'bar'" error.
Any help would be greatly appreciated!
Amie
*Edited to remove the play(pyramid) recording and changed color from red to ltkhaki since the default will be blue and red.
Using Stata 13.1, I am trying to create a bar chart with specific bars highlighted. However, most documentation I have looked at (help barlook_options & "Stata tip 102: Highlighting specific bars" by Nick Cox) explain how to do this with a single bar chart. I am working with a two way bar graph to create a population pyramid and cannot figure out where to put the
Code:
bar(1, color(ltkhaki))
Here is an excerpt of my data:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input int YEAR byte agegrp str9 agestr double(Total Male Female) float zero 1960 1 "Under 5" 20321000 -10.33 9.991 0 1960 2 "5 to 9" 18691000 -9.504 9.187 0 1960 3 "10 to 14" 16773000 -8.524 8.249 0 1960 4 "15 to 19" 13220000 -6.634 6.586 0 1960 5 "20 to 24" 10800000 -5.272 5.528 0 1960 6 "25 to 29" 10869000 -5.333 5.536 0 1960 7 "30 to 34" 11949000 -5.846 6.103 0 1960 8 "35 to 39" 12482000 -6.08 6.402 0 1960 9 "40 to 44" 11600000 -5.676 5.924 0 1960 10 "45 to 49" 10880000 -5.358 5.522 0 1960 11 "50 to 54" 9606000 -4.735 4.871 0 1960 12 "55 to 59" 8430000 -4.127 4.303 0 1960 13 "60 to 64" 7142000 -3.409 3.733 0 1960 14 "65 to 69" 6258000 -2.931 3.327 0 1960 15 "70 to 74" 4739000 -2.185 2.554 0 1960 16 "75 and up" 5563000 -2.387 3.176 0 end
Code:
twoway bar Male agegrp if YEAR==1960, horizontal xvarlab(Males) bar(1, color(ltkhaki))||bar Female agegrp if YEAR==1960 , horizontal xvarlab(Females) bar(1, color(ltkhaki)) , xtitle("Population(millions)") ytitle("Age")plotregion(style(none))ysca(noline) ylabel(1 "0" 6 "25" 10 "45" 14 "65")xsca(noline titlegap(-3.5))xlabel(-12 "12" -10 "10" -8 "8" -6 "6" -4 "4" 4(2)12 , tlength(0) grid gmin gmax)legend(label(1 Males) label(2 Females)) legend(order(1 2))title("1960") name(panelb, replace) nodraw
Code:
twoway bar Male agegrp if YEAR==1960, horizontal xvarlab(Males) ||bar Female agegrp if YEAR==1960 , horizontal xvarlab(Females), bar(1, color(ltkhaki)) xtitle("Population(millions)") ytitle("Age")plotregion(style(none))ysca(noline) ylabel(1 "0" 6 "25" 10 "45" 14 "65")xsca(noline titlegap(-3.5))xlabel(-12 "12" -10 "10" -8 "8" -6 "6" -4 "4" 4(2)12 , tlength(0) grid gmin gmax)legend(label(1 Males) label(2 Females)) legend(order(1 2))title("1960") name(panelb, replace) nodraw
Amie
*Edited to remove the play(pyramid) recording and changed color from red to ltkhaki since the default will be blue and red.
Comment