Announcement

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

  • ordering the graphs (multiple graphs)

    Dear all,

    I have a problem in ordering the graphs (ascending order) in a panel dataset. I have 28 countries variable name `cty' and 10 years observations for each country, variable `year'.
    I want a graph line (of variable `var1' ) for each country with the mean (line and number for instance on the mean line) over the 10 years. I also need an ordering from the lowest mean to the highest mean. In the graph, the country with the lowest mean must appear first, the second must appear second and so on ... and the last country must have the highest mean.
    First I calculate the mean for each country:
    encode cty, generate(cty2)
    xtset cty2 year
    by cty, sort: egen m_var1=mean(var1)
    sort m_var1 year

    1) the most straight ford way is to use xtline:

    xtline var1 m_var1, tlabel(#3)

    Here I have two problems, first STATA shows the graphs for each country in an alphabetical ordering (name of the country: AT, BE, BG, DE, FR, ... UK)). I have checked the option of "xtline", it is impossible to change the ordering (contrary to "bar graph" where "sort" can be used). Second I did not find any way in making appear on the graph the mean (#).

    2) I thought that "graph twoway" offers more options, and so I tried to do the same:

    graph twoway tsline var1 m_var1, by(m_var1)

    Here I have the ordering of the countries as I wish, and the number m_var1 by country appears in the title of the graph. However, the problem is that the name of the country does not appear at all in the graph!
    Of course I tried to use "label" inside "title" but I did not find any solution.
    I am sorry and also myself surprised that I am obliged to come to this forum to ask for help for such a basic question, but I really do not find the solution.
    Thank you for your help.
    kind regards,
    rv







  • #2
    What I often do in these cases is

    * create a new ordering variable based on the order of the means (breaking fortuitous ties by the original ordering variable)

    * assign value labels based on the original names

    In your case, this could be

    Code:
    egen newcty = group(m_var1 cty) 
    labmask newcty, values(cty) 
    tsline <whatever>, by(newcty)
    You must install labmask to do this.

    Code:
    search labmask, sj
    points to a discussion and a download location.

    Comment


    • #3
      Thank you a lot Nick for the tip "labmask", it works perfectly well!

      Comment

      Working...
      X