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

RE: st: date


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: date
Date   Wed, 17 Sep 2003 17:11:31 +0100

Enzo Coviello

>> how do i get the date (year only) from a string variable that look
>> like  dd/mm/yyyy.

> gen str4 year = substr(datevar,7, .)

Note that this would fail if a date happened to be e.g. 1/01/2001
or even 1/1/2001. In short, it depends on all dates being
exactly of the form specified. If you went this route
it's safer to work from the end and work with

substr(date,-4,4)

and safer yet to work with -split-, as Roger Newson
suggested. Note in that case the -destring- option.

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