Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: Difference between codebook and count


From   "Maarten Buis" <M.Buis@fsw.vu.nl>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: Difference between codebook and count
Date   Fri, 13 Jul 2007 11:54:27 +0200

--- 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.
See the example below, and the possible solution using -round- in the -cond- 
statement. 

*------------- begin example -------------------
scalar x = .2
di %23.18f  x
di "x " cond(x==.2,"is ", "is not ") ".2"
di "round(x,.1) " cond(round(x,.1)==.2,"is ", "is not ") ".2"
*--------------- end example --------------------
(For more on how to use examples I sent to the Statalist, see
http://home.fsw.vu.nl/m.buis/stata/exampleFAQ.html )

For more on this issue see (Cox 2006) and (Gould 2006).

Hope this helps,
Maarten

N.J. Cox (2006), "Stata tip 33: Sweet sixteen: Hexadecimal 
formats and precision problems", The Stata Journal, 6(2), 
pp. 282-283.

W. Gould (2006), "Mata Matters: Precision", The Stata Journal, 6(4), 
pp. 550-560.

-----------------------------------------
Maarten L. Buis
Department of Social Research Methodology 
Vrije Universiteit Amsterdam 
Boelelaan 1081 
1081 HV Amsterdam 
The Netherlands

visiting address:
Buitenveldertselaan 3 (Metropolitan), room Z434 

+31 20 5986715

http://home.fsw.vu.nl/m.buis/
-----------------------------------------



*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index