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 |
Nick Cox <n.j.cox@durham.ac.uk> |

To |
"'statalist@hsphsun2.harvard.edu'" <statalist@hsphsun2.harvard.edu> |

Subject |
RE: st: Transform matrices |

Date |
Mon, 20 Dec 2010 16:24:31 +0000 |

For completeness, note that a pre-Mata program was published in STB-56 in 2000 for this purpose: STB-56 dm79 . . . . . . . . . . . . . . . . . . Yet more new matrix commands (help matcorr, matewmf, matvsort, svmat2 if installed) . . N. J. Cox 7/00 pp.4--8; STB Reprints Vol 10, pp.17--23 commands to produce a correlation matrix, elementwise monadic function of another matrix, selected subsets of matrix rows and columns, vec or vech of a matrix, elements sorted within a vector, matrix from a vector, and commands to save matrices see mata matrix language incorporated into Stata 9.0 The program is called -matvtom-. Its main interest is for any users of Stata 6,7,8 out there, but it should still work. For other such extras, see STB-50 dm69 . . . . . . . . . . . . . . . . . . Further new matrix commands (help matdelrc, matewm, matmad, matpow if installed) . . . N. J. Cox 7/99 pp.5--9; STB Reprints Vol 9, pp.29--34 collection of new matrix commands providing additional matrix checking, management, element-wise operators, maximum absolute difference, and power STB-39 dm49 . . . . . . . . . . . . . . . . . . . . Some new matrix commands (help matfunc, varfunc if installed) . . . . . . . . . . . J. Weesie 9/97 pp.17--20; STB Reprints Vol 7, pp.43--48 collection of new matrix commands; several for explicit matrices and a few for implicit matrices (i.e., variables) see mata matrix language incorporated into Stata 9 Nick n.j.cox@durham.ac.uk Tirthankar Chakravarty ====================== 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 Tirthankar Chakravarty ====================== > 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 > ************************************* Ulrich Atz ========== >> 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. * * 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/

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

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

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

- Prev by Date:
**Re: st: asclogit with panel data** - Next by Date:
**st: Re: asclogit with panel data** - Previous by thread:
**Re: st: Transform matrices** - Next by thread:
**Re: st: Transform matrices** - Index(es):