Announcement

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

  • Formatting Dates in graph dot

    I am trying to use graph dot of a continuous measure over a date measure. The date measure is formatted to display the date content I want, the HRF, but the graph shows the underlying numeric value, the SIF.

    Other than relabeling the dates in the over() option is there a way to have the graph display the formatted dates?

    Here are the data and simple graph:

    Code:
    clear *
    input int (date intake) byte discharge
    22005    2    0
    22006    9    0
    22007    0    0
    22008    2    1
    22009    20    2
    22010    17    2
    22011    26    16
    22012    56    23
    22013    84    34
    22014    119    43
    22015    98    84
    22016    115    59
    22017    66    68
    22018    90    62
    22019    83    88
    22020    71    94
    22021    56    68
    22022    47    63
    22023    30    39
    22024    13    56
    22025    37    31
    22026    17    50
    22027    13    42
    22028    9    28
    22029    9    26
    22030    2    20
    22031    1    14
    22032    2    23
    22033    1    16
    22034    0    23
    22035    0    8
    end
    
    format %tdDD-Mon date
    
    graph dot intake, over(date)
    Thank you,
    Alan

  • #2
    I guess one solution is to generate a string version of your date and graph over that.

    Code:
    gen sdate = string(date, "%tdDD-Mon")
    graph dot intake, over(sdate)

    Comment


    • #3
      You can define value labels and they will show by default.

      labmask (Stata Journal) allows you to avoid writing a tedious and error-prone loop.

      Code:
      set scheme s1color
      
      gen format = string(date, "%tdDD-Mon")
      
      labmask date, values(format)
      
      graph dot intake, over(date, label(labsize(small)))  vertical
      EDIT: Justin Blasongame posted a solution in #2, but string dates are just strings and won't reliably sort as you want. In the example data of #1 31-Mar is the first date but it sorts after 30-Apr.
      Last edited by Nick Cox; 04 May 2020, 11:11.

      Comment


      • #4
        Thank you, Justin and Nick, for your suggestions. Both work well.

        Best wishes,
        Alan

        Comment

        Working...
        X