How about:
gen date=date(word(mydate,1),"mdy",2030) (for Stata 8)
or, for Stata7 :
gen date=date(substr(mydate,1,index(mydate," ")),"mdy",2030)
The 3rd argument for date provides a cut-off for the century (see help date)
Michael Blasnik
[email protected]
----- Original Message -----
From: "Huiber Gabi (nat1gxh)" <[email protected]>
To: <[email protected]>
Sent: Wednesday, April 16, 2003 4:02 PM
Subject: st: RE: date functions
> I get my date variables in the format "mm/dd/yy 00:00:00" because they
> include a default exact time in hours:minutes:seconds. I turn them into
> Stata elapsed date format as follows:
>
> rename mydate t
> gen q=index(t," ")
> gen str12 dateq=trim(substr(t,1,q))
>
> ** the line above will keep only the mm/dd/yy part of the original mydate
>
> gen mydate=date(dateq,"md20y")
>
> This assumes that there are no dates earlier than 2000. You can always
> adjust for that. One way would be:
>
> gen x=year(mydate)
> replace mydate=date(dateq,"md19y") if x>2003
>
> drop q t dateq x
>
> If there is an easier way, I'm curious.
>
> Gabi
>
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/