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: type mismatch error when trying to convert a date in stata format


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: type mismatch error when trying to convert a date in stata format
Date   Wed, 19 Feb 2014 13:53:12 +0000

The -date()- function expects a string argument.

The -encode- command produces a numeric variable.

No meeting of minds or bodies will work in that situation.

In any case, what you are trying to do is doomed to disaster, and
there I understate. -encode- will do things like this: dates like
"11jan2013",  "12jan2013" will get -encode-d to numbers like 1, 2,
losing all the date information in the original. They will also get
-encode-d alphanumerically, so usually the numbers won't even be in
the right date order.

Skip the -encode- completely.

gen vardate =date(oldvar, "DMY")
format vardate %td

should work. If not, show us real examples of what the data look like.

P.S. This would never have worked as you hoped. Nothing has changed
here for several versions.

Nick
[email protected]


On 19 February 2014 13:42, Raffaele Palladino
<[email protected]> wrote:
> Dear statalist users, I am dealing with the follow:
> I need to convert dates from an excel file to dates in stata format. I
> am using a do file I wrote time ago when I worked with the same
> database but this time it keeps saying type mismatch.
> Basically what I do is to copy the data from the excel sheet and I
> past them in the stata editor. All the dates are recognized as string,
> then I use these commands;
>
> encode oldvar, generate(newvar)
>
> gen vardate =date(newvar, "DMY")
>
> format vardate %td
>
>
> I do not know why it keeps saying typing mismatch when it comes to run
> the date function since it used to work perfectly.
>
> Anyway the data format in excel is in DD/MM/YYYY, I even tried to
> convert it in day month year format but without success
*
*   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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index