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


From   Nick Cox <njcoxstata@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: string date
Date   Thu, 2 Feb 2012 09:50:48 +0000

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 <njcoxstata@gmail.com> 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 <rzeng@wisc.edu> 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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index