Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Simple recoding

From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   Re: st: Simple recoding
Date   Fri, 16 Aug 2002 12:34:06 +0100

Chris Fergusson

I have a variable in my datasheet, sex which is formatted as str1 %9s.
There are two types either M or F.  I need to convert this so that M=1
F=2. How do I do this, or where is a problem similar to this
described.  I
have tried using "destring sex, replace" etc but have had no luck.
Thanks for all your help in advance on this relatively simple

>>> By default, -encode- uses alphabetical encoding, but that
can be overridden.


gen gender = cond(sex == "M", 1, 2)
label def gender 1 M 2 F
label val gender gender


label def gender 1 M 2 F
encode sex, gen(gender) label(gender)

In press in the Stata Journal 2(3) 2002 is a tutorial
on numbers and strings,
discussing -encode-/-decode-, -real()-/-string()-,

[email protected]

*   For searches and help try:

© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index