Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: matrix-addressing rownames-inserting missings


From   "Scott Merryman" <[email protected]>
To   <[email protected]>
Subject   st: RE: matrix-addressing rownames-inserting missings
Date   Fri, 3 Jun 2005 05:41:31 -0500

One way would be to use -capture- and nullmat.

For example:

matrix drop _all
matrix m = (1, 2, 3\ 4, 5, 6\ 7, 8, 9)

capture matrix b  = m["r2",1]
if _rc !=0 {
	matrix b = (nullmat(b),.)
	}

capture matrix d=m["d",1]
if _rc !=0 {
	matrix d = (nullmat(d),.)
	}
	
matrix list m
matrix list b
matrix list d


Hope this helps,
Scott


> -----Original Message-----
> From: [email protected] [mailto:owner-
> [email protected]] On Behalf Of Nicole Schneeweis
> Sent: Friday, June 03, 2005 4:25 AM
> To: [email protected]
> Subject: st: matrix-addressing rownames-inserting missings
> 
> hello,
> 
> i'm exporting cells out of matrices, and have a problem when cells are
> missing.
> 
> To be more precise:
> 
> it's important for me, to address the relevant row of a matrix with its
> name, not with its number (because it's a loop and numbers are changing,
> not names)
> 
> e.g. matrix M  is defined with rownames, a, b, c. I need the first
> column of row "b" and therefore I create a new matrix: matrix
> B=M["b",1].
> 
> Now, the problem is the following: in some matrices (of the loop) not
> all rows are available, but eg only the rows a and c.
> 
> The loop stops when "b" is not found! I want Stata to insert a missing
> and going on, rather than giving the error message and stopping the
> loop!
> 
> Possilbly there is an option, how to treat not-found-rows or an
> if-function has to be implemented. But how?
> 
> Does anyone know a solution to this problem???
> 
> Thanks
> Nicole
> 
> 
> *
> *   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/



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