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

Re: st: search the dataset for a string value


From   "Paul O'Brien" <[email protected]>
To   [email protected]
Subject   Re: st: search the dataset for a string value
Date   Mon, 23 Feb 2004 16:07:48 +0000

The help on -index- leaves me a bit ignorant.

I use this without knowing how it works:

gen oral = "OVYS" if index(stk,"OVYS")
replace oral = "MICROG" if index(stk, "MICROG")
replace oral ="FEMOD" if index(stk, "FEMOD")
replace oral = "LOGED" if index(stk, "LOGED")

Index 'returns the position' it finds the string'

The position of MICROG could be, say, 9th character to 14th in the string and returns 9-14. How is this translated in a yes?

Paul

On 23 Feb 2004, at 14:53, Dan Blanchette wrote:


The string function -index- searches a string or a string variable
and returns the position it found the string being searched for or
zero if not found.

. help strfun

. list MyStrVar if index(MyStrVar,"bank")

Or you could search for "bank" in any combination of upper or
lower case by using the -lower- function:

. list MyStrVar if index(lower(MyStrVar),"bank")

will list

MyStrVar

First Citizens Bank
Bank of America
bank
World BaNk

dan


From [email protected]
To [email protected]
Subject st: search the dataset for a string value
Date Mon, 23 Feb 2004 14:20:51 +0000

Dear Statalisters,

Probably this question came up many times, but I can not -findit-.
How do I search for a "string value" in one vector of string observations?
For example search for "bank" in the "company name" variable, so that I will get
all entries that contain the value "bank".

many thanks in advance
Dimitris Christodoulou



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


Dr Paul O'Brien
Westside Contraceptive Services
Raymede Clinic, Exmoor St, London
W10 6DZ
020 8962 4450 - tel
020 8962 4451 - fax
07900 495 118 - mob

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