Announcement

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

  • Changing the ticks' labels

    I have a graph its x axis shows week numbers (1-180). My unit of observation is week and I have data about 180 weeks. Now, I need to edit the x-axis to indicate years+quarters, instead of week numbers. For example, the ticks should change to y12q1, y12q2, y12q3. So, I need to delete the week numbers and add the year+quarter labels in their appropriate place.


    I really appreciate your help.

  • #2
    If your week variable already has a value label attached that captures years+quarters the solution is simple
    For a scatterplot
    Code:
    graph twoway scatter var1 weeks, xlabel(,valuelabel)
    If your week variable doesn't have a value label you can add it by hand
    Code:
    graph twoway scatter var1 weeks, xlabel(1 "y12q1" 2 "y12q2" 3"y12q3")
    But this is very cumbersome. It's better to generate a value label for your week variable with help of loop.
    Last edited by Evelyn Ersanilli; 16 Aug 2015, 03:27.

    Comment


    • #3
      I guess that your week 1 is the first week of 2012. Right?. Now, there is no exact relation beteen weeks and quarters, but a quarter is approximately 13 weeks (more precisely 13.045 weeks on average). Try this:

      Code:
      clear
      input week y
      1 55
      2 74
      3 54
      40 66
      50 70
      60 80
      179 99
      end
      
      gen quarter = week/13 + tq(2012q1)
      format quarter %tq
      scatter y quarter , xticks(#15)

      Comment


      • #4
        Thank you very much. I did it using the graph recorder but I will give your way a try. It sounds way better than mine. Thanks

        Comment

        Working...
        X