2
votes

Stata does not replace a value, as I am commanding. What is happening? I have this variable Shutouts, which is a float variable (%9.0g).

One observation has the value = 5.08; that is an error, it should be 5. I type: replace Shutout= 5 if Shutout==5.08. And, surprisingly to me, Stata responds:

replace Shutouts=5 if Shutouts==5.08
(0 real changes made)

I have a similar problem for a variable with the same characteristics, with the name Save_perc; one value is 9.2 but should be .92. And, also this time, I receive this response from Stata:

replace Save_perc=.92 if Save_perc==9.2
(0 real changes made)

Why "0 real changes"?

It seems like a very banal problem, but I have been working on it for like 30' and I cannot really figure it out.

1
Welcome to StackOverflow. Please take a look at these tips on how to produce a minimum, complete and verifyible example. Perhaps the following tips on asking a good question may also be worth a read. For example, you do not include the error message in your question. Please do so. - lmo
thanks, I had forgotten to type some relevant info. - Fuca26

1 Answers

3
votes

it has to do with how floating numbers are stored into memory. You should not use == when comparing two different number formats because some internal storage approximation can make the comparison fail.

In your case, you should just use

Shutouts=5 if Shutouts > 5.07 

or

  Shutouts=5 if Shutouts == float(5.07)