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

RE: st: date


From   Enzo Coviello <enzo.coviello@tin.it>
To   statalist@hsphsun2.harvard.edu
Subject   RE: st: date
Date   Thu, 18 Sep 2003 07:29:11 +0200

At 17.11 17/09/03 +0100, you wrote:
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.

Thanks prof Cox for your deeper comments.

Enzo


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

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

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