The short answer I believe to be No.
Whenever you are asking for a -float- result, Stata will (attempt to)
give you one. That usually -- not just occasionally -- gives you less
precision than is possible. What differs is that almost no-one cares
about the last few decimal places if there is a fractional part, whereas
we may well care about preserving integers exactly.
If you want a homunculus inside the machine smart enough to work out
that you are asking for something you don't really want, you may have to
program it yourself, as only you know what you don't really want.
More positively, these issues most commonly arise with long numeric
identifiers, in which case there are two simple pieces of advice.
1. Keep all long numeric identifiers in string variables.
2. If you have a good reason not to do that, make sure that results are
always specified as -long- or -double-.
By the way, you can specify the default new variable type as e.g.
-double-. (Specifying it as -long- would create more problems than it
solved.)
Nick
[email protected]
sdm1/Steve
Is there any way I can get Stata to warn me that it is doing this?
Nick Cox
You have a precision problem. By default -egen- will generate -float-
variables with the functions you are using. To keep every digit in the
integers you are playing with you need to spell out that you want a
-long- or -double-. There aren't enough bits in the variable type you
are
using.
I can't follow your code which seems to go back and forth between string
and
numeric results, nor do I know what MEPS means. I guess there's a much
simpler way to do what you want without using -egen- at all, but the
issue
that is biting you is illustrated thus:
. set obs 1
obs was 0, now 1
. gen long myin = 40002015
. egen myout = max(myin)
. egen long myout2 = max(myin)
. format myout* %12.0f
. l
+--------------------------------+
| myin myout myout2 |
|--------------------------------|
1. | 40002015 40002016 40002015 |
+--------------------------------+
*
* 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/