[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Re: How to turn my date variable into a variable Stata.10 can recognise?

From   "jmpsouza" <>
To   <>
Subject   st: Re: How to turn my date variable into a variable Stata.10 can recognise?
Date   Thu, 19 Mar 2009 18:01:25 -0300

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
----- Original Message ----- From: "Ekaterina Hertog" <>
To: <>
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

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 Hertog (née Korobtseva)
Career Development Fellow
Department of Sociology and Nissan Institute of Japanese Studies
University of Oxford

27 Winchester Road
United Kingdom

*   For searches and help try:

*   For searches and help try:

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