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: date functions: from monthly to quarterly only through daily?


From   Christopher Baum <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: date functions: from monthly to quarterly only through daily?
Date   Sat, 12 May 2012 08:09:24 -0400

<>
On May 12, 2012, at 2:33 AM, Gregorio wrote:

> I have a string variable containing quarterly dates in the form:
> 
> . li date
> 
> 	date 
> 1.	Dec1977 
> 2.	Mar1978
> .....etc.
> 
> I want to convert it into quarterly date (Stata format).  Is there a better way than the following?
> 
> * begin code
> gen timem = monthly(date,"MY")
> gen timed = dofm(timem) 
> gen timeq = qofd(timed)
> format timeq %tq
> * end code
> 
> I could not find a -qofm()- function but ideally, I would like to get it in the first line through an the right specification of -quarterly()-

A one-liner will suffice:

g yq = qofd(dofm(monthly(date,"MY"))) 

You might then want to

format yq %tq

Kit


Kit Baum   |   Boston College Economics & DIW Berlin   |   http://ideas.repec.org/e/pba1.html
                             An Introduction to Stata Programming  |   http://www.stata-press.com/books/isp.html
  An Introduction to Modern Econometrics Using Stata  |   http://www.stata-press.com/books/imeus.html


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