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, is already up and running.

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

Re: st: string date

From   Nick Cox <>
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


On Wed, Feb 1, 2012 at 11:20 PM, Rui Zeng <> 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:

© Copyright 1996–2015 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index