I would like to make a graph as shown below. In my simple example, I calculated concentration indices (CI) of age and gender for each of four countries and then I want to plot those CI values for each country in one graph as illustrated by the image example. For example, the total CI of country 1 would equal age1 + gender 1; country2 = age2 + gender2 and so on.
Array
I was told that graph hbar with stack command could be a good way to go but I still don't know how to make a similar graph. I would be grateful if anyone can help me out with this.
Note: I use -conindex- command from SSC, written by O'Donnell and colleagues.
Thank you.
Data
Code:
clear input float(id y wealth) int age byte gender float country 5795 4 4 67 0 2 5796 5 4 67 1 2 5797 6 2 63 1 2 5798 0 5 61 1 2 5799 7 5 73 0 2 5800 8 3 56 1 2 5801 9 2 64 0 2 5803 10 1 52 1 2 5804 11 1 61 1 2 5805 0 1 56 0 2 5806 0 5 64 0 2 5807 0 5 62 0 2 5808 12 5 56 1 2 5809 13 3 63 1 2 5810 3 2 73 0 2 5811 0 1 64 1 2 5812 1 1 58 0 2 5813 0 4 64 0 2 5814 1 2 51 1 2 5815 1 3 55 1 2 5816 2 3 59 1 2 5817 3 2 64 1 2 5818 0 3 73 0 2 5819 0 3 75 1 2 5820 0 2 57 0 2 3696 12 4 66 1 4 3697 2 4 73 0 4 3698 4 5 57 1 4 3699 5 3 70 0 4 3700 6 3 56 1 4 3701 7 5 60 1 4 3702 8 4 58 0 4 3703 9 4 51 1 4 3704 0 5 61 1 4 3705 0 4 64 0 4 3706 10 4 65 1 4 3707 2 2 60 0 4 3708 1 2 59 1 4 3709 11 2 64 1 4 3710 0 1 67 1 4 3711 2 4 53 1 4 3712 13 4 54 0 4 3713 3 3 57 1 4 3714 0 3 64 0 4 3715 3 5 60 1 4 3716 1 5 61 0 4 3717 0 5 50 1 4 3718 3 5 53 1 4 3719 1 5 56 0 4 3720 2 5 71 1 4 1161 4 3 52 1 3 1162 5 2 54 1 3 1163 6 1 51 0 3 1164 7 4 56 0 3 1165 8 4 53 1 3 1166 9 1 63 1 3 1167 10 4 60 0 3 1168 11 4 50 1 3 1169 0 2 52 1 3 1170 4 1 54 0 3 1171 0 1 54 1 3 1172 0 3 52 1 3 1173 12 1 61 1 3 1174 0 1 57 0 3 1175 0 4 73 1 3 1176 0 4 75 0 3 1177 13 3 52 0 3 1178 3 1 51 1 3 1179 0 1 53 0 3 1180 0 1 50 1 3 1181 13 2 68 0 3 1182 2 2 61 1 3 1183 0 5 70 0 3 1184 0 5 65 1 3 1185 0 3 51 0 3 1 2 2 54 0 1 2 1 2 51 1 1 3 4 5 58 0 1 4 5 2 73 1 1 5 6 1 56 0 1 6 7 1 53 1 1 7 8 3 71 1 1 8 9 5 74 1 1 9 10 5 69 0 1 10 11 4 67 0 1 11 12 1 70 0 1 12 1 1 67 1 1 13 0 3 64 1 1 14 13 3 69 0 1 15 3 3 65 1 1 16 0 4 65 0 1 17 2 5 61 0 1 18 0 3 66 0 1 19 5 3 62 1 1 20 0 2 63 0 1 22 0 5 54 1 1 23 0 3 66 0 1 24 0 3 60 1 1 25 0 1 68 0 1 26 0 4 60 1 1 end label values country countryn label def countryn 1 "Austria", modify label def countryn 2 "Switzerland", modify label def countryn 3 "Belgium", modify label def countryn 4 "Czech Republic", modify
Code
Code:
global X "age gender" gen age1=. gen age2=. gen age3=. gen age4=. gen gender1=. gen gender2=. gen gender3=. gen gender4=. foreach x of global X { forval i = 1/4 { qui { conindex `x' if country==`i', rankvar(wealth) truezero robust sca CI_`x'`i' = r(CI)*1000 } sca di CI_`x'_`i' replace `x'`i' = CI_`x'`i' if country==`i' list `x'`i' } }
0 Response to How to make this graph with stack option?
Post a Comment