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

Re: st: String to date

From   cb23 <>
Subject   Re: st: String to date
Date   Wed, 30 Oct 2002 16:17:37 +0000

There is an easier way, two as far as I can see.

You can split the string up based on

i) the positioning of the .
ii) the consistent locations of the numbers.

So for the simplest case of ii) you could

compress dob
gen str2 dob_day = substr(dob,1,2)
gen str2 dob_month = substr(dob,3,2)
gen str2 dob_year = substr(dob,5,2)
destring dob_*, replace
gen dob1 = mdy(dob_day,dob_month,dob_year)
format dob1 %d

"Ganesh, Saravana" wrote:
> Dear Statalisters
> I have a dataset in which the date of birth(dob) is entered in the
> format 01.08.45( Stata has recognised this as a string (str11)
> variable. Is there an easier way of making this as date format or do I
> have to painfully retype all the values in the variable as dates
> recognised by STATA?
> Any help will be appreciated.
> Thanks in advance
> ganesh
> Mr J Saravana Ganesh FRCS(Ed. & Glasg.)
> Clinical Research Fellow
> UK National Audit of Intrathoracic Transplantation
> Clinical Effectiveness Unit
> The Royal College of Surgeons of England
> Lincoln's Inn Fields
> London WC2A 3PE
> Direct line: 02078696620
> Fax: 02078696644
> This e-mail and any attached files are confidential and are intended
> solely for the use of the individual or entity to whom they are
> addressed.
> This communication represents the originators personal views and
> opinions, which do not necessarily reflect those of The Royal College of
> Surgeons of England.
> If you are not the intended recipient, or the person responsible for
> delivering the e-mail to the intended recipient, be advised that you
> have received this e-mail in error, and that any use, dissemination,
> forwarding, printing or copying of this e-mail is strictly prohibited.
> Registered Charity Number: 212808
> *
> *   For searches and help try:
> *
> *
> *
tel;cell:0795 818 3140
tel;fax:01904 432 700
tel;work:01904 432 694
org:NPCRDC;Centre for Health Economics
title:Research Fellow
adr;quoted-printable:;;Alcuin D=0D=0AUniversity of York=0D=0AHeslington;York;North Yorkshire;YO10 5DD;UK
fn:Chris Bojke

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