Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: If condition for restricting data starting with certain values like 45


From   daniel klein <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: If condition for restricting data starting with certain values like 45
Date   Sun, 5 Jan 2014 11:10:38 +0100

Nick already explained who to get the first two digits from your id
variable, using (string) functions. If you are only interested in the
first two digits and in more than one combination (like 45, 74, 63),
there is no better way.

If you want to search for patterns like 45* (or *45*) you can use
string function -strmatch()- like this

...if strmatch(string(id), "45*")

A canned solution for this is -lookfor_val- from the SSC.

. lookfor_val id ,p(45*) tabulate

will -tabualte- all ids starting with 45.

Best
Daniel

-- 
You seem to be reaching for

... if inlist(substr(string(id), 1, 2), "45", "74", "63")

Notes:

1. -if- used in this way is called a qualifier, not a command.

2. See help on the functions -string()-, -substr()-, -inlist()-.

3. See also http://www.stata-journal.com/article.html?article=dm0058
for an introductory tour of functions.
Nick
[email protected]


On 5 January 2014 02:15, Veeresh Thummadi <[email protected]> wrote:
> Hi
>
> I have a question regarding how to restrict values using if command
> with dynamic values. For instance there are players with ids 45**. So
> I want to tabulate all players with starting rank as 45, 74 and 63.
> How will I do that using if condition statement. The format for the
> rank variable is integer.
>
> Thanks
> Veeresh
*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index