Statalist The Stata Listserver


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

RE: st: recoding variables


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: recoding variables
Date   Fri, 10 Feb 2006 14:46:03 -0000

Svend is right. 

What's more, if you have ordered codes, the -recode- is 
unnecessary. 

For example a mapping to codes 1 2 3 is given by 2 + sign(tobacco - poker). 

Nick 
[email protected] 

Svend Juul
 
> Krista wrote:
> 
> I have two variables: age at first poker use (poker) and age of first
> tobacco use (tobacco).
> 
> I want to create a variable (risk_behaviour) with 3 levels that will
> have the value labels of 1 = tobacco<poker, 2 = tobacco>poker, and 3
> tobacco=poker.
> ----------------------------------------------
> 
> Austin Nichols and Nick Cox gave good solutions. I think, 
> however, that
> the following is simpler. If one of the variables is missing, 
> risk will
> be missing too.
> 
>    . generate risk = sign(tobacco-poker)
>    . recode risk (-1=1)(0=3)(1=2)
> 
> For help on the sign() fuction, type
>    . help sign()

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