Announcement

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

  • including a legend with labels in an overlay graph

    Dear all,

    I would like to add to an overlay plot a legend, that gives for every color used the name of the region. Here I got 3 regions, that are already labeled, but for some reason the code below only produces a legend showing mean_var three times. What am I doing wrong?

    Code:
    graph twoway line mean_var year if year<2020 & region==1 || line mean_var year if year<2020 & region==2 || line mean_var year if year<2020 & region==3
    Best,
    Julian

  • #2
    I produced mean_var using:

    Code:
    bysort year region: egen mean_var=mean(var) if var!=.

    Comment


    • #3
      Nevermind. I solved it myself using the following option:

      Code:
      legend(order(1 "Eastern Europe and post Soviet Union" 2 "Latin America" 3 "North Africa and the Middle East"))

      Comment


      • #4
        If the values of region are labeled, this would produce a similar result that is more robust than using legend(order(...)):
        Code:
        xtset region year
        xtline mean_var if year<2020, overlay

        Comment

        Working...
        X