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]

st: Re: Extracting a submatrix based on multiple conditions


From   Partho Sarkar <partho.ss@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   st: Re: Extracting a submatrix based on multiple conditions
Date   Fri, 1 Jul 2011 16:43:25 +0530

I am very new to Mata, so please excuse if this is too naive.  I have
a very short question:

In Mata, is there a way, and if so what, to extract a submatrix of
rows where more than one condition is met, i.e., conditions on values
in 2 or more columns?  E.g., in the following matrix

         1       2       3       4       5
    +-----------------------------------------+
  1 |  18049       1       1      91    2500  |
  2 |  18079       2       1      91    2500  |
  3 |  18079       1       1     124    2300  |
    +-----------------------------------------+

I want to extract the rows where the column 2 value==1 AND column 3
value==1 .  As far as I can see so far, this is possible for a single
condition, e.g.,

y[.,3]:==1

would give me the row numbers where this condition is met.  But this
does not work ( I tried with various parentheses):

 y[.,3]:==1 & y[.1]:==1

Many thanks
P.S.

*
*   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