Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: RE: RE: RE: How to label days of week and hours of day on x axis

From   Nick Cox <>
To   "''" <>
Subject   st: RE: RE: RE: How to label days of week and hours of day on x axis
Date   Wed, 2 Nov 2011 21:01:45 +0000

That can be automated with numlists. Again, this is explained in -help axis label options-. 


-----Original Message-----
From: [] On Behalf Of Guang Dai
Sent: 02 November 2011 20:47
Subject: st: RE: RE: How to label days of week and hours of day on x axis

hi Nick,
thanks for the clarification on week.
For most of the cases, speeling all the labels and ticks desired is a what I do. However, my need to draw the same graph for many weeks in many years, spelling all the labels
is a daunting job.. 

Guang Dai | Economist, Market Surveillance Administrator | 403.705.3183 | #500, 400 - 5th Avenue S.W., Calgary AB T2P 0L6 | 
-----Original Message-----
From: [] On Behalf Of Nick Cox
Sent: Wednesday, November 02, 2011 2:38 PM
To: ''
Subject: st: RE: How to label days of week and hours of day on x axis

On your first question: I think you are misunderstanding what -week()- does. There is a discussion in 

SJ-10-4 dm0052  . . . . . . . . . . . . . . . . Stata tip 68: Week assumptions
        . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  N. J. Cox
        Q4/10   SJ 10(4):682--685                                (no commands)
        tip on Stata's solution for weeks and on how to set up
        your own alternatives given different definitions of the

In essence, week 1 in any year starts on 1 January, and so forth. So the weeks start on whatever day of the week 1 January is. -week()- is thus quite independent of -dow()-'s idea of when the week starts. 

What the Tip discusses is summarised above. 

On your other questions, the trick is simply that you must spell out all the labels  and ticks that you want if the default does not provide them, so the answers lie in the help for -axis label options-. 


G. Dai

I have some difficulties to draw a graph with hour of days within a week as a time series x axis.

To be more specific, please take the following example ***************************Example Begins************************ *****generate the date set as an example***** clear set obs 744 gen year=2011 gen month=7 gen date=_n replace date=mod(date,31)+1 gen hour=_n replace hour=mod(hour,24) gen price=100*runiform() gen quant=5+2*abs(rnormal(1,5))

*from year, month and date to generate week and day of week.
gen week=week(mdy(month, date, year))
gen dow=dow(mdy(month, date, year))
gen myday=dhms(mdy(month, date, year), hour,0,0) format myday %tc

***draw a graph showing price and quant on each day and each hour of the given week tsset myday,c twoway (tsline price if year==2011&week==27, yaxis(1) )(tsline quant if year==2011&week==27,yaxis(2)) /// , tlabel(,format(%tcDay) grid ) xmlabel(,format(%tcHH)) ttitle("July,2011")ttitle("Day of the Week") ///  ytitle("Market Price") ytitle("Quantity Bought",axis(2))

*********************Example Ends***************

The first problem with the graph is that the week in the graph starts with  Saturday, not the one we expected as Sunday, which is the first day of a week. I know this is related to the way Stata defines week. But how can I make it consistent with the "tradition" way?

Second, on the graph, only Sat, Mon, Wed and Sat are labeled, but I definitely want to see all days of the week from Sat to Mon. How?

Third,  even though xmlabel(,format(%tcHH))  is used in the the command, we don't see the minor labels showing the hours within each day. How to make it work? Of course, I'm looking for labeling all hours, but hours like 0,6,12, 18 would be great.

*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index