Statalist The Stata Listserver

[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: a question about number precision

From (William Gould, Stata)
Subject   Re: st: a question about number precision
Date   Tue, 04 Apr 2006 07:52:26 -0500

In response to my posting about precision issues, Michael McCulloch
<> asked, To:

> May I ask, for those of us with lesser experience, what are the command
> methods to stick to in generating variables, so that the integer result we
> want isn't missed by Stata because of the binary storage?

The last sentence of my previous post pretty much said it:

      The rule is, "Make extraction calculations using integers."

Jian Zhang <> wanted to extract the 127 part from 21557127.  My
solution was,

         . gen leftpart = int(ID/1000)
         . gen areaxxx = ID - leftpart*1000

although others have suggested 

         . gen area = mod(ID, 1000)

and that is a great solution.  But going back to my solution, the point is
that even though I divided by 1000, I immediately truncated the result to an
integer.  If, every step of the way, values are integers, you cannot go wrong.

-- Bill
*   For searches and help try:

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