Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

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

Re: st: MM/DD/YYYY string to stata date

From   daniel klein <>
Subject   Re: st: MM/DD/YYYY string to stata date
Date   Tue, 5 Jun 2012 08:13:11 +0200


here is one way to go.

// split the string variable into parts
split <mystrvar> ,g(part) p("/")

// add leading zero
forv j = 1/2 {
	replace part`j' = "0" + part`j' if length(part`j') < 2

// now put it back together
g tmp = part1 + part2 + part3

// transfer to date
g mydate = date(tmp, "MDY")
form mydate %td

// clean up
drop part? tmp

Thank you both.

Nick: i dont want to make it hard for Stata. How do i go from string
mm/dd/yyyy to date?

Lars Folkestad
*   For searches and help try:

© Copyright 1996–2016 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index