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: How to label days of week and hours of day on x axis
From
"G. Dai" <[email protected]>
To
statalist <[email protected]>
Subject
st: How to label days of week and hours of day on x axis
Date
Wed, 2 Nov 2011 13:55:37 -0600
Dear all,
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.
thanks for reading and expect your suggestions.
G.
*
* 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/