Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Can't display countries on two-way graphs

    Hello statalist.

    I am trying to plot confidence intervals of some estimates calculated indexes from survey data on country level.
    That is, I want a graph of lines showing each countries 95% confidence interval along with an indicator for the mean.
    However, whenever I try to do so with my encoded iso3-code as the x-axis i get the results in the picture attached. I want an even space between the intervals, and most importantly I want the x-axis to not be a numerical representation, but either the country-name or the iso3 countrycode. For the life of me, I can't figure out, how to stop Stata from listing the countries as numerical values. My code is below:

    egen lower_gini = pctile(indgini_year), by(iso3num year) p(2.5)
    egen upper_gini = pctile(indgini_year), by(iso3num year) p(97.5)
    egen mean_gini = mean(indgini_year), by(iso3num year)

    twoway (scatter mean_gini iso3num if year == 2020, mcolor(red)) ///
    (rcap lower_gini upper_gini iso3num if year == 2020, lcolor(red)), ///
    legend(label(1 "2010") label(2 "2020")) ytitle("Perceived Gini coefficient") xtitle("Country")
    Click image for larger version

Name:	Screenshot 2023-05-18 at 00.26.41.png
Views:	1
Size:	313.7 KB
ID:	1713984
    Click image for larger version

Name:	Screenshot 2023-05-18 at 00.26.54.png
Views:	1
Size:	78.0 KB
ID:	1713985


    Furthermore I have uploaded a picture of a representative example of what I am looking to create.


    Thank you very much in advance!


  • #2
    You won't get what you don't ask for, as none of your syntax will show country names as text or ensure regular spacing.

    You need please to give us a data example

    Code:
    dataex iso3num !!! mean_gini if year==2020
    where !!! should be omitted if iso3num holds country names as value labels and otherwise should be whatever holds country names.

    Getting what you ask for will be just the first of your problems:

    1. Why does iso3num define a meaningful order? As in your ideal graph, it makes more sense to sort on whatever measure is of most concern.

    2. I count 29 countries and their names won't be easy to read unless you change to a horizontal display. Even the example with 13 countries has awkward and unfriendly sloping labels.

    3. Why label 2020 data with 2010? (This one should be trivial.)

    Comment

    Working...
    X