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

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

From   Ekaterina Hertog <>
Subject   st: How to turn my date variable into a variable Stata.10 can recognise?
Date   Thu, 19 Mar 2009 20:13:14 +0000

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:

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