Announcement

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

  • Time series graph problem

    Hello everyone,

    I have monthly data from 2007m1 to 2017m11 and when I make a time series graph something happens and I can't solve it. As you can see in the graph below it takes also the year 2006 and the 2018 and I don't have that data. How can I fix this problem?

    Thank you very much for your help.



    Click image for larger version

Name:	Graph.png
Views:	1
Size:	67.3 KB
ID:	1427193
    Last edited by Ramon Medina; 23 Jan 2018, 19:29.

  • #2
    It doesn't seem outrageous that Stata defaults to axis labels for January 2006(2)2018 for these data. But you can do better and here's one way.

    Your problem can be reproduced with a sandbox like this:

    Code:
    clear 
    set obs 131 
    gen t = ym(2006,12) + _n 
    gen y = rnormal()
    format t %tm 
    line y t
    How to do better? Code first, then commentary.

    Code:
     
    format t %3.0f
    line y t , xtick(`=ym(2006,12) + 0.5'(12)`=ym(2017,12) + 0.5', tlength(*3)) ///
    xla(`=ym(2007,6) + 0.5'(12)`=ym(2017,6)+0.5', noticks format(%tmCCYY)) xtitle("")
    First, I switch off the monthly date format and substitute a plain integer format. That may seem crazy but for reasons I don't understand it doesn't mesh with the tricks here.

    Then I arrange for

    * Ticks to be shown at year ends. Those are halfway between December and January and spaced 12 months apart. You'd be pushed to spot that being slightly wrong (e.g. showing years ends at December or January), but it is not difficult to ensure that it's done exactly right. The `= ' syntax ensures calculations on the fly. I make those ticks long.

    * Year labels to be shown at year middles, halfway between June and July. I remove the corresponding ticks.

    * The title to be zapped. Who needs t or year orwhatever? The reader who can't work out what 2006 or 2016 means really needs a different occupation.

    Here's the graph.


    Click image for larger version

Name:	nicedates.png
Views:	1
Size:	87.3 KB
ID:	1427231


    More at http://www.stata-journal.com/sjpdf.h...iclenum=gr0030

    SJ-7-4 gr0030 . Stata tip 55: Better axis labeling for time points/intervals
    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . N. J. Cox
    Q4/07 SJ 7(4):590--592 (no commands)
    tip on labeling graphs for time points and time intervals


    Comment


    • #3

      Thank you very much for your help. I'll take the advice.


      Comment

      Working...
      X