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: filter string variable


From   Nick Cox <njcoxstata@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: filter string variable
Date   Mon, 25 Mar 2013 11:12:01 +0000

You can select _string variables_ that contain text such as "agri" by

... if strpos(mystrvar, "agri")

and by extension by you can select such _observations_.  The function call

strpos(string, "text")

returns a positive number (meaning true) if the starting position of
"text" is 1 or more, and is thus a check on "text" being included.

Otherwise it returns zero, meaning false

To understand this, type

. display strpos("this is an example", "example")

. display strpos("this is not", "example")

Nick

On Mon, Mar 25, 2013 at 11:02 AM, victor <victor.baelus@gmail.com> wrote:

> I have a dataset which contains the amount of contributions from various
> lobbies to a member of congress. However, for my research I am only
> interested in the contributions from the agricultural lobby. Therefore, I
> would like to filter in a way that keeps only the observations which contain
> words like “agri” or “farm” etc. in it. Since I have to do this for various
> members of congress on several occasions I would like to make some sort of
> code for it. So far I am unable to work something out.

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index