I assume by your example you mean "aa" and "a". One way would be
-gen y = regexm(x, "aa") + regexm(x, "a")-
To relace:
-gen x2 = regexr(x,"aa" ,"zz")-
-replace x2 = regexr(x2,"a" ,"z")-
Scott
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/