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/