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]

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


From   daniel klein <[email protected]>
To   [email protected]
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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index