Statalist The Stata Listserver


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

st: Stored decimals


From   "Siyam, Amani" <[email protected]>
To   <[email protected]>
Subject   st: Stored decimals
Date   Wed, 1 Mar 2006 12:05:23 +0100

Dear Stata-listers,

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

I would appreciate your help with this very much. 

Cheers,


Amani


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



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