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]

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


From   "Miller, Ann C." <[email protected]>
To   "[email protected]" <[email protected]>
Subject   st: RE: RE: RE: FW: producing value labels when value has decimal point
Date   Wed, 11 Aug 2010 16:51:23 -0400

I'll give the multiplication a try; thank you for the advice!

I tried the -tostring- before -recast-, and got the error that it could "not be converted reversibly: no replace". Is this because of the decimal point precision issue you mention below? 
Thank you again. 
--Ann  

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Nick Cox
Sent: Wednesday, August 11, 2010 4:35 PM
To: [email protected]
Subject: st: RE: RE: FW: producing value labels when value has decimal point

Eric's suggestion of multiplying by 10 probably has fewer potential
pitfalls ahead. 

Nick 
[email protected] 


-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Nick Cox
Sent: 11 August 2010 21:31
To: [email protected]
Subject: st: RE: FW: producing value labels when value has decimal point

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. 

Nick 
[email protected] 

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. 

PS: 
My program was as follows:

# delimit ;

lab def se_code1 
1.1 "Nausea and vomiting" 
1.2"Diarrhea" 
2.1"Hepatitis"
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:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

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

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