Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: Wildcard for string variables


From   "John Wagai" <jwagai@nairobi.kemri-wellcome.org>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: Wildcard for string variables
Date   Thu, 17 Jul 2008 16:11:17 +0300

Hi,

To get to your final answer use the regex command:

gen seq = regexm(newvar, "Tim")

NB use the newvar generated by Rich below

JW

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Richard
Goldstein
Sent: 17 July 2008 16:04
To: statalist@hsphsun2.harvard.edu
Subject: Re: st: Wildcard for string variables

Sorry about the typo:

gen byte newvar=substr(sequence,1,4)=="Tim "

Richard Goldstein wrote:
> I don't see any need for a wildcard; how about
> 
> gen byte newvar=substr(sequence,1,4)=="Tim"
> 
> Rich
> 
> Hugh Colaco wrote:
>> Hi Statalisters,
>>
>> I am not sure how the string wildcard works. For example, I have a
>> string variable called "sequence" that has the following
>> observations:-
>>
>> 1. "Tim and Tom and Jane"
>> 2. "Tim and Jane and Tom"
>> 3. "Tom and Jane and Harry"
>> 4. "Jane and Jill"
>>
>> I want to generate a new variable that equals one if Tim is the first
>> name mentioned, and zero otherwise.
>>
>> Thanks in advance,
>>
> *
> *   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/
> 
> 
*
*   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/

17/7/2008
"This e-mail (including any attachment to it) contains information
which is confidential. It is intended only for the use of the named
recipient. If you have received this e-mail in error, please let us know
by replying to the sender, and immediately delete it from your system.
Please note, that in these circumstances, the use, disclosure,
distribution or copying of this information is strictly prohibited. We
apologize for any inconvenience that may have been caused to you.
KEMRI-Wellcome Trust cannot accept any responsibility for the accuracy
or completeness of this message as it has been transmitted over a public
network. The Unit reserves the right to monitor all incoming and
outgoing email traffic. Although the Unit has taken reasonable
precautions to ensure no viruses are present in emails, the Unit cannot
accept responsibility for any loss or damage arising from the use of the
email or attachments. Any views expressed in this message are those of
the individual sender, except where the sender specifically states them
to be the views of KEMRI- Wellcome Trust Research".

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