Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: problem with blabla if baz == float(#)


From   Joseph Coveney <[email protected]>
To   [email protected]
Subject   Re: st: problem with blabla if baz == float(#)
Date   Mon, 18 Nov 2002 11:15:12 +0900

Guillaume Frechette asked about how to get Stata to recognize certain rational 
numbers.

-------------------begin posting excerpt-----------------------

 Here's an example
. gen foo = 1/3
. gen bar = 1/3
. gen baz = 1-foo-bar
. tab baz

        baz |      Freq.     Percent        Cum.
------------+----------------------------------
   .3333333 |        850      100.00      100.00
------------+----------------------------------
      Total |        850      100.00

. tab baz if baz == float(1/3)
no observations

Can someone tell me how to get Stata to know to recognize baz as equal to 
1/3?
------------------end posting excerpt--------------------------

The only way that I know of is to explicitly provide tolerances as in the example below.

Joseph Coveney

------------------begin Frechette.do--------------------------

clear
set obs 850
generate double foo=1.0/3.0
generate double foo=1.0/3.0
generate double bar=1.0/3.0
generate double baz=1.0-foo-bar
tabulate baz if baz > float(1/3)-0.994e-8 /*
*/ & baz < float(1/3)+0.994e-8
clear
set obs 850
generate float foo=1.0/3.0
generate float bar=1.0/3.0
generate float baz=1.0-foo-bar
tabulate baz if baz > float(1/3)-0.299e-7 /*
*/ & baz < float(1/3)+0.299e-7
end

----------------------end Frechette.do----------------------------

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index