Hi!
I'm working in Stata 15 trying to create a twoway bar graph with the prevalence of obesity on the y-axis and agegroups on X-axis. The problem arises when I would like to have four different years per age group. As you can see from image - the bars overlap such that 2017 hides the other years.

My syntax looks like below. I have also tried syntax from this forum, but the same issue occurs.
Kind regards
Jannie
Data looks like below:
I'm working in Stata 15 trying to create a twoway bar graph with the prevalence of obesity on the y-axis and agegroups on X-axis. The problem arises when I would like to have four different years per age group. As you can see from image - the bars overlap such that 2017 hides the other years.
My syntax looks like below. I have also tried syntax from this forum, but the same issue occurs.
Code:
twoway (bar PropOB100 Age if year==1999, bcolor(maroon) barw(0.85)) /// (bar PropOB100 Age if year==2005, bcolor(green) barw(0.85)) /// (bar PropOB100 Age if year==2011, bcolor(orange) barw(0.85)) /// (bar PropOB100 Age if year==2017, bcolor(ltblue) barw(0.85)) /// (rcap UL_PropOB100 LL_PropOB100 Age), /// legend(order(1 "1999" 2 "2005" 3 "2011" 4 "2017") rows(1)) /// xlabel( 1 "18-24" 2 "25-29" 3 "30-34" 4 "35-39" 5 "40-44" 6 "45-49" 7 "50-54" 8 "55-59" 9 "60-64" 10 "65-69" 11 "70+") /// xtitle("Age") /// ylabel(10 15 20 25 30 35 40, nogrid) yscale(range(10 40)) /// ytitle("Prevalence of Obesity (%)")
Jannie
Data looks like below:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input float Age int year float(PropOB100 UL_PropOB100 LL_PropOB100) 1 1999 13.17658 21.05773 7.948086 1 2005 11.623165 15.07769 8.877385 1 2011 11.668415 16.13067 8.318133 1 2017 22.425257 30.4586 16.022507 2 1999 19.39137 25.26686 14.614967 2 2005 21.315594 26.809494 16.690784 2 2011 25.78692 29.398335 22.477903 2 2017 20.97302 25.118103 17.353456 3 1999 23.135847 29.03269 18.130724 3 2005 28.99342 34.968296 23.66789 3 2011 26.953384 30.90038 23.340256 3 2017 26.911236 31.977936 22.38316 4 1999 19.963625 24.04661 16.423998 4 2005 30.60505 35.755623 25.89733 4 2011 31.232634 36.082886 26.76138 4 2017 34.455215 39.22816 29.97655 5 1999 20.86615 25.44563 16.923758 5 2005 25.207075 28.99692 21.76075 5 2011 33.73074 38.65309 29.13751 5 2017 36.5879 41.3974 32.03175 6 1999 19.79532 24.334633 15.92455 6 2005 25.62487 29.749763 21.89367 6 2011 31.366955 37.132996 26.12421 6 2017 38.81377 45.70695 32.340916 7 1999 24.086357 28.284763 20.33443 7 2005 24.31568 29.64821 19.674046 7 2011 28.43865 32.9217 24.34451 7 2017 35.051098 40.99437 29.53813 8 1999 23.921154 30.39058 18.46362 8 2005 26.60072 31.81101 21.968874 8 2011 32.129158 36.176197 28.33387 8 2017 33.545105 38.55017 28.884417 9 1999 25.58697 33.5093 19.002365 9 2005 28.75425 35.585022 22.77117 9 2011 28.82813 35.00919 23.34635 9 2017 33.55486 39.09665 28.43188 10 1999 18.511532 24.576674 13.671854 10 2005 25.4658 34.930893 17.861412 10 2011 30.76999 35.505802 26.407217 10 2017 27.48402 34.345863 21.54324 11 1999 14.925941 19.391964 11.343714 11 2005 15.567016 19.01545 12.646297 11 2011 18.220095 22.78926 14.396216 11 2017 22.37479 26.9338 18.39321 end label values Age agecat label def agecat 1 "18-24", modify label def agecat 2 "25-29", modify label def agecat 3 "30-34", modify label def agecat 4 "35-39", modify label def agecat 5 "40-44", modify label def agecat 6 "45-49", modify label def agecat 7 "50-54", modify label def agecat 8 "55-59", modify label def agecat 9 "60-64", modify label def agecat 10 "65-69", modify label def agecat 11 "70+", modify
Comment