[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
Maarten buis <maartenbuis@yahoo.co.uk> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: Problem with replace if - test condition works only for some values of test variable |

Date |
Fri, 24 Oct 2008 09:38:29 +0100 (BST) |

--- Naunihal Singh <naunihal@post.harvard.edu> wrote: > I'm able to make assignments to y only when x equals 0, .25, .5, .75, > and 1 but for no other value. This is the output I get: > > . replace y=1 if x==.5 > (1 real change made) > > . replace y=1 if x==.51 > (0 real changes made) > > Why does this happen and how do I fix it? x is a float, so it should > have enough precision for the test condition. And if the test can > recognize .25 it should be able to recognize .26. You will find an explanation in -help float-. In short, the number .51 in the statement -replace y = 1 if x == .51- is stored as a double, which will be different from the value .51 stored in the variable x, which is stored as a float. You can solve this by typing: replace y=1 if x==float(.51) Hope this helps, Maarten ----------------------------------------- Maarten L. Buis Department of Social Research Methodology Vrije Universiteit Amsterdam Boelelaan 1081 1081 HV Amsterdam The Netherlands visiting address: Buitenveldertselaan 3 (Metropolitan), room N515 +31 20 5986715 http://home.fsw.vu.nl/m.buis/ ----------------------------------------- * * 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/

**References**:**st: Problem with replace if - test condition works only for some values of test variable***From:*"Naunihal Singh" <naunihal@post.harvard.edu>

- Prev by Date:
**st: RE: Problem with replace if - test condition works only for some values of test variable** - Next by Date:
**st: RE: RE: Pausing a command in runtime** - Previous by thread:
**st: RE: Problem with replace if - test condition works only for some values of test variable** - Next by thread:
**st: suggested references about the variables to include in zero-inflated portion of zinb?** - Index(es):

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