Subject: | |
From: | |
Reply To: | |
Date: | Tue, 31 Oct 2006 01:46:50 -0600 |
Content-Type: | text/plain |
Parts/Attachments: |
|
|
On 10/30/06, Barry C. Burden <[log in to unmask]> wrote:
> I am trying to write some if/then statements in Stata that depend on the
> value of a string variable. The trouble is that variable contains names
> that are not always spelled the same way or written out fully. For
> example, in one observation the name is written as "Hoover, Herbert" but
> in another observation it has been shortened to "Hoover, Herb." To
> capture both of these possibilities I would like to tell Stata to recode
> if y=="Hoov*" or some such thing. Unfortunately, the user guide isn't
> clear about the use of wildcards with string variables and my own
> experiments have failed. Perhaps this is a better question for the
> Stata users list, but I thought another political scientist who has
> worked with strings might be able to come through with a solution.
You may want to try the regexm and/or strmatch functions; alas,
Stata's online help doesn't really document the pattern matching
syntax for either... but if regexm(y, "Hoov.*") should do it -- note
you use '.*' instead of '*' in regular expressions to match any
string.
Hope this helps,
Chris
--
Christopher N. Lawrence <[log in to unmask]>
Assistant Professor of Political Science (non-tenure-track)
Saint Louis University
109 Fitzgerald Hall
3500 Lindell Boulevard
St. Louis, Missouri 63103-1021
Website: http://www.cnlawrence.com/
**********************************************************
Political Methodology E-Mail List
Editor: Karen Long Jusko <[log in to unmask]>
**********************************************************
Send messages to [log in to unmask]
To join the list, cancel your subscription, or modify
your subscription settings visit:
http://polmeth.wustl.edu/polmeth.php
**********************************************************
|
|
|