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 at the end of May, and its replacement, statalist.org 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 <klein.daniel.81@googlemail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: MM/DD/YYYY string to stata date
Date   Tue, 5 Jun 2012 08:13:11 +0200

Lars,

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

Best
Daniel
-- 
Thank you both.

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

Mvh
Lars Folkestad
*
*   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/


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