Copy and paste put the last three lines into one.
gen day ...
gen mydate ...
format ...
Eric de Souza
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of DE SOUZA Eric
Sent: 19 March 2009 21:26
To: [email protected]
Subject: <POSSIBLE SPAM>RE: <POSSIBLE SPAM>st: How to turn my date variable into a variable Stata.10 can recognise?
Leave it as a numeric variable.
Then do the following (where date is the name of the date of birth variable):
gen year = int(date/10000)
gen month = int((date-year*10000)/100)
gen day = int((date-year*10000-month*100)) gen mydate = mdy(month,day,year) format mydate %d
Eric de Souza
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Ekaterina Hertog
Sent: 19 March 2009 21:13
To: [email protected]
Subject: <POSSIBLE SPAM>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/
*
* 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/