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]

st: RE: Re: Extracting a submatrix based on multiple conditions


From   Nick Cox <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   st: RE: Re: Extracting a submatrix based on multiple conditions
Date   Fri, 1 Jul 2011 12:29:19 +0100

: select(y, (y[,2] :== 1 :& y[,3] :== 1))
           1       2       3       4       5
    +-----------------------------------------+
  1 |  18049       1       1      91    2500  |
  2 |  18079       1       1     124    2300  |
    +-----------------------------------------+

Nick 
[email protected] 

Partho Sarkar

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


*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index