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: Stata cannot do math?


From   Yu Xue <[email protected]>
To   [email protected]
Subject   Re: st: Stata cannot do math?
Date   Thu, 19 May 2011 00:08:56 -0500

Thanks Joseph and Conor! float() works! Sorry that I did not notice
that Stata FAQ.

Conor, I think Mathematica deals with floating-point variables in a
different way. I did not expect this issue with Stata.

On Wed, May 18, 2011 at 7:20 PM, Conor Hughes <[email protected]> wrote:
> Hi,
> Stata can certainly do math, just not quite the same math you're used
> to.  This is an issue of floating point arithmetic.  For example,
> replace
> count a == 100.1
> in your code with
> count a == float(100.1)
>
> Click through the FAQ a bit, maybe starting here
> http://www.stata.com/support/faqs/data/float.html, as well as any
> introductory numerical analysis textbook to get a better idea of how
> computer arithmetic works.
>
> - Conor
>
> On Wed, May 18, 2011 at 6:44 PM, Yu Xue <[email protected]> wrote:
>>
>> Hi All,
>>
>> This may be a stupid question. Here are the command and Stata output:
>>
>> .set obs 50
>> .gen a=100.1
>> .count if a==100.1
>> 0
>> .tab a
>> 100.1
>> .sum a
>> variable  obs  mean  s.d.  min    max
>> a            50    100.1  0    100.1  100.1
>> .gen b=a-100
>> .tab b
>> 0.0999985
>>
>> So, Stata shows that a is equal to 100.1, but actually, it is equal to
>> 100.0999985....
>>
>> Can anyone explain to me what this is? Do I have to set precision when
>> I do math in Stata? How to set precision?
>> Thanks!
>>
>> Yu
>> *
>> *   For searches and help try:
>> *   http://www.stata.com/help.cgi?search
>> *   http://www.stata.com/support/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/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/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


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