Announcement

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

  • (two-way plots) How to sort countries according to magnitudes of an index

    Dear all,

    I want to use twoway command to make a scatter plot where countries are sort by the magnitude of index variable. For example, the order I wanted is 3, 1, 4 and 2. Any help is much appreciated.

    Thank you.

    Data
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(index ub lb country)
    -.22235993   -.1310528  -.3136671 1
    -.14211084 .0018675288  -.2860892 2
      -.307784  -.22378303  -.3917849 3
    -.18752892  -.10114556 -.27391228 4
    end
    Code
    Code:
        twoway    (scatter index country,)    ///
                (rspike ub lb country,),     ///
                 xla(1/4) scheme(s2color)

  • #2
    See https://www.statalist.org/forums/for...ng-over-and-by and the advice to use myaxis from the Stata Journal.

    Here's indicative code. As in the linked thread, a horizontal display is likely to work better for real data.

    Code:
    clear
    input float(index ub lb country)
    -.22235993   -.1310528  -.3136671 1
    -.14211084 .0018675288  -.2860892 2
      -.307784  -.22378303  -.3917849 3
    -.18752892  -.10114556 -.27391228 4
    end
    
    myaxis COUNTRY = country, sort(mean index )
    
    scatter index COUNTRY || rspike ub lb COUNTRY, xla(1/4, valuelabel) scheme(s1color)
    Last edited by Nick Cox; 17 Feb 2023, 04:04.

    Comment


    • #3
      Many thanks Nick, it works perfectly.

      Comment

      Working...
      X