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

From |
"Nick Cox" <n.j.cox@durham.ac.uk> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
st: RE: Bugs in generating variables? |

Date |
Thu, 4 Nov 2004 10:05:20 -0000 |

I see no bug here. This is a standard precision issue arising from the fact that computers work in binary. 0.1 looks simple to you but it can only be approximated, not held exactly, in binary. This is well documented: Look at [U] 16.10 and (for example) http://www.stata.com/support/faqs/data/mod.html and then, I believe, this mystery will become clear. Also, a practical answer to your need lies in the -float()- function. I can't comment on your colleague's bug, but I'd guess the same histoire. Nick n.j.cox@durham.ac.uk Fabrice Etile > > Here is a strange output, which shows that Stata 8 has some > problems for dealing with inequalities: > [added comment : continuous is a continuous (formatted > double) variable in > the range 0-1.1] > . ta continuous > > continuous | Freq. Percent Cum. > ------------+----------------------------------- > 0 | 7,156 92.55 92.55 > .1 | 241 3.12 95.67 > .2 | 150 1.94 97.61 > .3 | 99 1.28 98.89 > .4 | 48 0.62 99.51 > .5 | 23 0.30 99.81 > .6 | 6 0.08 99.88 > .7 | 6 0.08 99.96 > .9 | 2 0.03 99.99 > 1.1 | 1 0.01 100.00 > ------------+----------------------------------- > Total | 7,732 100.00 > > . g discrete=(continuous>0.1) > [added comment : I generate a discrete variable which takes > value 1 if > continuous is strictly greater than 0.1] > . ta continuous discrete > > | discrete > continuous | 0 1 | Total > -----------+----------------------+---------- > 0 | 7,156 0 | 7,156 > .1 | 0 241 | 241 > .2 | 0 150 | 150 > .3 | 0 99 | 99 > .4 | 0 48 | 48 > .5 | 0 23 | 23 > .6 | 0 6 | 6 > .7 | 0 6 | 6 > .9 | 0 2 | 2 > 1.1 | 0 1 | 1 > -----------+----------------------+---------- > Total | 7,156 576 | 7,732 > > > As you can see, observations with continuous==0.1 should have > discrete==0 > and this is not what happens!! > > Has someone an answer to that? > > PS: note that one of my colleague showed me a similar bug, so > that it is not a hardware-related problem. * * 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/

- Prev by Date:
**st: RE: Gary King's Clarify for Stata - looping** - Next by Date:
**st: RE: RE: Bugs in generating variables?** - Previous by thread:
**st: RE: Bugs in generating variables?** - Next by thread:
**st: RE: RE: Bugs in generating variables?** - Index(es):

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