When I use mean() function from egen it seems that egen does not store the result as double even when I indicated that. The result is problematic since I am trying to identify values that depart from the mean (of course, I can use round() and it actually works perfect though I'm just curious about why is this going on with egen).

I have a x variable with a "binary-problematic" number. I define it with

I calculate xMean as the mean of observations per individual

Then

I expect to obtain 0 however, I obtain a non-zero value. It works as expected if I use

It does work as expected when I manually input values (114.77) instead of using egen mean().

I read Precision (yet again), Part I and The Penultimate Guide to Precision. What am I missing?

I have a x variable with a "binary-problematic" number. I define it with

Code:

gen double x = 0

Code:

by ID: egen double xMean = mean(x)

Code:

gen double xDiff = x-xMean

Code:

gen double xDiff = x-round(xMean, .01)

id | x | xMean | xDiff |

1 | 114.77 | 114.77 | -1.421e-14 |

1 | 114.77 | 114.77 | -1.421e-14 |

I read Precision (yet again), Part I and The Penultimate Guide to Precision. What am I missing?

## Comment