[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: dates
Nick Cox <firstname.lastname@example.org>
Re: st: dates
Fri, 7 Oct 2011 19:44:07 +0100
Intelligent support for run-together dates was added in Stata 10. (For
Stata 8 and 9. -todate- (SSC) is a work-around.)
If such dates are numeric, then a conversion can be used like
. di date(string(20080105, "%12.0f"), "YMD")
Your splitting, back transforming and recombining are then all
unnecessary. The format argument is needed because otherwise the
-string()- conversion will change the large integer to a power of 10.
. di string(20080105)
On Fri, Oct 7, 2011 at 7:07 PM, Pedro Nakashima
> For the days that are in the format like 20080105, I usually transform
> them to string, break it with substr() (day, month, year), transform
> back to numeric, and then build the date with the function td=mdy().
> I don't know a faster way to do that..
> 2011/10/6 Michael Eisenberg <email@example.com>:
>> I have a list of visit dates for patients. Unfortunately, the format
>> is not constant.
>> Most are listed with the year, month, day such as 20080105 for Jan 5,
>> 2008 but some are listed only with the year and month 200801 for Jan
>> I attempted to convert them into stata dates with the commands below
>> without success.
>> gen ndate = date(dx_date, "YMD")
>> gen ndate = date(dx_date, "CCYYNNDD")
>> Can stata handle such inconsistent data?
* For searches and help try: