[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

From |
"Nick Cox" <n.j.cox@durham.ac.uk> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
RE: st: matrix question |

Date |
Fri, 25 Mar 2005 15:38:25 -0000 |

This is a bit easier in some other software than it is in Stata. But is also a bit easier than this. I agree with the main idea, of looping over rows to select those you want, but Paul's example can be condensed and then extended a bit roughly along these lines: forval i=1/`=rowsof(mat1)' { if mat1[`i',1]==999999 { mat mat2 = nullmat(mat2) \ mat1[`i',2] local rownames "`rownames' `i'" } } matrix rownames mat2 = `rownames' The key details are 1. use -rowsof()- to work out the number of rows on the fly. 2. use -nullmat()- either to initialise or to enlarge a matrix 3. use the loop to select the rownames as well, if of interest. That said, some canned routines in -matvsort- on SSC are other possibilities in nearby terrain. Nick n.j.cox@durham.ac.uk Paul Millar > 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" Indranil Majumdar > > 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. * * 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/

**Follow-Ups**:**st: Cluster Analysis, Factor Analysis and summated rating scales,Matrix ados***From:*Paul Millar <paul.millar@shaw.ca>

- Prev by Date:
**st: RE: adding text to "by graphs"** - Next by Date:
**Re: st: RE: adding text to "by graphs"** - Previous by thread:
**Re: st: matrix question** - Next by thread:
**st: Cluster Analysis, Factor Analysis and summated rating scales,Matrix ados** - Index(es):

© Copyright 1996–2015 StataCorp LP | Terms of use | Privacy | Contact us | What's new | Site index |