<>
Using the -msub()- function in Nick Cox's -egenmore- package (SSC),
here is an example that counts the number of crosses in the variable
"crosses" and creates a new variable which replaces them with "a"s in
the variable "replaced". You can tweak this if you would like to only
replace the "aa"s.
********************
clear*
set obs 100
g crosses = " "
local cross "x"
forv i=1/ 100 {
qui: replace crosses="`cross'" in `i'
local cross "`cross'x"
}
// ssc install egemore, replace
egen noccur = noccur(crosses), string("x")
su noccur
egen replaced = msub(crosses), find("x") replace("a")
********************
T
2009/7/28 <[email protected]>:
> Dear statalists,
>
> I have a string variable X as follows:
>
> X Y
>
> aabb 2
>
> bbdd 0
>
> cdba 1
>
> dxbaa 2
>
> dxaa 2
>
> I want to generate a variable Y to stand for the number of certain characters,
> such as "aa" and replace these characters with other characters, such as "zz".
>
>
> How to do it ?
>
> Thank you !
>
> Sincerely,
>
> From Rose.
>
>
> *
> * For searches and help try:
> * http://www.stata.com/help.cgi?search
> * http://www.stata.com/support/statalist/faq
> * http://www.ats.ucla.edu/stat/stata/
>
--
To every ω-consistent recursive class κ of formulae there correspond
recursive class signs r, such that neither v Gen r nor Neg(v Gen r)
belongs to Flg(κ) (where v is the free variable of r).
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/