Statalist The Stata Listserver


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

Re: st: < and > operand in recode


From   "Svend Juul" <[email protected]>
To   <[email protected]>
Subject   Re: st: < and > operand in recode
Date   Mon, 21 Aug 2006 13:17:46 +0200

BW wanted to recode a variable:

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

- and that gave rise to quite a few comments and useful suggestions.

However, I was surprised by Nick's dislike of -recode- which he wrote
was not meant to be used for continuous variables. To me, it works
perfectly, and I find it more transparent than any of the other
suggestions. For BW's example it is:

   recode x (min/1=1)(1/2=2)(2/5=3)(5/10=4)(10/max=5) , generate(newx)

If intervals overlap, the first interval specification wins, so if you
want 1, 2, 5 and 10 in the upper groups, just reverse the sequence:

   recode x (10/max=5)(5/10=4)(2/5=3)(1/2=2)(min/1=1) , generate(newx)

-recode- also lets you define value labels at once:

   recode x (min/1=1 "(0-1]")(1/2=2 "(1-2]") ... , generate(newx)

So, my conclusion is that -recode- is VERY good to create grouped
variables from continuous variables.

As stated by others, the -generate()- option is extremely important. To
prevent accidents it might have been wise to require a -replace- option,
if the user wants to overwrite an existing variable. But that is
probably too late now.

Svend

__________________________________________

Svend Juul
Institut for Folkesundhed, Afdeling for Epidemiologi
(Institute of Public Health, Department of Epidemiology)
Vennelyst Boulevard 6
DK-8000  Aarhus C, Denmark
Phone: +45 8942 6090
Home:  +45 8693 7796
Email: [email protected]
__________________________________________

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