Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: < and > operand in recode


From   Dick Campbell <dcamp@uic.edu>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: < and > operand in recode
Date   Sun, 20 Aug 2006 12:10:49 -0500

I was in the midst of posting a response to this query when Nick Cox's very
complete answer arrived. Just two additional points. The full documentation for recode can be found in [D}, data management.
The key idea is that recode rules are evaluated left to right. Thus (1/5=1)(5/10=2) results in a value of 5 being recoded
to 1 even though "5" appears in both rules. Nick is certainly right; recoding continous variables can sometimes
result in unexpected outcomes. At the very least, it is a good idea to always use the -gen- option with recode rather than
overwrite the original variable and to immediately cross tabulate the original variable against the new.


At 07:54 AM 8/20/2006 Sunday, you wrote:

hi all,

Stata 8.2,

i wanted to recode a variable, which consisted of continuous number, something to the effect of:

<=1 coded 1 (<= i.e. meaning less than or equal to)
>1 to <=2 coded 2
>2 to <= 5 coded 3
>5 to <=10 coded 4
>10 coded 5

when i tried to use the equality operands (i.e. < or > in my recode commands, it gives an error message 'unknown el <2 in rule') so after consulting my manual on [R] recode, i managed by recoding:

0.0001/1 = 1
1.0001/2 = 2
.
.
10/1000 = 5
etc

being careful to make sure that the parameters included all the values.

i would appreciate if someone could confirm that equality sign cannot be used in recode. would appreciate it too if anyone can point out an alternative/better way to accomplish the recode.

many thanks,
bw

_________________________________________________________________
Try Live.com - your fast, personalized homepage with all the things you care about in one place.
http://www.live.com/getstarted
*
* 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/
Richard T. Campbell
Professor
Division of Epidemiology and Biostatistics
School of Public Health &
Institute for Health Research and Policy
University of Illinois at Chicago

*
* 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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index