I am having some data from IMF for a panel data for countries. Countries are classified by income and region. I provide a sample of my data below at the end of my inquiry.
Where index1, index2a, and index2b are quality indexes I have produced and ka is the variable of interest. I am trying to reproduce the attached graph.
Array
I am using the following code in order to create a bar graph classifying countries by their IMF region.
Code:
recode ts (1980/1989 =1 "1980/1989")(1990/1999=2 "1990/1999")(2000/2009 =3 "2000/2009 ")(2010/2020=4 "2010/2020"), gen(decades) graph bar (mean) ka, over(imf_region) asyvar over(decades)
I have also tried with no success
Code:
line kaopen ts if ts>=1950 & imf_region1==1, lw(medthick) || bar kaopen ts if ts>=1950 & imf_income1==1, yaxis(2) fi(20) /// || line kaopen ts if ts>=1950 & imf_region2==2, lc(navy) lp(dash) || line kaopen ts if ts>=1950 & region3==1 || /// line kaopen ts if ts>=1950 & region4==1 || line kaopen ts if ts>=1950 & region5==1, /// lc(navy) lp(dash) graphr(c(white)) title("A: Case1 {sup:a}", size(medsmall)) /// ylabel(, axis(1)) ylabel(, axis(2)) xlabel(1950(10)2020) /// xtitle("") yline(0, lc(navy) lp(dash)) ytitle("", axis(1)) /// legend(label(3 "")) ytitle("", axis(2)) legend(label(2 "")) /// legend(order(1 4)) legend(col(1)) name(case1) nodraw
After that, while keeping the first Y constant, change the second Y and graph for index2a index2b.
Note that instead of varname, the label of the variables should be displayed.
Also, while I do have a code for the line graphs and the code I used should work, again with a second y at the right, I don't know how to draw the lines inside the same graph. I tried the by option, however it produces three different types of graphics. Not the desired way.
My first thought was to collapse, but then I got confused.
I would like to reproduce the graph in the image for countries and for the ka variable in the data according to their classification, with a second y at the right.
Finally, how is it possible to split it into two regions above and below, say region A on the top with title and region B at the bottom title with their title, and then a general title?
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input float ts str28(imf_region imf_income) str97 country float(ka index1 index2a index2b) byte(cat1 cat2) float(d1 d2) 1986 "Asia and Pacific" "AM" "Australia" .8800636 8.6 0 1 4 4 1 0 1987 "Asia and Pacific" "AM" "Australia" .9400318 2.7697804 0 1 4 4 1 0 1988 "Asia and Pacific" "AM" "Australia" 1 -4.5 0 1 4 4 1 0 1989 "Asia and Pacific" "AM" "Australia" 1 -4.5 0 1 4 4 1 0 1996 "Asia and Pacific" "AM" "Australia" .9400318 18.228453 0 1 4 4 1 0 1997 "Asia and Pacific" "AM" "Australia" .8800636 22.593 0 1 4 4 1 0 1998 "Asia and Pacific" "AM" "Australia" .8200954 27.6381 0 1 4 4 1 0 1999 "Asia and Pacific" "AM" "Australia" .7601272 48.458 0 1 1 4 1 0 2006 "Asia and Pacific" "AM" "Australia" .700159 31.889 0 1 1 4 1 0 2007 "Asia and Pacific" "AM" "Australia" .700159 29.87246 0 1 1 4 1 0 2008 "Asia and Pacific" "AM" "Australia" .700159 5.674 0 1 1 4 1 0 2009 "Asia and Pacific" "AM" "Australia" .700159 5.674 0 1 1 4 1 0 2010 "Asia and Pacific" "AM" "Australia" .700159 -6.130934 .2967033 .7032967 1 4 1 0 2011 "Asia and Pacific" "AM" "Australia" .700159 -34.113 1 0 1 4 1 0 2012 "Asia and Pacific" "AM" "Australia" .7601272 -34.113 1 0 1 4 1 0 2013 "Asia and Pacific" "AM" "Australia" .8200954 -17.802141 .7142857 .2857143 1 4 1 0 2014 "Asia and Pacific" "AM" "Australia" .8800636 22.975 0 1 1 4 1 0 1986 "Asia and Pacific" "EM" "India" .16434518 0 0 1 8 2 1 0 1987 "Asia and Pacific" "EM" "India" .16434518 0 0 1 8 2 1 0 1988 "Asia and Pacific" "EM" "India" .16434518 0 0 1 8 2 1 0 1989 "Asia and Pacific" "EM" "India" .16434518 0 0 1 8 2 1 0 1996 "Asia and Pacific" "EM" "India" .16434518 0 1 0 7 2 1 0 1997 "Asia and Pacific" "EM" "India" .16434518 0 1 0 7 2 1 0 1998 "Asia and Pacific" "EM" "India" .16434518 0 .21153846 .7884616 7 2 1 0 1999 "Asia and Pacific" "EM" "India" .16434518 0 .4917582 .5082418 7 2 1 0 2006 "Asia and Pacific" "EM" "India" .16434518 0 1 0 8 2 1 0 2007 "Asia and Pacific" "EM" "India" .16434518 0 1 0 8 2 1 0 2008 "Asia and Pacific" "EM" "India" .16434518 0 1 0 8 2 1 0 2009 "Asia and Pacific" "EM" "India" .16434518 0 1 0 10 3 1 0 2010 "Asia and Pacific" "EM" "India" .16434518 . . . 10 3 1 0 2011 "Asia and Pacific" "EM" "India" .16434518 . . . 10 3 1 0 2012 "Asia and Pacific" "EM" "India" .16434518 . . . 10 3 1 0 2013 "Asia and Pacific" "EM" "India" .16434518 . . . 8 2 1 0 2014 "Asia and Pacific" "EM" "India" .16434518 . . . 8 2 1 0 1986 "Asia and Pacific" "AM" "New Zealand" .8800636 -9.788 0 1 12 3 1 0 1987 "Asia and Pacific" "AM" "New Zealand" .9400318 -14.278473 0 1 12 3 1 0 1988 "Asia and Pacific" "AM" "New Zealand" 1 -21.986 0 1 12 3 1 0 1989 "Asia and Pacific" "AM" "New Zealand" 1 -21.986 0 1 12 3 1 0 1996 "Asia and Pacific" "AM" "New Zealand" 1 -6.882123 0 1 12 3 1 0 1997 "Asia and Pacific" "AM" "New Zealand" 1 -7.235 0 1 12 3 1 0 1998 "Asia and Pacific" "AM" "New Zealand" 1 -7.235 .33516484 .6648352 12 3 1 0 1999 "Asia and Pacific" "AM" "New Zealand" 1 -8.191456 1 0 12 3 1 0 2006 "Asia and Pacific" "AM" "New Zealand" 1 -29.707 1 0 12 3 1 0 2007 "Asia and Pacific" "AM" "New Zealand" 1 -29.707 1 0 12 3 1 0 2008 "Asia and Pacific" "AM" "New Zealand" 1 -21.978655 1 0 12 3 1 0 2009 "Asia and Pacific" "AM" "New Zealand" 1 37.456 1 0 12 3 1 0 2010 "Asia and Pacific" "AM" "New Zealand" 1 37.456 1 0 12 3 1 0 2011 "Asia and Pacific" "AM" "New Zealand" 1 35.647743 1 0 12 3 1 0 2012 "Asia and Pacific" "AM" "New Zealand" 1 -1.262 1 0 12 3 1 0 2013 "Asia and Pacific" "AM" "New Zealand" 1 -1.262 1 0 12 3 1 0 2014 "Asia and Pacific" "AM" "New Zealand" 1 -2.527769 1 0 12 3 1 0 1986 "Europe" "EM" "Turkey" .16434518 6.5 0 1 14 5 0 1 1987 "Europe" "EM" "Turkey" .16434518 6.464286 0 1 14 5 0 1 1988 "Europe" "EM" "Turkey" .16434518 5.2 0 1 14 5 0 1 1989 "Europe" "EM" "Turkey" .41687185 5.2 0 1 14 5 0 1 1996 "Europe" "EM" "Turkey" .16434518 29.073414 .49041095 .509589 14 5 1 0 1997 "Europe" "EM" "Turkey" .16434518 31.695776 0 1 14 5 1 0 1998 "Europe" "EM" "Turkey" .16434518 29.936 0 1 10 3 1 0 1999 "Europe" "EM" "Turkey" .16434518 14.872792 .3763736 .6236264 10 3 1 0 2006 "Europe" "EM" "Turkey" .16434518 5.187 0 1 13 4 1 0 2007 "Europe" "EM" "Turkey" .16434518 5.187 0 1 13 4 1 0 2008 "Europe" "EM" "Turkey" .4476323 . . . 13 4 1 0 2009 "Europe" "EM" "Turkey" .4476323 . . . 13 4 1 0 2010 "Europe" "EM" "Turkey" .4476323 . . . 12 3 1 0 2011 "Europe" "EM" "Turkey" .4476323 . . . 12 3 1 0 2012 "Europe" "EM" "Turkey" .4476323 . . . 12 3 1 0 2013 "Europe" "EM" "Turkey" .4476323 . . . 12 3 1 0 2014 "Europe" "EM" "Turkey" .4476323 . . . 12 3 1 0 end
0 Response to Twoway bar and line with 2 y-axes and labels
Post a Comment