Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

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

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

clear all
input x

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

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: )

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.

Nicholas J. Cox (2006) "Stata tip 33: Sweet sixteen: 
Hexadecimal formats and precision problems" The Stata 
Journal, 6(2): 282-283.

Jean Marie Linhart (2008) "Mata matters: Overflow, 
underflow and the IEEE floating-point format" The 
Stata Journal, 8(2): 255-268.

Hope this helps,

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


*   For searches and help try:

© Copyright 1996–2015 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index