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

st: Re: search the dataset for a string value


From   Christopher F Baum <[email protected]>
To   [email protected]
Subject   st: Re: search the dataset for a string value
Date   Tue, 24 Feb 2004 06:10:54 -0500

On Feb 24, 2004, at 2:33 AM, Paul wrote:

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?
This function (and most of Stata's string functions) work exactly like those in many programming languages, e.g. c or perl. Since you get a positive return if the substring is found and a zero return if it is not, if(index()) will be true if found, false if not found.

Kit

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