Announcement

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

  • Working with dates in locals

    I have a program that outputs a graph with a semester date on the x-axis and the starting point is flexible, depends on a global.

    Now I want the x-axis labels to be adjusted automatically but I am finding it hard to work with dates in locals.

    Suppose I have some

    Code:
    global start 2004h1
    How can I use this to get something like

    Code:
    xlabel(1 "$start" 2 "${start}+1" ...)
    but with proper date formatting?

  • #2
    No need to use globals here. The easiest way is to create a separate xvar and use the -format()- suboption:

    Code:
    gen xvar2= xvar + th(2004h1)
    tw scatter yvar xvar2,  xlabel(`=th(2004h1)'/`=th(2004h1)+12', format(%th))
    but as you want it

    Code:
    local start di %th `=th(2004h1)'
    ..., xlabel(1 "`:`start''" 2 "`:`start'+1'"...)
    Last edited by Andrew Musau; 17 Mar 2023, 17:10.

    Comment

    Working...
    X