I have two variables "group" and "agegrp3". Both are categorical variables with 2 and 3 categories, respectively. I want to make a clustered bar chart as shown in the attached figure, but I want different colors (green, red, and blue) for the three bars representing the 3 categories of agegrp3. Here is the data example.
Here is the code I used to make the bar chart attched.
Code:
* Example generated by -dataex-. For more info, type help dataex clear input int caseid byte(agegrp3 group) 1 1 0 2 1 0 3 1 0 4 2 0 5 0 0 6 1 0 7 0 0 8 1 0 9 1 0 10 2 0 11 1 0 12 1 0 13 1 0 14 0 0 15 1 0 16 0 0 17 1 0 18 1 0 19 2 0 20 0 0 21 2 0 22 0 0 24 1 0 25 2 0 26 0 0 27 2 0 28 0 0 29 2 0 30 0 0 31 2 0 32 0 0 33 1 0 34 1 0 35 2 0 36 0 0 38 2 0 39 1 0 40 1 0 41 1 0 42 2 0 43 1 0 44 2 0 45 0 0 46 0 0 47 1 0 48 0 0 1 1 1 2 0 1 3 2 1 4 1 1 5 2 1 6 1 1 7 2 1 8 1 1 9 0 1 11 2 1 12 0 1 13 2 1 14 0 1 17 2 1 18 2 1 19 1 1 20 1 1 21 2 1 22 0 1 23 1 1 24 1 1 25 1 1 26 0 1 27 0 1 28 1 1 29 2 1 30 2 1 31 0 1 32 0 1 33 2 1 34 0 1 35 1 1 36 1 1 37 0 1 38 1 1 39 2 1 40 2 1 41 0 1 42 0 1 43 0 1 44 1 1 45 1 1 46 2 1 47 0 1 48 2 1 49 1 1 50 0 1 51 0 1 52 1 1 53 2 1 54 1 1 55 1 1 57 1 1 58 0 1 end label values agegrp3 agegrp3 label def agegrp3 0 "10-29", modify label def agegrp3 1 "30-49", modify label def agegrp3 2 ">=50", modify label values group group label def group 0 "control", modify label def group 1 "case", modify
Code:
graph bar (count), over(agegrp3, gap(1)) over(group) ytitle("Frequency")
Comment