Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: FW: producing value labels when value has decimal point


From   Maarten buis <[email protected]>
To   [email protected]
Subject   Re: st: FW: producing value labels when value has decimal point
Date   Wed, 11 Aug 2010 20:50:46 +0000 (GMT)

--- On Wed, 11/8/10, Miller, Ann C. wrote:
> I have been given a float variable in which the values are
> things like 1.1 ,1.2, 2.1, 2.2, 2.3.  These values
> correspond to diagnoses in a medical record, for example
> 1.1=diarrhea, 1.2=nausea/vomiting/other GI . and so on. I
> would like to create labels for this variable,but so far
> have been unable. I created a program to do this (see below)
> but the error message I got back was "may not label 1.1".

One solution is to turn these codes into integers by
mutliplying them by 10. This is a better format for storing
such categorical variables like these anyhow, as integers
can be stored exactly on computers while numbers like 1.1
can't.

*--------------- begin example -------------

clear all
input x
1.1
1.2
end

lab def se_code1           ///
11 "Nausea and vomiting"  ///
12"Diarrhea" 

gen x10 = x*10
lab val x10 se_code1

// 1.1 cannot be stored exactly,
// which is the reason for the
// following weird behaviour:
count if x == 1.1

// here is one solution:
count if x == float(1.1)

// but easier is to use the 
// the variable where the codes
// are stored as integers
count if x10 == 11
*---------------- end example -----------------
(For more on examples I sent to the Statalist see: 
http://www.maartenbuis.nl/example_faq )

All this is related to the precision with which a 
number is stored on a computer. A number of great 
resources are:

William Gould (2006) "Mata matters: precision" The 
Stata Journal, 6(4):550-560.
http://www.stata-journal.com/article.html?article=pr0025

Nicholas J. Cox (2006) "Stata tip 33: Sweet sixteen: 
Hexadecimal formats and precision problems" The Stata 
Journal, 6(2): 282-283.
http://www.stata-journal.com/article.html?article=dm0022

Jean Marie Linhart (2008) "Mata matters: Overflow, 
underflow and the IEEE floating-point format" The 
Stata Journal, 8(2): 255-268.
http://www.stata-journal.com/article.html?article=pr0038

http://www.stata.com/support/faqs/data/prec.html

http://www.stata.com/support/faqs/data/float.html

http://www.ats.ucla.edu/stat/stata/faq/longid.htm

http://www.michaelnormanmitchell.com/stow/floats-and-doubles.html

Hope this helps,
Maarten

--------------------------
Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
Germany

http://www.maartenbuis.nl
--------------------------


      

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index