Bookmark and Share

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]

Re: st: Label categorical axis of - graph box - with dates


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: Label categorical axis of - graph box - with dates
Date   Wed, 7 Nov 2012 11:44:47 +0000

Note that although Allan's work-around solves his problem completely,
it hinges on being able to specify one variable for what is shown and
another variable for the sort order. In other graph programs you might
not have both of those controls at once. If you couldn't do that, and
a -format()- suboption doesn't apply, another trick would be assign
value labels to the date variable that contained the date format.

Illustrating with Allan's problem

g sdate=string(idate,"%td")
labmask idate, values(sdate)
graph box y, over( idate, label(angle(30)))

should work too. Here -labmask- is from SJ.

Nick

On Tue, Nov 6, 2012 at 7:00 PM, Nick Cox <[email protected]> wrote:
> I'd guess that what's happening is that the categorical axis labels as
> shown are always strings. That's the general case, after all. If they
> really are strings, meaning values of a string variable, that works.
> If they really are value labels that might contain string characters,
> that works. If they really are numbers, then showing the same numeric
> characters as a string also works.
>
> So -format()- is here is regarded as irrelevant, as supplying a date
> format could not change a string.
>
> That's consistent with your work-around.
>
> I haven't dived into the -graph box- code, but that's my guess. From
> the programmer's point of view, it's intended behaviour; it's just
> that you can't get what you want without a trick. This may be why
> -format()- is not documented as a cat_axis_label option.
>
> Nick
>
> On Tue, Nov 6, 2012 at 6:43 PM, Nick Cox <[email protected]> wrote:
>
>> I'd want -format()- to work in that context. It's not listed as one of
>> the cat_axis_label_options, but I share Allan's surprise.
>>
>> On Tue, Nov 6, 2012 at 5:44 PM, Allan Reese (Cefas)
>> <[email protected]> wrote:
>>> This ought to be obvious; apologies if it's well documented elsewhere.
>>>
>>> A dataset where the group variable is a date, stored as integer with %td format:
>>> - tab idate -         shows the dates as 1apr2012 etc with count for each date
>>> - scatter y idate -   labels the X axis with date values, though not necessarily those in the data
>>> - graph box y, over(idate) -
>>>                       labels the categories with the internal (SIF) values
>>> - graph box y, over(idate, label( angle(30) format(%td) ) ) -
>>>                       rotates the labels; format is ignored but NOT flagged as error
>>>
>>> The workround is to create a string variable containing the date strings, use that for the labels but coerce the date ordering:
>>>
>>> - g sdate=string(idate,"%td")  -
>>> - graph box y, over( sdate, label(angle(30)) sort(idate)) -
>>>
>>> It seems a bug that the format is honoured by scatter but not by box, and another that a format option is accepted but ignored.
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


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