Bookmark and Share

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

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

st: convert string variable to date

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


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:

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":

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

Neo Stylianou

PhD Candidate
University of Manchester

*   For searches and help try:

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