# Re: st: a question about number precision

 From Michael McCulloch To statalist@hsphsun2.harvard.edu Subject Re: st: a question about number precision Date Tue, 04 Apr 2006 09:44:52 -0700

```Thank you very much!

At 05:52 AM 4/4/2006, you wrote:
```
```In response to my posting about precision issues, Michael McCulloch

> 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 <jzh@ucdavis.edu> 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
wgould@stata.com
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```
```
Best wishes,
Michael

____________________________________

Michael McCulloch
Pine Street Clinic
124 Pine Street, San Anselmo, CA 94960-2674
tel     415.407.1357
fax     415.485.1065
email:  mm@pinest.org
web:    www.pinest.org
www.pinestreetfoundation.org

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```