help for mydays

List of specified days, say for axis labels or ticks

mydays [if] [in] , local(macname) [ days(numlist) last months(numlist) format(date_format) ]


mydays displays a formatted list of specified days that lie within the range of a tsset daily date variable describing a time series and puts the numeric version of that list in a specified local macro. The result may be useful for specifying axis label or tick positions on graphs of time series.


To use mydays, you must have a time series dataset defined by a daily date variable. If it has not been done previously, you must tsset. For example:

. sysuse sp500, clear . tsset date

If you ask for a time series graph, Stata by default uses its best guess at some "nice" dates as labelled dates on the time axis, in this case 1 January 2001, 1 April 2001, 1 July 2001, 1 October 2001, 1 January 2002.

. tsline high low

Now suppose you do not like that default. In principle you just need to spell out which days you want, but that can be tedious. Differing month lengths and the existence of leap years mean that what you want is unlikely to be a regularly spaced series of days. mydays offers an alternative. Unless it is obvious otherwise, it takes the tsset time variable to be a daily date. Suppose you want the last days of each quarter:

. mydays, last months(3(3)12) local(last) . tsline high low, xla(`last', format(%dn_d))

The process thus entails two steps: define the days you want with mydays, and then feed the name of the macro containing them to the graph command, here tsline. In this case, mydays does not show 31 December 2000, as it is not within the range of the data, but that could be added on the fly:

. tsline high low, xla(`=mdy(12,31,2000)' `last', format(%dn_d))

For days other than the last of each month, you need to specify an argument for days().


local(macname) inserts the numeric list of daily dates in local macro macname within the calling program's space. Hence that macro will be accessible after mydays, say for graph or other graphics commands. This option is required.

days() specifies the days of each month you want to include. The argument must be a numlist of one or more integers between 1 and 31. Impossible dates implied by this and your choice of months() (e.g. 31 February) will be ignored.

last specifies that the last day of each month specified should be included in the macro. Leap year corrections are automatic. (Note to programmers: calculating in terms of mdy(#,1,#) - 1 avoids ringing the changes on 28, 29, 30 and 31 days in each month and on ordinary and leap years.)

At least one of days() and last must be specified.

months() specifies the months you want to include. The argument must be a numlist of one or more integers between 1 and 12. The default is all months, i.e. 1/12.

format() specifies a format controlling the display of the list. By default the format of the tsset time variable will be used. This option has no effect on the contents of the macro and is intended only to help in checking that the list contains what is desired.


. sysuse sp500, clear . tsset date . mydays, day(1) local(ticks) . mydays, day(15) local(labels) . tsline high low, xla(`labels', labsize(*0.9) notick format(%dm)) xtic(`=mdy(1,1,2001)' `ticks' `=mdy(1,1,2002)')


Nicholas J. Cox, Durham University n.j.cox@durham.ac.uk

Scott Merryman, Risk Management Agency/USDA smerryman@kc.rr.com


This program grew out of a question from Eric Wruck.

Also see

Online: help for axis label options