Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


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

Re: st: Dates in -graph bar-


From   Nick Cox <njcoxstata@gmail.com>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   Re: st: Dates in -graph bar-
Date   Wed, 12 Jun 2013 16:35:43 +0100

There is a presumption here that -over()- will mostly call up
categorical variables, i.e. string variables or numeric variables with
value labels. It so happens that your desired labels such as

"2007q1", "2007q2", ...

correspond in alphanumeric order to the  numeric order of the Stata
quarterly dates, here values such as

188, 189, ...

If you wanted to show e.g.

"Q1 07", "Q2 07"

using a -format-  %tq!Qq_Y

then the alphanumeric order of the strings  would be

"Q1 07" "Q1 08" ....   "Q2 07" "Q2 08" ...

etc. which is unlikely to be what you want.

So, a more general way to do it would be to use (a) the string values
containing the date formats you want as (b) the value labels of the
numeric dates you have. -labmask- (SJ) is one way of doing that.

gen sYear_Quarter = string(Year_Quarter, "%tq!Qq_Y")
labmask Year_Quarter, values(sYear_Quarter)


Nick
njcoxstata@gmail.com


On 12 June 2013 16:16, STOLOWY, Herve <stolowy@hec.fr> wrote:
> Dear Nick:
>
> It works perfectly fine.
>
> Once again, I thank you very much.
>
> Hervé
>
>
> On Wed, Jun 12, 2013 at 4:25 PM, Nick Cox <njcoxstata@gmail.com> wrote:
>> I would try
>>
>> gen sYear_Quarter = string(Year_Quarter, "%tq")
>>
>> ... , over(sYear_Quarter)
>>
>> Nick
>> njcoxstata@gmail.com
>>
>>
>> On 12 June 2013 13:31, STOLOWY, Herve <stolowy@hec.fr> wrote:
>>
>>> I have a question very similar to the one raised in:
>>>
>>> http://www.stata.com/statalist/archive/2010-04/msg00867.html
>>>
>>> I read the answer and some other threads on dates in graph
>>> (http://www.stata.com/statalist/archive/2011-10/msg00731.html) and do
>>> not find the answer for my problem.
>>>
>>> I want to make a graph with the command:
>>>
>>> graph bar Downgrade Upgrade if Crisis2 == 1, over (Year_Quarter)
>>>
>>> where Year_Quarter is formatted as  %tq. I have 8 quarters involved in
>>> the graphs (from 2007q1 to 2008q4).
>>>
>>> This produces a graph with the number corresponding to the quarter on
>>> the x-axis (from 190 to 197), rather than the actual quarter (e.g.
>>> '190' instead of '2007q1').
>>>
>>> How can I get the quarter to show up rather than the corresponding number?
>>>
>>> In the above mentioned thread, I read the solution. I do not
>>> understand why with a graph twoway, the label is by default the one I
>>> would like to have. With bar, it does not work by default. (But my
>>> graph cannot be twoway).
>>>
>>> I found the following solution:
>>>
>>> graph bar Downgrade Upgrade if Crisis2 == 1, over (Year_Quarter,
>>> relabel (1 "2007q1" 2 "2007q2" ... 8 "2008q4")).
>>>
>>> It works by it is painful. I was not able to use -mylabels-
>>> downloadable from ssc) to generate automatically the "relabel".
>> *
>> *   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/
>
> *
> *   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/

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index