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: string date


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: string date
Date   Thu, 2 Feb 2012 12:26:45 +0000

Sorry, correction: That is an alternative to yofd(dofq(yourvar)).

Nick

On Thu, Feb 2, 2012 at 9:50 AM, Nick Cox <[email protected]> wrote:
> An alternative to quarter(dofq(yourvar)) is 1959 + ceil(yourvar/4).
> This follows directly from the rule that quarters run 1 ... 4 in each
> calendar year and Stata's rule that the first date of any kind in 1960
> is numbered 1. So in 1960 quarterly dates run 1..4 which round up to 1
> when divided by 4 and in 2012 quarterly dates run 208 ... 212 which
> round up to 53 when divided by 4.
>
> On Wed, Feb 1, 2012 at 11:39 PM, Nick Cox <[email protected]> wrote:
>> There is some ambiguity here.
>>
>> If -yourvar- is a numeric variable with such a format assigned then
>> the year is yofd(dofq(yourvar)) and it is itself a quarterly date. The
>> quarter of year which runs 1...4 is quarter(dofq(yourvar)) or
>> mod(yourvar, 4) + 1.
>>
>> If -yourvar- is string, then year is real(substr(yourvar,1,4))  and
>> the quarter of the year is real(substr(yourvar, -1, 1)).
>>
>> To solve these problems, you just have to read the help to find the
>> right functions. Nothing is esoteric or hidden; equally there are so
>> many possibilities that it can easily take a few minutes to find the
>> solution.
>
> On Wed, Feb 1, 2012 at 11:20 PM, Rui Zeng <[email protected]> wrote:
>
>>> How can I extract year and quarter from a string format date suhc as
>>> "1987q1"? I can not use the format command to transfer from string to %tq
>>> format. thanks!

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