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: test the format isdate


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: test the format isdate
Date   Wed, 18 Dec 2013 10:33:31 +0000

Your root problem is now evident as of comparing two versions of the
same data entered twice. I have not used -cfout- and can't advise on
how to use it or to modify it for your own purposes. Why not contact
the author directly if he does not respond on the list?

Given the same problem I know I might start with -duplicates- as a
tool written with that purpose in mind. Indeed -cfout- does make use
of -duplicates- internally.

Alternatively, given two versions of the same data and an identifier
then something like

bysort id : gen double diff  = mydate[1] - mydate[2]

list id mydate diff if diff & version == 1

will show you any differences in dates directly.
Nick
[email protected]


On 18 December 2013 05:39, rasool.bux <[email protected]> wrote:
> Dear Nick,
>
> Actually I am using -cfout- program of Ryan Knight (http://ideas.repec.org/c/boc/bocode/s457300.html ) which is generating output in .csv file. When I open csv file excel, the differences of date variables are not in readable format. That's why I am converting all date variables to string variable for comparing double entry files.
>
> Is there any other way to handle this kind of issue? Any suggestion to modify -cfout- for date variable comparison and save the results to dta file instead of csv.
>
> I have seen -cf3- command also but there is no option to save discrepancies results.
>
> Sorry for inconvenience.
> Thank you again.
> Rasool Bux
>
> -----Original Message-----
> From: [email protected] [mailto:[email protected]] On Behalf Of Nick Cox
> Sent: Tuesday, December 17, 2013 8:25 PM
> To: [email protected]
> Subject: Re: st: test the format isdate
>
> As Stata's documentation clearly implies, dates are not a variable, data or storage type. So, no check for a date type is possible. That's why there is no -confirm date-.
>
> Being a date is in the mind of the user and in a strong sense nothing to do with Stata as such. I could go with
>
> sysuse auto
> format mpg %td
>
> and Stata would not complain. That would be perverse, but not illegal.
> Nevertheless the usual assumption is that a date format is diagnostic of something you (should) understand as a date. That could easily break down with yearly dates as often users would be entirely happy with default formats.
>
> I have encountered users with personal or even institutional conventions that dates are distinguishable (indeed, _must_ be
> distinguished) using some convention for variable names (e.g. that dates and only dates have names beginning with "d"), but while such a convention makes date management easier for such users it manifestly has no general force.
>
> -ds- identifies variables with date formats using one command line. I am not clear why you appear to regard that as a poor solution.
>
> I don't know of an -isdate- or equivalent command, but if such existed you would be able to find it. One such is easily programmable, but my own stance here is that writing such a program would be a waste of time given the existence of more general tools.
>
> In terms of your code, that can be shrunk from
>
> qui ds, has(format %td*) // or qui findname, format(%td*) local test "`r(varlist)'"
> foreach v of varlist `test' {
>         tostring `v', replace usedisplayformat force }
>
> to
>
> qui ds, has(format %td*) // or qui findname, format(%td*) tostring `r(varlist)', replace usedisplayformat force
>
> as -tostring- takes a varlist as argument (removing the need for a
> loop) and there is no need to put r(varlist) into a local macro when it already has such a persona, as your code already illustrates.
>
> Your code, however, is dangerous in replacing variables with -force- so that if there is a problem with the data you may have lost information. String date variables are not much use in Stata but your motive in doing this may be (e.g.) export to other software.
>
> Nick
> [email protected]
>
>
> On 17 December 2013 14:03, rasool.bux <[email protected]> wrote:
>> Dear Nick,
>>
>> Thanks for reply, and I have used it as follows:
>> *****************
>>   qui ds, has(format %td*) // or qui findname, format(%td*)
>>   local test "`r(varlist)'"
>>   foreach v of varlist `test' {
>>         tostring `v', replace usedisplayformat force
>>   }
>> ******************
>> May be there is another good way. I have checked -confirm- command also but (confirm date variable `v') is not working. I have seen that macro at this link: http://www.stata.com/statalist/archive/2008-04/msg00892.html.
>>
>> Kindly let me know if there is any command like it for checking type & format of a variable i.e. -isnumber/ isdate/ isstring.
>>
>> Thanks & best regards
>> Rasool Bux
>>
>> -----Original Message-----
>> From: [email protected]
>> [mailto:[email protected]] On Behalf Of Nick Cox
>> Sent: Monday, December 16, 2013 7:41 PM
>> To: [email protected]
>> Subject: Re: st: test the format isdate
>>
>> way to think more generally, as dates are typically defined only by their display formats.
>>
>> ds, has(format %d*)
>>
>> or
>>
>> ds, has(format %td*)
>>
>> would be simple examples.
>>
>> -findname- (SJ) is of the same flavour, but more versatile.
>>
>> Note that -tostring- is a Stata command, not a Stata function.
>> -isnumeric- (origin not explained by you) is presumably a Stata command, not a Stata macro. Using terminology from outside Stata is likely to confuse or bemuse.
>>
>> All that said, -tostring- won't usefully save numeric date variables as string dates, unless you specify a date format.
>> Nick
>> [email protected]
>>
>>
>> On 16 December 2013 14:06, rasool.bux <[email protected]> wrote:
>>> Dear Statalist,
>>>
>>> I want to test the format of a variable in a program for conversion to string in a loop using the tostring function. If the format of a variable is %td then I want to save it in a string variable by using the tostring function.
>>>
>>> I have searched web I found the macro -isnumeric- . But I want to
>>> test the format also i.e. -isdate-
>>>
>>> Kindly suggest me in this regard.
> *
> *   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/
>
>
> ________________________________
>
> This e-mail may contain information that is privileged or confidential. If you are not the intended recipient, please delete the e-mail and any attachments and notify us immediately.
>
>
> *
> *   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/

*
*   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