dear Ekaterina:
try -todate-, available from -ssc install todate-.
todate olddate,gen(newdate) pattern(yyyymmdd)
In your case olddate= 19560413; newdate= 13apr1956
Jose Maria Pacheco de Souza, Professor Titular (aposentado)
Departamento de Epidemiologia/Faculdade de Saude Publica, USP
Av. Dr. Arnaldo, 715
01246-904 - S. Paulo/SP - Brasil
fones (11)3061-7747; (11)3768-8612
fax (11)3714-2403
www.fsp.usp.br/~jmpsouza
----- Original Message -----
From: "Ekaterina Hertog" <[email protected]>
To: <[email protected]>
Sent: Thursday, March 19, 2009 5:13 PM
Subject: st: How to turn my date variable into a variable Stata.10 can
recognise?
Dear All,
I have got a dataset which contain dates of birth for individuals and
these dates of birth look as follows: 19560413 and I am trying to turn
them into date variables Stata can recognise.
It is a numeric variable and I have turned it into string.
The problem is that the following approach:
gen birth_date = date(strbirth_date, "DMY")
format birth_date %td
does not work I just get missing values. Presumably that is because my
date variable is not in the order: day - month - year, but rather year -
month - day.
I then thought I would redo the variable into a correct order and first
tried to create 3 separate string variables out of each date: one for
year, one for month and one for day.
I tried to do it as follows:
generate strbirth_date= string(date_of_birth, "%08.0f")
gen yob = substr(strbirth_date,1,4)
gen mob = substr(strbirth_date,5,6)
gen dob = substr(strbirth_date,7,8)
As a result 19560413 turned into: yob=1956
mob=0413
dob=13
I do not understand why did the month of birth (mob) did not transform
correctly and what can I do next.
I would be very grateful for any advice as to how I can turn my date
variable into a variable Stata10 can recognise,
Sincerely yours,
Ekaterina
--
Ekaterina Hertog (née Korobtseva)
Career Development Fellow
Department of Sociology and Nissan Institute of Japanese Studies
University of Oxford
27 Winchester Road
Oxford
OX2 6NA
United Kingdom
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/