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]

st: RE: RE: RE: date functions: from monthly to quarterly only through daily?


From   Nick Cox <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   st: RE: RE: RE: date functions: from monthly to quarterly only through daily?
Date   Fri, 11 May 2012 17:36:13 +0100

Using -display- and nesting function calls are tips included in 

SJ-11-3 dm0058  . . . . . . . . Speaking Stata: Fun and fluency with functions
        . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  N. J. Cox
        Q3/11   SJ 11(3):460--471                                (no commands)
        a tour of easily missed or underestimated Stata functions

Nick 
[email protected] 

Impavido, Gregorio

Thank you Nick for the very useful suggestion of testing things first with -display-.

And thank you Tashi for earlier reply.

Nick Cox

As you say, there is no -qofm()- function to do this directly; so you need to do it indirectly. I guess you don't like the rather ugly code that seems to imply,  but it can be simplified a bit as 

gen timem = monthly(date,"MY")
gen timed = dofm(timem) 
gen timeq = qofd(timed)

can be telescoped to 

gen timeq = qofd(dofm(monthly("May2012", "MY")))

as there is no need to invoke functions one at a time, or to create a variable for each step in the calculation. When working out such problems, I usually test with -display-, so that 

. di  %tq qofd(dofm(monthly("May2012", "MY")))
2012q2

indicates that the main idea is right. 

Nick 
[email protected] 

Impavido, Gregorio

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()-

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