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

RE: st: date

From   "Nick Cox" <>
To   <>
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


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


*   For searches and help try:

© Copyright 1996–2023 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index