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: formatting dates using "todate"
From
Nick Cox <[email protected]>
To
"[email protected]" <[email protected]>
Subject
Re: st: formatting dates using "todate"
Date
Wed, 26 Mar 2014 18:35:28 +0000
-todate- is one of mine (SSC). From the time it was first issued
(2001, it seems) until version Stata 10 was released in 2007 it
provided a stopgap or longstop (*) role in doing something official
Stata had left open, conversion of run-together dates presented as
numbers or strings.
(*) arcane cricket allusion
Unless you are using version 9 or earlier, you should not need to be
using -todate- at all.
Regardless of that, my best guess as program author is that the reason
for the error message
length does not match pattern
is that that is your problem. Which date are you trying to convert? If
they are numeric dates that appear as 01nov2013 then you are just
seeing the display format; the dates themselves will be numbers like
19663 and not match the pattern given. If they are string dates that
appear as "01nov2013" they will not match the pattern given either.
If they are numeric or string dates such as "20131101" or 20131101,
then that should work, so the next thing is to check for exceptions as
in
count if length(old_date) != 8
list old_date if length(old_date) != 8
in the case of a string date variable and
count if length(string(old_date, "%12.0f")) != 8
if the case of a numeric variable.
But, as said, unless you have Stata 9 or earlier, use the conversion
functions provided by official Stata.
Nick
On 26 March 2014 17:03, Alexey Lyubimov <[email protected]> wrote:
> I have dates in one file formatted as 01nov2013, and in the second file they are formatted as 20131101. I need to merge the files, so I am trying to convert the dates into the same format. There is a posting in the archives as of Thu, 25 Oct 2007 09:36:11 -0500 which suggests the following code to convert YYYYMMDD to stata date format:
> todate old_date, gen(new_date) pattern(yyyymmdd) format(%d)
> I installed "todate" and tried to run this code, but I get the following error message: "length does not match pattern".
> Does anyone have any suggestions on how to fix that?
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/