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

Re: st: date format


From   Joseph Coveney <[email protected]>
To   Statalist <[email protected]>
Subject   Re: st: date format
Date   Mon, 13 Dec 2004 19:38:56 +0900

Hans J. Baumgartner wrote:

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

Thanks for any suggestions

----------------------------------------------------------------------------

I think that you'll need to choose an arbitrary day of the month to settle
on.  Two choices that seem to be common are the first and the fifteenth.
The latter is more common to represent "year known, month known, but day not
known" (not remembered by respondent).

Joseph Coveney

set obs 2
generate str6 part_dt = "200210"
replace part_dt = "190601" in 2
replace part_dt = substr(part_dt, 1, 4) + "-" + substr(part_dt, 5, 2) + ///
  "-" + "01"
/* If the quoted ASCII minus sign doesn't work with your system,
   use -char(45)- instead */
generate int date = date(part_dt, "ymd")
format date %dCY-N-D
list, clean

          part_dt         date
  1.   2002-10-01   2002-10-01
  2.   1906-01-01   1906-01-01

.





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