Dear David,
thanks a lot for Your Kind and helpful hint.
Kind Regards,
Carlo
-----Messaggio originale-----
Da: [email protected]
[mailto:[email protected]] Per conto di David Kantor
Inviato: venerd� 13 luglio 2007 12.59
A: [email protected]
Oggetto: Re: st: RE: Difference between codebook and count
At 05:54 AM 7/13/2007, Maarten Buis wrote:
>--- Carlo Lazzaro wrote:
> > I have experienced the following problem (please, see details
> below) with .2
> > value, which is reported with codebook but seemingly ignored with count.
> > . codebook dosea1
> >
>
----------------------------------------------------------------------------
> > dosea1
> > (unlabeled)
> >
>
----------------------------------------------------------------------------
> > type: numeric (float)
> >
> > range: [.2,1] units: .1
><snip>
> >
> >. count if dosea1==.2
> > 0
>
>This is a due to the fact that computers and Stata count in base-2
>and we count
>in base-10 numbers. The number .2 (base-10) cannot be held exactly in
base-2.
[...]
You then gave an example using -round-.
But the important issue is that calculations are done in double,
while the storage type of dosea1 is float. That is, in -count if
dosea1==.2-, the .2 is evaluated as a double, and is compared to
dosea1, which is a float. If you had generated and stored dosea1 as
double, then the apparent paradox would not occur. But storing such
numbers as double is usually not necessary and can waste space. Given
that is is a float, the appropriated test is...
count if dosea1 == float(.2)
See -help float-.
hth
--David
*
* 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/
*
* 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/