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]

From |
Tirthankar Chakravarty <tirthankar.chakravarty@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: Transform matrices |

Date |
Mon, 20 Dec 2010 01:49:59 -0800 |

More generally, you can use selection vectors: ************************************* clear* mat define A = (1, 2, 3, 4, 5, 6)' mata mA = st_matrix("A") st_matrix("B", (mA[2:*(1::length(mA)/2):-1,1], /// mA[2:*(1::length(mA)/2),1])) end mat list B ************************************* T On Mon, Dec 20, 2010 at 1:40 AM, Tirthankar Chakravarty <tirthankar.chakravarty@gmail.com> wrote: > 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). > -- 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/

**Follow-Ups**:**RE: st: Transform matrices***From:*Nick Cox <n.j.cox@durham.ac.uk>

**References**:**st: Transform matrices***From:*u.atz@lse.ac.uk

**Re: st: Transform matrices***From:*Tirthankar Chakravarty <tirthankar.chakravarty@gmail.com>

- Prev by Date:
**Re: st: Transform matrices** - Next by Date:
**st: tabulate: one variable against two others?** - Previous by thread:
**Re: st: Transform matrices** - Next by thread:
**RE: st: Transform matrices** - Index(es):