Announcement

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

  • two lpolyci with date on x-axis

    When I use two lpolyci or two lpoly to graph an outcome over a date, the date shows up as the underlying numbers, not Stata format dates. I see posts online about how to make your date format "nicer" when the date shows up to begin with (https://www.stata.com/support/faqs/g...s/date-labels/) but I don't see any mention of how to simply obtain dates on the x-axis.

    I can't find a stata dataset with a date within it, to make a reproducible example.

    But essentially this code has (badly formatted) dates on the x-axis (edate formatted %td):
    two scatter la2ctime edate

    But these two do not:
    two lpolyci la2ctime edate
    two lpoly la2ctime edate


    How to solve this? Thanks!

  • #2
    See the -format()- suboption of -xlabel-. Consider:

    Code:
    webuse sp500, clear
    twoway lpolyci volume date, xlab(,format("%tdCYm")) leg(off)
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	40.5 KB
ID:	1756458

    Comment


    • #3
      Here's some technique. Default labelling wasn't very good. For a notional 6 months in the first half of this year, I asked for axis labels at 1 and 15 of each month.

      Code:
      clear
      set obs 182 
      gen ddate = mdy(12,31,2023) + _n
      set seed 314159
      gen y = rnormal(0,3) + 0.2 * _n 
      
      twoway lpolyci y ddate , xla(, format(%td)) legend(ring(0) pos(11)) name(G1, replace)
      
      forval m = 1/6 { 
          local labels `labels' `=mdy(`m', 1, 2024)' `=mdy(`m', 15, 2024)'
      }
      
      twoway lpolyci y ddate , xla(`labels', format(%tdd_m)) legend(ring(0) pos(11))  name(G2, replace)

      Comment

      Working...
      X