Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Re: st: how to count the number of certain characters in a string variable?


From   [email protected]
To   statalist<[email protected]>
Subject   Re: Re: st: how to count the number of certain characters in a string variable?
Date   Tue, 28 Jul 2009 22:47:56 +0800

Tirthankar and Scott, Thank you very much for your help!

I know how to do now. -egen- is a very useful command!


----- Original Message -----
From: Scott Merryman <[email protected]>
To: [email protected]
Subject: Re: st: how to count the number of certain characters in a string variable?
Date: 2009-7-28 22:18:29

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 燳
>
> aabb ?
>
> bbdd ?
>
> cdba ?
>
> dxbaa ?
>
> dxaa ?
>
> 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/

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



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index