### Wednesday, March 01, 2006

## st: RE: RE: Stored decimals

Dear Nick,

Thanks for your reply. I want to store the variable "tweight" as a variable with only 1 decimal place.

If you consider:

gen tweight=weight/10

without any rounding or formatting, "weight" is an integer ranging from 15 to 807 therefore "tweight" will be a real ranging from 1.5 to 80.7 as a 3-digit number with 1 decimal place.

When I save my data file after the command above, the content of "tweight" is as the example shows:

True tweight Stata-stored tweight 3.0 3.0 3.1 3.0999999 3.2 3.2 3.3 3.3000002 3.4 3.4000001 3.5 3.5 3.6 3.5999999 3.7 3.7 3.8 3.8 3.9 3.9000001

Sorry I might be missing a minor point here but I am looking for a command or function to generate and store "tweight" exactly as a 1 decimal place variable.

Thanks very much.

Amani

-----Original Message----- From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Nick Cox Sent: 01 March 2006 14:04 To: statalist@hsphsun2.harvard.edu Subject: st: RE: Stored decimals

You shouldn't need to -round(,)-. This is a standard precision issue (-search precision, faq-) and the presentation problem should be soluble using -format-.

Thus we need to know in what sense that "doesn't work".

Nick n.j.cox@durham.ac.uk

Siyam, Amani > I am dealing with survey data that avails children weights in kgs (int > %8.0g). The way the weight variable is provided is without decimal > places as a three digit number, the last digit representing the 1st > decimal place, that is the variable has to be divided by 10 before it > can be used for the necessary calculations. > > I used the command: > > gen tweight=weight/10 > > The way the variable "tweight" is stored is critical to the subsequent > user of my programme and rather annoying because I don't understand > where the extra decimal places are coming from. Below is an > example of > the pattern of how the 1 decimal place > > DHS weight True tweight Stata-stored tweight > 30 3.0 3.0 > 31 3.1 3.0999999 > 32 3.2 3.2 > 33 3.3 3.3000002 > 34 3.4 3.4000001 > 35 3.5 3.5 > 36 3.6 3.5999999 > 37 3.7 3.7 > 38 3.8 3.8 > 39 3.9 3.9000001 > > When you summarise the variable tweight, it neatly displays as a > 1-decimal place variable. > > Variable | Obs Mean Std. Dev. Min Max > -------------+-------------------------------------------------------- > tweight | 2686 8.617238 3.959973 1.5 80.7 > > I tried the common formatting commands but none seem to be working: > > gen float tweight=weight > repl tweight=round(tweight, 0.1) > format tweight %9.1f >

* * 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/

* * 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/

Tag: statalist