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
Wed, 1 Feb 2012 23:39:26 +0000
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.
Nick
On Wed, Feb 1, 2012 at 11:20 PM, Rui Zeng <[email protected]> wrote:
> Dear Statalister,
>
>
> 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!
>
>
> Rui
*
* 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/