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

Re: st: String to date


From   cb23 <[email protected]>
To   [email protected]
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(dd.mm.yy). 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.
> 
> http://www.rcseng.ac.uk
> 
> Registered Charity Number: 212808
> *
> *   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/
begin:vcard 
n:Bojke;Chris
tel;cell:0795 818 3140
tel;fax:01904 432 700
tel;work:01904 432 694
x-mozilla-html:FALSE
url:http://www0.york.ac.uk/inst/che/bojke.htm
org:NPCRDC;Centre for Health Economics
version:2.1
email;internet:[email protected]
title:Research Fellow
adr;quoted-printable:;;Alcuin D=0D=0AUniversity of York=0D=0AHeslington;York;North Yorkshire;YO10 5DD;UK
fn:Chris Bojke
end:vcard



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