Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

st: convert string variable to date


From   Neophytos Stylianou <[email protected]>
To   "[email protected]" <[email protected]>
Subject   st: convert string variable to date
Date   Mon, 21 Jan 2013 11:18:58 +0000

Hello,

I have a problem with 2 of my variables which I want to convert form string to dates. One of the variable is "admissiondate" seen below:

				ADMISSIONDATE
type:	string (str13)

unique values:	3287	missing	"":	0/59047

examples:	"16th Aug 2007"
	"21st Feb 2007"
	"27th Jan 2011"
	"4th Apr 2007"

warning:	variable has embedded	blanks


My other variable is "dichordeathdate":

					DISCHORDEATHDATE
type:	string (str25)

unique values:	3335	missing	"":	0/59047

examples:	"16th Apr 2011"
	"21st Aug 2011"
	"27th Feb 2004"
	"3rd Sep 2009"

warning:	variable has embedded	blanks

How can I convert them to dates?

I do not think the command """gen admdate2 = date(admissiondate, "DMY")""" works here since I do have the 4digit year but I have the rd,st,th after the day!

Is there an easy way to covert the variable to date variable without having to rewrite the whole dates?

I am working on STATA 12

Thanks,
Neo Stylianou

PhD Candidate
University of Manchester



*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index