Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: problem with stata misreading decimals


From   n j cox <[email protected]>
To   [email protected]
Subject   Re: st: problem with stata misreading decimals
Date   Wed, 23 Apr 2003 16:26:56 +0100

Emma Samman wrote:

I am writing because of a problem with the way STATA is interpreting a
'do' file written to create a variable that assigns a weight to each
respondent in my sample (hh survey data), based on their age and
position within a household.

The program is copied below - but the basic problem is that rather than
assigning a value of e.g. .3 to an observation, STATA assigns .30000001.
It does the same for all other decimal weights that are not preceded by
a number before the decimal point (i.e. 1.2 is given as 1.2; but .8 is
.80000001).
I would be very grateful for any advice or possible solutions. (I do not
want to simply round the weights, because I will need to use them in
subsequent calculations).

Here is a copy of the do-file:

*Create famweight variable (this is based on respondent's position in
their household and age). PCO1 describes the relationship to household
head.
gen famweight = 1.2 if pco1==1
replace famweight = .8 if pco1==2
replace famweight = .8 if (3<=pco1 & pco1<=11) & edad >=11
replace famweight = .4 if (3<=pco1 & pco1<=11) & (5<=edad & edad<=10)
replace famweight = .3 if (3<=pco1 & pco1<=11) & (0<=edad & edad<=4)
tab famweight
This "problem" is at root a consequence of the
fact that you think in decimal but that your
computer thinks in binary, and so must the programs
it uses. For diagnosis, see
[U] 16.10 Precision and problems therein.

Nick
[email protected]

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