Statalist


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

st: counting the number of times a string appears in a string variable?


From   "Mingfeng Lin" <[email protected]>
To   [email protected]
Subject   st: counting the number of times a string appears in a string variable?
Date   Tue, 4 Nov 2008 21:42:28 -0500

Greetings,

I looked through the list of string functions but couldn't find one
that fits the bill.  Suppose I have a string variable X, and I would
like to generate a new numeric variable Y containing the number of
times a certain string appeared in X.  For instance

X = "johnabc johncd"

If I'd like to find the number of times "john" shows up in X, I hope to obtain
Y = 2

Is there a function in Stata to do this?

Thank you very much for your help!

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