Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
st: Transform matrices
From 
 
[email protected] 
To 
 
[email protected] 
Subject 
 
st: Transform matrices 
Date 
 
Mon, 20 Dec 2010 09:24:45 +0000 
Dear matrix wizards,
I tried to get a column vector into a matrix format, such as
1
2
3
4
5
6
 into 
1	2
3	4
5	6
for a general specification.
My clumsy solution was to create two loops
clear
mat def A = (1\ 2\ 3\ 4\ 5\ 6)
forvalues n = 1(2)5 {
	mat a`n' = A[`n', 1]
	if `n' == 1	local m = "`n'"
		else local m = "`m' \ `n'"
	mat c1 = (`m')
}
forvalues n = 2(2)6 {
	mat a`n' = A[`n', 1]
	if `n' == 2	local k = "`n'"
		else local k = "`k' \ `n'"
	mat c2 = (`k')
}
mat B = (c1, c2)
mat list B
Surely there is a more elegant (and more general) way? Perhaps Mata is the solution?
This is a rather academic exercise, but it would be nice if someone could share his/her potential code example.
Cheers,
Ulrich
Please access the attached hyperlink for an important electronic communications disclaimer: http://lse.ac.uk/emailDisclaimer
*
*   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/