Dear Statalist,
I am looking to get some help plotting three twoway barcharts stacked with subgroups on a timeseries data. Below is a sample data I'm using.
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input byte _ID float date str2 scode float(cum_a cum_r cum_d) 35 21988 "AP" 1 0 0 35 21989 "AP" 1 0 0 35 21990 "AP" 1 0 0 35 21991 "AP" 1 0 0 35 21992 "AP" 1 0 0 35 21993 "AP" 3 0 0 35 21994 "AP" 3 0 0 35 21995 "AP" 5 0 0 35 21996 "AP" 6 0 0 35 21997 "AP" 7 0 0 35 21998 "AP" 8 0 0 35 21999 "AP" 9 1 0 35 22000 "AP" 10 1 0 35 22001 "AP" 12 1 0 35 22002 "AP" 18 1 0 35 22003 "AP" 20 1 0 35 22004 "AP" 22 1 0 35 22005 "AP" 43 1 0 35 22006 "AP" 109 2 0 35 22007 "AP" 147 2 0 35 22008 "AP" 161 2 1 35 22009 "AP" 189 2 1 35 22010 "AP" 250 5 1 35 22011 "AP" 295 5 3 35 22012 "AP" 305 5 4 35 22013 "AP" 338 6 4 35 22014 "AP" 347 10 6 35 22015 "AP" 365 10 6 35 22016 "AP" 389 10 6 35 22017 "AP" 401 12 7 35 22018 "AP" 420 12 7 35 22019 "AP" 457 16 11 35 22020 "AP" 491 20 14 35 22021 "AP" 500 20 14 35 22022 "AP" 523 35 14 35 22023 "AP" 545 42 16 35 22024 "AP" 565 65 17 35 22025 "AP" 610 92 20 35 22026 "AP" 639 96 22 35 22027 "AP" 669 120 24 35 22028 "AP" 725 141 27 35 22029 "AP" 781 145 29 35 22030 "AP" 814 171 31 35 22031 "AP" 835 231 31 35 22032 "AP" 911 235 31 35 22033 "AP" 970 258 31 35 22034 "AP" 1014 287 31 23 21988 "DL" 5 1 1 23 21989 "DL" 4 2 1 23 21990 "DL" 4 2 1 23 21991 "DL" 5 2 1 23 21992 "DL" 7 2 1 23 21993 "DL" 10 3 1 23 21994 "DL" 14 5 1 23 21995 "DL" 21 5 1 23 21996 "DL" 21 5 1 23 21997 "DL" 24 5 1 23 21998 "DL" 23 6 1 23 21999 "DL" 28 6 1 23 22000 "DL" 29 6 1 23 22001 "DL" 33 6 1 23 22002 "DL" 42 6 1 23 22003 "DL" 64 6 2 23 22004 "DL" 89 6 2 23 22005 "DL" 112 6 2 23 22006 "DL" 144 6 2 23 22007 "DL" 281 8 4 23 22008 "DL" 372 8 6 23 22009 "DL" 423 16 6 23 22010 "DL" 480 16 7 23 22011 "DL" 502 16 7 23 22012 "DL" 547 20 9 23 22013 "DL" 639 21 9 23 22014 "DL" 683 25 12 23 22015 "DL" 862 27 14 23 22016 "DL" 1023 27 19 23 22017 "DL" 1102 28 24 23 22018 "DL" 1451 31 28 23 22019 "DL" 1500 31 30 23 22020 "DL" 1505 41 32 23 22021 "DL" 1550 52 38 23 22022 "DL" 1593 72 42 23 22023 "DL" 1643 207 43 23 22024 "DL" 1668 290 45 23 22025 "DL" 1603 431 47 23 22026 "DL" 1498 611 47 23 22027 "DL" 1476 724 48 23 22028 "DL" 1518 808 50 23 22029 "DL" 1604 857 53 23 22030 "DL" 1702 869 54 23 22031 "DL" 1987 877 54 23 22032 "DL" 2177 877 54 23 22033 "DL" 2182 1078 54 23 22034 "DL" 2291 1092 56 end format %tdDD/NN/YY date
I'm able to create line graphs to my full satisfaction using
Code:
twoway (line cum_a date) (line cum_r date) (line cum_d date), ytitle("") /// ylabel(, labels labsize(vsmall) angle(horizontal)) xtitle("") /// xlabel(#4, labels angle(vertical) format(%tdMon_DD)) /// by(, title("Cases by scode", size(medsmall) position(12))) /// by(, legend(on)) legend(order(1 "cum_a" 2 "cum_r" 3 "cum_d") size(medsmall)) /// scheme(_grstyle_) by(scode, style(default) imargin(small) cols(3) yrescale)
However, instead of these line plots, I actually like to show stacked bars that will enable me to see a total value which is the sum of cum_a, cum_r and cum_d. The data is a panel data with
Code:
tsset _ID date
Any help will be appreciated.
Thanks,
Rijo.
Comment