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: reversible -destring-, precision, longs v doubles


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: reversible -destring-, precision, longs v doubles
Date   Tue, 6 Aug 2013 22:54:33 +0100

Precision is certainly one issue.

But what's the real problem here? If you need panel identifiers,

egen panelid = group(strvar), label

beats all alternatives.
Nick
[email protected]


On 6 August 2013 22:36, László Sándor <[email protected]> wrote:
> Thanks, Nick, as always.
>
> I am actually still confused, and maybe it is not just me: Could you
> discuss when the reversibility check would fail?
>
> From Bill's penultimate guide to precision, esp. points 4.3, 4.4, I
> gather that the IDs will be unique (not rounded) if my system is set
> to double as the default datatype. Permanently.
> http://blog.stata.com/2012/04/02/the-penultimate-guide-to-precision/
>
> Still, it is a bit scary to risk rounding your identifiers by a
> mistaken float somewhere. On the other hand, string identifiers cannot
> be panel IDs for xtset, so I need to bite the bullet.
>
> Thanks again,
>
> Laszlo
>
> On Tue, Aug 6, 2013 at 12:29 PM, Nick Cox <[email protected]> wrote:
>> I guess I wrote some zeroth version of that.
>>
>> Conversion is reversible if real(string(<original>)) = <original> or
>> string(real(<original>)) = <original> where <original> is whatever you
>> feed in and -string()- can use whatever format is specified.
>>
>> What this amounts to is a stipulation is that you must lose no
>> information, crucial if you change your mind about what should be done
>> to the data.
>>
>> So, a reversible potato peeler or university education would restore
>> the potatoes or the students to their original state.
>> Nick
>> [email protected]
>>
>>
>> On 6 August 2013 17:03, László Sándor <[email protected]> wrote:
>>> I ran into an error with identifiers longer than -maxlong()- before
>>> (blame statistical offices fond of 10 digits or more). So now I wanted
>>> to be careful while destringing, but you cannot specify the type for
>>> the result — however, -destring- breaks if the process is not
>>> "reversible." What does it mean exactly? I cannot find it documented.
>>> (Actually, the default type for -destring- is double, so it is surely
>>> not the case the destring only produces longs unless forced to.)
>>>
>>> Do I need to worry about my identifiers becoming imprecise or rounded
>>> if -destring- did not warn me?
>>>
>>> The documentation of -tostring- does contain the following, but this
>>> is not exactly the same thing.
>>>
>>> Conversion of numeric data to string equivalents can be problematic.
>>> Stata, like most software, holds numeric data to finite precision and
>>> in binary form. See the discussion in [U] 13.11 Precision and problems
>>> therein. If no format() is specified, tostring uses the format %12.0g.
>>> This format is, in particular, sufficient to convert integers held as
>>> bytes, ints, or longs to string equivalent without loss of precision.
>>> However, users will often need to specify a format themselves,
>>> especially when the numeric data have fractional parts and for some
>>> reason a conversion to string is required.
>>>
>>> Thanks!
>>>
>>> *
>>> *   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/
>
> *
> *   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