Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Re: date format


From   n j cox <n.j.cox@durham.ac.uk>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Re: date format
Date   Thu, 25 Oct 2007 17:50:03 +0100

Everyone's right, but there is scope for a little
more explanation.

There is an FAQ at
How do I convert date variables into Stata elapsed dates when the numbers run together, like 4151999?
http://www.stata.com/support/faqs/data/dateseq.html

Stata 9 or earlier: Elizabeth recommends -todate- from
SSC. I agree with that as a good solution. As far as I
know, nothing in Stata 10 breaks it. -todate- can handle
several date variables at once, which may be a feature
for some users. Naturally, you could also use a loop over
variables with calls to -date()- in Stata 10.

Stata 10: As Alexandra points out, -date()- can now
handle run-together dates.

There is a variant on her solution. Instead of using
-tostring- for a numeric variable, you can get there
directly with

gen datenew=date(string(dateold), "YMD")

-tostring- is at heart an elaborate wrapper for -string()-.
Its extra bells and whistles can be useful when you need
them, but I can't see much harm in just using -string()-
on the fly.

Nick
n.j.cox@durham.ac.uk

Elizabeth Rainwater
-------------------

There may be a new trick in Stata 10, but in Stata 9 I use the
user-written -todate-, available from SSC (-ssc install todate-). They
syntax is:
todate old_date, gen(new_date) pattern(yyyymmdd) format(%d)

Alexandra Griffiths
-------------------

Just use:

gen datenew=date( dateold, "YMD")
format datenew %td

If your date variable is not a string variable then run this (below)
first to convert it to a string:

tostring datesold, replace

Dan Rodriguez
-------------

Need to convert date format of YYYYMMDD into Stata date format. Does anyone have a short do-file to accomplish this?

*
* 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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index