Announcement

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

  • Plotting string variable on the same axis

    Year City Frequency
    2018 London 2
    2017 London 2
    2018 Manchester 6
    2017 Manchester 2
    I am trying to plot a graph with frequency against year. With the city being a string variable I am have been able to use the if function to plot essentially only one city at a time.
    is there a way I can write this so that I am able to get plot both London and Manchester on the same axes?

    Thanks in advance!

  • #2
    What kind of graph are you generating? Bar, line, or something else? Something like the following should work.

    Code:
    gr bar Frequency, over(City) over(Year) ytitle("Frequency")

    Comment


    • #3
      Originally posted by Andrew Musau View Post
      What kind of graph are you generating? Bar, line, or something else? Something like the following should work.

      Code:
      gr bar Frequency, over(City) over(Year) ytitle("Frequency")
      A line graph. A bar chart wouldn't work because everything would overlap on the x-axis. So was hoping to use the same axis and essentially have a line graph 1 on top of the other.

      Comment


      • #4
        Code:
        encode City, g(C)
        xtset C year
        xtline Frequency, overlay
        Present a data example using dataex if the above does not work. Refer to FAQ Advice #12 for details.

        Comment


        • #5
          Originally posted by Andrew Musau View Post
          Code:
          encode City, g(C)
          xtset C year
          xtline Frequency, overlay
          Present a data example using dataex if the above does not work. Refer to FAQ Advice #12 for details.
          Thank you that worked

          Comment

          Working...
          X