Statalist


[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 <[email protected]>
To   [email protected]
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
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/



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