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

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

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

 From Nick Cox To "'statalist@hsphsun2.harvard.edu'" Subject st: RE: How to label days of week and hours of day on x axis Date Wed, 2 Nov 2011 20:38:20 +0000

```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
week

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-.

Nick
n.j.cox@durham.ac.uk

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:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```

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