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

st: run-together dates [was :... syntax; option real & varname ]


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: run-together dates [was :... syntax; option real & varname ]
Date   Thu, 15 Aug 2002 16:41:09 +0100

VISINTAINER PAUL

Quick question.

I have a numeric variable (float) of the form:  19460515

The variable actually refers to the date, May 15, 1946.  Truncating
and
concatenating functions appear to operate only on string variables.
What
approach can I use to change this to the correct date?

>>>

Manual discussion: [U] p.287

FAQ discussion:

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

First principles approach:

. gen year = real(substr(string(date),1,4))
. gen month = real(substr(string(date),5,2))
. gen day = real(substr(string(date),7,2)
etc.

Canned solution:

. ssc inst todate
. todate date, p(yyyymmdd) g(sdate)

Recommendation: use the resources available.

Nick
[email protected]

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