Bookmark and Share

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

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

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

From   "Nick Cox" <>
To   <>
Subject   st: RE: FW: producing value labels when value has decimal point
Date   Wed, 11 Aug 2010 21:31:27 +0100

You have a bundle of problems simultaneously: 

1. As the help for -label- clearly states, value labels may be attached
to integers. What is more, they may only be attached to integers. That
is absolute. 

2. Most decimal values -- 1.1 is a leading example -- cannot be held
exactly in Stata because they do not have exact binary equivalents. This
is well documented in various FAQs and articles. -search precision-
points to some references. This precision problem underlies your
difficulties with testing for equality with 1.2 and so forth. 

3. You can't -recast- from numeric to string or vice versa. The help
should be a bit clearer on this. You must use -string()- or -tostring-
for that purpose.

One possible variable type for your codes is string. But it would also
be possible to use integer values 1, 2, etc. and value labels 1 <=> "1.1
Diarrhea", and so forth. 

label define codes 
1 "1.1 Nausea and vomiting" 
2 "1.2 Diarrhea" 
3 "2.1 Hepatitis"
4 "2.2 "Transaninase increase"
<etc> ; 

And then look at -mencode- from SSC. 


Miller, Ann C.

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". I then tried to create
a cloned variable and "recast" it as a string, and got the error message
"string invalid". Then I tried replacing the decimal points by using
"replace clonese_code1=12 if clonese_code1==1.2 " and got "0 real
changes made" despite there being 67 of them with a code of 1.2.  Do you
have any suggestions about what I'm doing wrong here? There are 10
variables with the same value codes corresponding to 10 possible
episodes of a side effect. My eventual objective is to try to identify
if a person has at any time had (for example) hepatitis as a side effect
in any of the 10 visits.  Any advice about what I'm doing wrong here
would be most appreciated. 

My program was as follows:

# delimit ;

lab def se_code1 
1.1 "Nausea and vomiting" 
2.2 "Transaninase increase"
3.1 "Renal insufficiency"
4.1 "Hypothyroidism"
5.1 "Hypokalemia"
6.1 "Arthralgia"
6.2 "Myalgia"
7.1 "Anaphylaxis"
7.2 "Pruritis"
7.3 "Rash"
8.1 "Tinnitus"
8.2 "Ototoxicity"
9.1 "Depression"
9.2 "Psychosis"
10.1 "Peripheral neuropathy"
10.2 "Seizure"
11 "Hypotonia"

lab val se_code1 se_code1;
lab val se_code2 se_code1;
lab val se_code3 se_code1;
lab val se_code4 se_code1;
lab val se_code5 se_code1;
lab val se_code6 se_code1;
lab val se_code7 se_code1;
lab val se_code8 se_code1;
lab val se_code9 se_code1;
lab val se_code10 se_code1;

# delimit cr

*   For searches and help try:

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