Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: st: Re: string comparision


From   tashi lama <ltashi32@hotmail.com>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: Re: string comparision
Date   Tue, 31 Jul 2012 14:06:39 +0000

awesome.. Thanx guys.

----------------------------------------
> Date: Mon, 30 Jul 2012 20:34:18 -0700
> From: bichsan@yahoo.com
> Subject: Re: st: Re: string comparision
> To: statalist@hsphsun2.harvard.edu
>
> Hi Tashi,
>
> I think strpos is what you need
>
> list if strpos(Name,"Jo")>0
>
> Regards,
> San
>
> ----- Original Message -----
> From: Joseph Coveney <jcoveney@bigplanet.com>
> To: statalist@hsphsun2.harvard.edu
> Cc: 'tashi lama' <ltashi32@hotmail.com>
> Sent: Monday, July 30, 2012 9:43 PM
> Subject: st: Re: string comparision
>
> Tashi Lama wrote:
>
> Is there a direct way of listing variables matching all of the some of the
> strings, similar to sql functions "like" and "rlike" ? Here is my dataset say,
>
> ID Name
> 1 John Malda
> 2 Sam Houston
>
> I would like to list Name var matching full or part of the string something like
> following
>
> list if Name like "Jo"
>
> I searched for previous posts related to above question and found some of the
> string-matching functions/commands like strgroup, reclink and strmatch. I can
> picture using strmatch to solve my problem but that wouldn't be direct in the
> sense, I will have to use loops and may be create indicator variables to get my
> job done. But again, I can only picture at this point. Any folks know any direct
> and better options?
>
> --------------------------------------------------------------------------------
>
> Stata's -strmatch()- function does just what you want. It works with wildcard
> symbols, just like SQL's LIKE. -strmatch()- is direct, and you don't need to
> create indicator variables or use loops. See illustration below.
>
> Stata also has regular expression capabilities, but they're not needed to do
> what you show that you want to accomplish.
>
> Joseph Coveney
>
> . drop _all
>
> . input byte ID str244 Name
>
> ID
>>
>>
>> Name
> 1. 1 "John Malda"
> 2. 2 "Sam Houston"
> 3. end
>
> .
> . list if strmatch(Name, "*Jo*"), noobs
>
> +-----------------+
> | ID Name |
> |-----------------|
> | 1 John Malda |
> +-----------------+
>
>
> *
> * 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/ 		 	   		  
*
*   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   |   Site index