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

st: RE: Simple recoding


From   [email protected]
To   [email protected]
Subject   st: RE: Simple recoding
Date   Fri, 16 Aug 2002 13:44:26 +0200

I think destring would require to have your variable coded as '1' and '2'
already. So either you rename them first:

replace sex="1" if sex=="m"
replace sex="2" if sex=="f"

and than destring, replace

or you could try: 

encode sex, gen(sex2)

This gives you F=1 and M=2, because it's done alphabetically but the rest is
easy to change. 


Soeren Mattke
OECD Health Policy Unit
2, rue Andre Pascal
75775 Paris Cedex 16

phone: + 33 1 4524 9236
fax:      + 33 1 4524 9098 

-----Original Message-----
From: [email protected] [mailto:[email protected]]
Sent: Friday, August 16, 2002 1:23 PM
To: [email protected]
Subject: st: Simple recoding


Hello statalisters,

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 and
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 question.

Christopher D Fergusson
*
*   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/
*
*   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