Announcement

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

  • Graphing mean values of all ids combined for a panel dataset

    Hi,
    I have a panel dataset with observations for approx 400 cities over a number of years. I would like to make a simple graph showing how the mean value of the y-variable (in my case cinema tickets purchased) has changed over the years. The problem is, as far as I have understood using the syntax "xtline", it is only possible to either choose a single city to display graphically, or all of them. What I would like to do specifically, is graph a single line which represents the overall mean value calculated from ALL of the cities combined. The "overlay" option puts all the cities onto one graph, but then I end up with 400 lines, one for each city, when what I really want is just one. Is this possible, and if so, how do I do it? It must be a very simple action but I just havn't figured it out!
    Thanks in advance!

  • #2
    Try this
    Code:
    bysort year: egen mean_y = mean(y_variable)
    egen byte flag = tag(year)
    graph twoway line mean_y year if flag, sort

    Comment


    • #3
      Hi Lauren, besides Clyde's insightful suggestion (lets you know what you are doing), if you are a lazy one like me, you may prefer the user written program called "lgraph" written by Timothy Mak.

      Type
      Code:
      ssc install lgraph    /*to install the program*/
      
      lgraph y year  /*this will give you for the overall 'y' mean for each year collapsing all districts*/
      
      lgraph y year, err(semean/95)  /*this with S.E / 95% CI bars of the means for each year */
      There are other options, see the help file.
      Roman

      Comment


      • #4
        thank you for lgraph!

        Comment

        Working...
        X