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

RE: st: -replace- does not create an exact copy

From   "Nick Cox" <>
To   <>
Subject   RE: st: -replace- does not create an exact copy
Date   Mon, 26 Oct 2009 17:24:04 -0000

The second "affect" should be "effect". 

The list will range from those to who didn't notice to those who did  notice but will be pleasantly amused by the fact that I got this wrong. 


Nick Cox

In addition, it should be clearly understood that -format- affects only the way numbers are displayed. It has absolutely no affect on their underlying values or how they are stored. 


Maarten buis

That is a precision issue, a computer can't store that number 
exactly (think of storing 1/3 in decimal: 0.3333 etc.). There
are a couple of things you can do: replace to 583 rather than 
58.3, as computers can store integers exactly, or use 
- ... if var1==float(58.3)-.

--- On Mon, 26/10/09, Michael McCulloch wrote:
> For some reason, the following command:
> bysort var1 : replace var1 = cond(_n == 1, x, y)
> replaces the variable var1 with a number not *exactly*
> identical, such as:
>     58.29999924 instead of 58.3.
> Although I could say:
>     . format %9.2f,
> that won't find a match for -if-, as in:
>     . ...  if var1==58.3

*   For searches and help try:

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