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

RE: st: Help with String Variables


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: Help with String Variables
Date   Wed, 3 Sep 2003 14:16:14 +0100

Ernest Berkhout

> >I am trying to recode a string variable and am having a hard time.
> >My command is as follows:
> >gen str8 race= PT_RACE
> >this command worked, I then tried to recode using the 
> following command:
> >recode race=1 if PT_RACE==RAC101 (the race variable is 
> coded as RAC101,
> >RAC102, etc.)
> >when I put this command in it reads:
> >=exp not allowed
> 
> Recode is not for strings, use -replace- instead.  Further, 
> remind that 
> strings are better put in double quotes ("string") before 
> taken to an 
> evaluation. That would make:
> 
> replace race=1 if PT_RACE=="RAC101 "
> 
> See -help replace- for more info, and also the User Guide 
> "[U] 16 Functions 
> and expressions".
> 

Typo: 

replace race = "1" if PT_RACE == "RAC101" 

For the whole problem, there are probably 
easier solutions making use of string functions. 

Nick 
[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