Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.

# RE: st: Keeping values in upper triangle of matrix

 From Michael Betz To "statalist@hsphsun2.harvard.edu" Subject RE: st: Keeping values in upper triangle of matrix Date Wed, 7 Dec 2011 03:36:13 +0000

```Awesome Brendan, that's the command I needed! I'm having a problem now with the next step, getting the column vector into Stata. When I use -st_matrix- Stata freezes up. I'm trying to put a 4729350x1 column vector, so I don't know if I'm running into a size problem. I'm using Stata 11 SE. My revised code is below.

foreach x of varlist amenityscale-wages{
use "Merged1993", clear
mkmat `x'

mata: a=st_matrix("`x'")
mata: b=J(3075,3075,1)
mata: c=b:*a
mata: d=c:-a'
mata: e=vech(d)
mata: st_matrix("`x'", e)		//This is the step where Stata freezes up

svmat `x'
keep `x'
if `j'>0 merge 1:1 _n using "Finalmat93_00", nogen
save "Finalmat93_00", replace
local j=`j'+1
}

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Brendan Halpin
Sent: Tuesday, December 06, 2011 5:36 PM
To: statalist@hsphsun2.harvard.edu
Subject: Re: st: Keeping values in upper triangle of matrix

On Tue, Dec 06 2011, Michael Betz wrote:

> I wondered if there was a way to
> save all the elements of the upper triangle of the matrix as a column
> vector.

Check out the vech() function in Mata.

Brendan
--
Brendan Halpin,   Department of Sociology,   University of Limerick,   Ireland
Tel: w +353-61-213147  f +353-61-202569  h +353-61-338562;  Room F1-009 x 3147
mailto:brendan.halpin@ul.ie    ULSociology on Facebook: http://on.fb.me/fjIK9t
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```