Announcement

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

  • Re-sorting variables in the x-axis

    Hello,

    I am trying to make a plot of incidence rate ratios over site using

    twoway rcap irr_lb irr_ub _site, lc(black) || scatter irr _site, mc(black) ti(
    > "IRR of 5-17y to <5y in pre-PCV period by site") yti(IRR) xti(Site) xlabel(1 2
    > 3 4 5 6 8 9 10 11 12 13 16 17 19 20 21 23 26 27 30 32 33 34 35 36 37 38 40 41
    > 42 43 44 45, valuelabel angle(45))


    I want to sort the sites in a different order than they are in the dataset and tried using gen double obsorder = _n
    with no luck.

    Any help would be appreciated.

    Thanks!


  • #2
    To get a different order to the graph, you need a different x axis variable. Why not show some example data?

    Comment


    • #3
      _site irr irr_lb irr_ub obsorder
      Denmark 0.21421 0.098672 0.353252 5
      Switzerland 0.353252 0.137113 0.532342 2
      Northern Territory 0.54632 0.104696 0.76452 4
      Spain Navarra 0.12421 0.020892 0.23434 3
      Israel 0.43132 0.082485 0.6241 1
      For example, the sites are in the x-axis and irr is the y-axis. The graph will be Denmark, Switz, etc. I wish for it to be ordered as shown in the obsorder above. Is there a way to do this? Thanks!

      Comment


      • #4
        Please read through the FAQs and familiarize yourself with how to present data examples using dataex. Since you have a variable that defines the order, you can install labmask from Stata Journal by Nick Cox and label this variable with the names of the countries. For readability, you may want to have the country names on the y-axis, so look at the option -horizontal- in the help of tw rcap.

        Code:
        decode _site, gen(country)
        *findit labmask and click link to install
        labmask obsorder, val(country)
        Thereafter, use "obsorder" in place of "_site". There is no need to specify all the numbers from 1 to 45 in the command, you can simply have

        Code:
        xlab(1(1)45)
        Last edited by Andrew Musau; 03 Apr 2020, 15:13.

        Comment

        Working...
        X