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

st: RE: RE: RE: Filling upper triangle of a symetric matrix


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: RE: RE: Filling upper triangle of a symetric matrix
Date   Wed, 26 Mar 2003 17:30:01 -0000

Ronnie Babigumira

> Works like a charm (can it be generalized for similar 
> problems or is it not
> worth the extra bit)

One generalisation: 

program matfill 
* NJC 1.0.0 26 March 2003 daffodils out in Durham
* fill in matrix missings from transpose 
	version 8 
	args m garbage 
	confirm matrix `m' 
	if "`garbage'" != "" error 198 

	if !matmissing(`m') { 
		di as err "no missings in `m'" 
		exit 498 
	} 

	if `= colsof(`m')' != `= rowsof(`m')' { 
		di as err "`m' not square"
		exit 498 
	}
	else local n = colsof(`m') 	

	forval i = 1/`n' {
		forval j = 1/`n' {
	 		if `m'[`i',`j'] == . {
				if `i' == `j' { 
					di as txt "can't replace on diagonal"
				}	
				else matrix `m'[`i',`j']  = `m'[`j',`i']
			}
		}	
 	}
end 

Nick 
[email protected] 
*
*   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