Hello,
I am using Stata 13.1 and trying to create a population pyramid with the outline presented at
. The difference is that I have multiple years that I will be graphing and, in the end, combining multiple graphs into a single graphic with multiple panels.
Therefore, I want to update this code to only graph a specified year.
Below is an excerpt of data with two years:
I edited the code and added two "if YEAR==1944" for both males and females. It works and only displays 1944; however, it now combines both males and females to the right side rather than having males on the left and females on the right. How do I fix this?
Thank you in advance!
Amie
I am using Stata 13.1 and trying to create a population pyramid with the outline presented at
HTML Code:
http://statistics.ats.ucla.edu/stat/stata/library/GraphExamples/code/twobar4.htm
Therefore, I want to update this code to only graph a specified year.
Below is an excerpt of data with two years:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input int YEAR str15 B long Total double(Male Female) str10 agestr float(agegrp zero) 1944 "0-4 years old" 12644540 6.438293 6.206247 "Under 5" 1 0 1944 "5-9 years old" 11168095 5.682759 5.485336 "5 to 9" 2 0 1944 "10-14 years old" 10748443 5.447873 5.30057 "10 to 14" 3 0 1944 "15-19 years old" 11305978 5.446659 5.859319 "15 to 19" 4 0 1944 "20-24 years old" 9982174 3.873215 6.108959 "20 to 24" 5 0 1944 "25-29 years old" 9710781 3.895733 5.815048 "25 to 29" 6 0 1944 "30-34 years old" 10282240 4.74028 5.54196 "30 to 34" 7 0 1944 "35-39 years old" 9696497 4.640735 5.055762 "35 to 39" 8 0 1944 "40-44 years old" 9163708 4.497546 4.666162 "40 to 44" 9 0 1944 "45-49 years old" 8418320 4.1982 4.22012 "45 to 49" 10 0 1944 "50-54 years old" 7784007 3.938154 3.845853 "50 to 54" 11 0 1944 "55-59 years old" 6617369 3.378113 3.239256 "55 to 59" 12 0 1944 "60-64 years old" 5165890 2.609618 2.556272 "60 to 64" 13 0 1944 "65-69 years old" 4002453 1.975605 2.026848 "65 to 69" 14 0 1944 "70-74 years old" 2895674 1.39836 1.497314 "70 to 74" 15 0 1944 "75UP years old" 2977102 1.379601 1.597501 "75 and up" 16 0 2060 "0-4 years old" 22778379 11.651752 11.126627 "Under 5" 1 0 2060 "5-9 years old" 22893686 11.701628 11.192058 "5 to 9" 2 0 2060 "10-14 years old" 22870518 11.685481 11.185037 "10 to 14" 3 0 2060 "15-19 years old" 23066671 11.789972 11.276699 "15 to 19" 4 0 2060 "20-24 years old" 23999332 12.288607 11.710725 "20 to 24" 5 0 2060 "25-29 years old" 25064814 12.824985 12.239829 "25 to 29" 6 0 2060 "30-34 years old" 25845067 13.209786 12.635281 "30 to 34" 7 0 2060 "35-39 years old" 26151118 13.360831 12.790287 "35 to 39" 8 0 2060 "40-44 years old" 25948680 13.240612 12.708068 "40 to 44" 9 0 2060 "45-49 years old" 25368021 12.920705 12.447316 "45 to 49" 10 0 2060 "50-54 years old" 25394932 12.885485 12.509447 "50 to 54" 11 0 2060 "55-59 years old" 24892603 12.559795 12.332808 "55 to 59" 12 0 2060 "60-64 years old" 24357042 12.20071 12.156332 "60 to 64" 13 0 2060 "65-69 years old" 24111639 11.967085 12.144554 "65 to 69" 14 0 2060 "70-74 years old" 21661957 10.522546 11.139411 "70 to 74" 15 0 2060 "75UP years old" 52390151 22.953831 29.43632 "75 and up" 16 0 end label values agegrp agelbl
Code:
twoway bar Male agegrp if YEAR==1944, horizontal xvarlab(Males)||bar Female agegrp if YEAR==1944 , horizontal xvarlab(Females)||sc agegrp zero , mlabel(agegrp) mlabcolor(black) msymbol(i)||, xtitle("Population in millions") ytitle("")plotregion(style(none))ysca(noline) ylabel(none)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("US Male and Female Population by Age, 1944")note("Source: U.S. Census Bureau, National Projections 2014")
Thank you in advance!
Amie
Comment