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

# Re: st: Transform matrices

 From Tirthankar Chakravarty To statalist@hsphsun2.harvard.edu Subject Re: st: Transform matrices Date Mon, 20 Dec 2010 01:40:58 -0800

```Using the Mata -rowshape()- function:

*************************************
clear*
mat define A = (1, 2, 3, 4, 5, 6)'
mata: st_matrix("B", rowshape(st_matrix("A"), 3))
mat list B
*************************************

T

On Mon, Dec 20, 2010 at 1:24 AM,  <u.atz@lse.ac.uk> wrote:
> 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/
>

--
To every ω-consistent recursive class κ of formulae there correspond
recursive class signs r, such that neither v Gen r nor Neg(v Gen r)
belongs to Flg(κ) (where v is the free variable of r).

*
*   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/
```