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   Roger Newson <roger.newson@kcl.ac.uk>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: search the dataset for a string value
Date   Mon, 23 Feb 2004 16:21:03 +0000

At 16:07 23/02/04 +0000, Paul O'Brien 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?
The -index()- function evaluates to zero if the second argument appears nowhere in the first argument. And -if- treats zero value as "no", and treats all nonzero numeric values (including negative and missing values) as "yes". See -help ifcmd- and -help if- for further references.

Roger


--
Roger Newson
Lecturer in Medical Statistics
Department of Public Health Sciences
King's College London
5th Floor, Capital House
42 Weston Street
London SE1 3QD
United Kingdom

Tel: 020 7848 6648 International +44 20 7848 6648
Fax: 020 7848 6620 International +44 20 7848 6620
or 020 7848 6605 International +44 20 7848 6605
Email: roger.newson@kcl.ac.uk
Website: http://www.kcl-phs.org.uk/rogernewson

Opinions expressed are those of the author, not the institution.

*
* 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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index