Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Re: RE: date functions


From   "Michael Blasnik" <michael.blasnik@verizon.net>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: Re: RE: date functions
Date   Wed, 16 Apr 2003 18:57:14 -0400

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
michael.blasnik@verizon.net

----- Original Message -----
From: "Huiber Gabi (nat1gxh)" <nat1gxh@ups.com>
To: <statalist@hsphsun2.harvard.edu>
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/



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