Converting string variables into date variables in STATA

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Converting string variables into date variables in STATA

MargaretHeslin
This post has NOT been accepted by the mailing list yet.
Hi all,

I would really appreciate some help.

I have dates in a string format as follows (dmy):

19.09.02
01.12.09 etc

I have tried using the following command to convert to date format but the new variable comes up blank. Any suggestions as to what I am doing wrong?

DVadmission1 is new new date variable
Admission_date_1_12M is the origianl string date variable

gen DVadmission1 = date(Admission_date_1_12M, "DMY")
format DVadmission1 %td

Many thanks,
Margaret Heslin.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Converting string variables into date variables in STATA

LucyRiley89
This post has NOT been accepted by the mailing list yet.
It might be because your data has 2-digit years

Try

gen DVadmission1 = date(Admission_date_1_12M, "DMY", 2013)

Adding ,2013 to the end of the code helps stata to read the 2-digit year as the largest year that does not exceed 2013.

 
Loading...