Another way to do this is a combination of -svmat- & -keep-/-drop- & -mkmat-
to move to data area and use familiar -keep- or -drop- there. But because
this uses data area, you have to take care of your data in memory first
perhaps using -preserve- and -restore- afterwards.
Try this:
preserve
drop _all
svmat mat1, name(col)
drop if ratsect~=999999
mkmat _all, mat(mat2)
restore
Hope this will help,
Ichiro
On 05.3.25 9:06, "Paul Millar" <[email protected]> wrote:
> 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 <[email protected]>
> 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/
>
*
* 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/