Announcement

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

  • Customising Legend on Xtline so only a few panels are highlighted

    Hi,

    I am working with a large panel (>80) of historical prices ​over a number of years.

    I want to graph the panels over time. This is easy enough because I can use the xtline command and overlay the panels with a command like:

    xtline price, overlay legend(order())

    However as you can see from the attached photo I'm not gaining much useful information by having a legend with keys for all panels.

    I want to customize the legend so I can pick the most expensive/cheapest panels and just highlight those.

    While I do have the panel id's that I want to highlight, ie I can write

    xtline price, overlay legend(order(​id_a "firma" id_b "firmb" id_c "firmc")

    (where id_a id_b id_c are numerals corresponding to the panel id's of interest).

    However from some experimentation using xtline, I have noticed that what ​should ​go in the place of id_a, id_b, id_c are merely the corresponding keys of the panels in the xtline plot.
    ie. that go from 1, 2, 3, ....... , n. Where n is the amount of panels.
    2 Questions:
    1. How are the keys generated in xtline for plotting, is there a way to find the right key for the corresponding panel id of interest?
    2. Is there a better way for me to try and do this?


    Thanks,

    Appreciate the help.

    Marc

  • #2
    1. I believe it is the order the panels are currently sorted.

    2. Below are two different ways of creating such graph - xtline or twoway line, c(L)

    Code:
    webuse grunfeld, clear
    //Indentify largest/smallest panels
    qui sum kstock if year == 1954
    tab com if kstock == r(max) & year == 1954
    qui sum kstock if year == 1954
    tab com if kstock == r(min) & year == 1954
    
    xtline kstock ,overlay legend(order(1 "max" 10 "min")) /// 
     plot1opt(lw(medthick) lc(black))  /// 
     plot10opt(lw(medthick) lc(black)) name(gr1,replace)
    
    twoway line kstock  year, c(L) lw(medium) lc(gs10) /// 
     || line kstock year  if com ==1, lw(thick) lc(black) /// 
     || line kstock year if com == 10, lw(thick) lc(black) /// 
     || , legend(order(2 "max" 3 "min")) name(gr2,replace)

    Comment


    • #3
      Thanks Scott,

      However in your legend ordering and plot1opt and plot10opt - this relies on you knowing what plot1 and plot10 relate to?

      Comment


      • #4
        Yes. The first part of the example code is identify the minimum and maximum. Given the current sort order, the maximum for year 1954 first group while the minimum is group 10.


        Code:
        // Identify largest/smallest panels
        qui sum kstock if year == 1954
        tab com if kstock == r(max) & year == 1954
        qui sum kstock if year == 1954
        tab com if kstock == r(min) & year == 1954

        Comment


        • #5
          Hi
          I am having the same problem. I want to see the impact a law for 140 countries on my outcome variable. Want to see a overall scenario of y of 140 countries over 18 years..
          How can I set the command?
          Best
          Nuzaba

          Comment

          Working...
          X