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

st: RE: Replace a substring


From   "Frank de Libero" <[email protected]>
To   <[email protected]>
Subject   st: RE: Replace a substring
Date   Tue, 13 Sep 2005 17:17:31 -0700

The function, subinstr(), (or regular expression functions) will do it.
E.g., gen newvar = subinstr(oldvar,"dis","reg",.).

..Frank

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of TEWODAJ
MOGUES
Sent: Tuesday, September 13, 2005 4:47 PM
To: Stata _
Subject: st: Replace a substring

Hi,
I am hoping that this is quick and simple to answer. I want to replace 
all occurrences of a substring in some string variable with another 
substring. E.g. I want to replace "dis" with "reg" so that the old 
variable has the values:

oldvar
dis14
batidis
leg_diszone
cont

and the new variable is

newvar
reg14
batireg
leg_regzone
cont

Using Nick's egenmore, this can be done for whole words using -msub-, 
but how can this be done when the string to be replaced is not a whole 
word?

Thanks,
tewodaj 

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