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

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


From   "Ronnie Babigumira" <ronnie.babigumira@ios.nlh.no>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: RE: RE: RE: Filling upper triangle of a symetric matrix
Date   Wed, 26 Mar 2003 21:56:42 +0100

Many thanks Nick, just gave matfill a testrun and I am happy as can be
(considering how many sleepless nights I have had ).

Ronnie

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu]On Behalf Of Nick Cox
Sent: 26. mars 2003 18:30
To: statalist@hsphsun2.harvard.edu
Subject: st: RE: RE: RE: Filling upper triangle of a symetric matrix


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
n.j.cox@durham.ac.uk
*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index