# Re: st: matrix question

 From Paul Millar To statalist@hsphsun2.harvard.edu Subject Re: st: matrix question Date Thu, 24 Mar 2005 17:06:23 -0700

```Dear Indranil,

As far as I know, there is no easy way to do this in Stata.  You will probably need at least 1 loop to do this:

mat mat2=J(260,1,0)
local rows=0
forvalues i=1/260 {
if mat1[`i',1]==999999 {
local nrows=`nrows'+1
mat mat2[`nrows',1]=mat1[`i',2]
}
}
di "`nrows' rows updated in mat2"

- Paul
Sociology
University of Calgary

----- Original Message -----
From: Indranil Majumdar <imajumdar@creditsights.com>
Date: Thursday, March 24, 2005 10:34 am
Subject: st: matrix question

> Hi,
>
> I have a matrix (mat1) with the following data (extract).
>
> . matrix list mat1
>
> mat1[260,2]
>        ratsect     cutoff
>  r1     999999  3.435e-06
>  r2     999999  4.572e-06
>  r3     999999  6.596e-06
>  r4     999999  9.606e-06
>  r5     999999  .00001548
> r22     999998  5.470e-06
> r23     999998   .0000119
> r24     999998   .0000177
> r25     999998   .0000295
> r26     999998   .0000439
>
> I want to create another matrix (say mat2) with only those rows
> that have a
> particular 'ratsect' e.g. 999999
>
> I guess the command will look something like the following.
> matrix mat2 = mat1["some expression ???",2]
> I am not sure how to filter rows based on a criterion.
> Any help will be appreciated.
>
> Thanks,
> Indranil
> CreditSights. Inc,
> (212) 340-3820
>
> *
> *   For searches and help try:
> *   http://www.stata.com/support/faqs/res/findit.html
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```