Announcement

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

  • Doubt about labeling x-axis (double time?)

    Hello everybody,

    I was practicing again the graphical part of STATA and I wanted to know if it is possible to do what appears on the x-axis (attached image).

    The most I have been able to do is that instead of showing the quarters only the year appears, but I don't know how to make the quarter appear with a letter like the one in the image and the year below the quarters.

    I hope I have explained.

    As always, thanking you in advance for your valuable comments.


    Code:
    clear
    
    input int date float gnp96
    28 3631.6
    29 3644.5
    30   3672
    31 3703.1
    32 3757.5
    33 3818.3
    34 3841.6
    35 3861.8
    36 3906.8
    37   3915
    38 3937.8
    39 3922.9
    40   3922
    41 3922.3
    42 3961.3
    43   3931
    44 4027.3
    45   4042
    46 4064.7
    47 4072.9
    end
    
    format %tq date
    
    gen datestring = string(date,"%tq")
    
    gen qtly=substr(datestring,6,1)
    
    gen trim="I" if qtly=="1"
    replace trim="II" if qtly=="2"
    replace trim="III" if qtly=="3"
    replace trim="IV" if qtly=="4"
    
    
    
    local start1 = yq(1967,1)  
    local end1 = yq(1971,4)  
    local start2 = yq(1967,3)  
    local end2 = yq(1971,3)
    
    #delimit ;
    
    tsset date;
    
    tsline gnp96,
    
        xticks(`start1' (4) `end1', tlength(*0))
        xlabel(`start2' (4) `end2', noticks format(%tqCY))    
    
        ;
        
        #delimit cr
    Attached Files

  • #2
    Note -- the code below installs and uses Nick Cox's labutil set of commands from SSC:

    Code:
    ssc install labutil
    labmask date, values(trim)
    tsline gnp96 , xla(,format("%tqCY")) xmla(##4, valuelabel)
    Result:
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	53.0 KB
ID:	1673205

    Comment


    • #3
      All sorts of small tricks are possible. See e.g.

      SJ-19-3 gr0079 . . . . . . . . . Stata tip 132: Tiny tricks and tips on ticks
      . . . . . . . . . . . . . . . . . . . . . . . N. J. Cox and V. Wiggins
      Q3/19 SJ 19(3):741--747 (no commands)
      collection of small points on those small ticks, intended to
      explain what is not quite obvious -- or not quite obviously
      useful -- on reading the documentation


      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

      Code:
      clear
      
      input int date float gnp96
      28 3631.6
      29 3644.5
      30   3672
      31 3703.1
      32 3757.5
      33 3818.3
      34 3841.6
      35 3861.8
      36 3906.8
      37   3915
      38 3937.8
      39 3922.9
      40   3922
      41 3922.3
      42 3961.3
      43   3931
      44 4027.3
      45   4042
      46 4064.7
      47 4072.9
      end
      
      format %tqq date
      set scheme s1color 
      
      twoway connected gnp96 date, xmla(28/47, tlength(0)) xtick(27.5(4)47.5, tlength(*5)) xla(29.5(4)45.5, format(%tqCCYY) tlength(*2) tlcolor(none)) xtitle("")

      Click image for larger version

Name:	timeticks.png
Views:	1
Size:	25.3 KB
ID:	1673208


      To spell it out:

      Tick length and color can be tuned. A longer or shorter tick -- even one with no colour -- can be useful.

      You can have minor labels as well as labels on any axis, leading to different sizes of labels.

      People usually can recall some teacher who went crazy if you didn't give titles to each axis. That teacher was usually right, but it's rare that you need to show a variable name (or its variable label) when time is one axis, especially if years are evident.

      Comment


      • #4
        Dear Ali and Nick

        Thank you very much, I was really struggling to analyze how you had done it. It is really a great help to have this excellent community. I hope someday I will be able to help in the same way you do.

        I will read carefully what Nick has attached.

        Greetings!

        Comment

        Working...
        X