Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: date format


From   jean ries <[email protected]>
To   [email protected]
Subject   Re: st: date format
Date   Mon, 13 Dec 2004 12:16:40 +0100

Hans J. Baumgartner wrote:

Dear statalist,

I have got one variable in my data that comes in format “YYYYMM”, i.e. the first four digits correspond to the year and the last two to the month.

How can I translate this format into Stata elapsed date %d (see [U] 27)?

Try out -nsplit- which is available from SSC. With -nsplit- you could do:

. nsplit olddate, digits(4 2)
. gen dd = 1
. gen newdate = mdy(olddate2,dd,olddate1)
. format newdate %d_m_Y

Without -nsplit-, you could do:

. gen yy = floor(olddate/100)
. gen mm = mod(olddate,100)
. gen dd = 1
. gen newdate = mdy(mm,dd,yy)
. format newdate %d_m_Y

Of course, you might pick another value for the day, as suggested by Joseph Coveney.


*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/




© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index