Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Making a Matrix from Three Variables


From   "Glenn Goldsmith" <glenn.goldsmith@gmail.com>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: Making a Matrix from Three Variables
Date   Sat, 9 May 2009 17:44:51 +0100

Hi Allan,

It seems like what you're after is more-or-less the same as converting from
sparse matrix storage, so the mata code here should do the trick:

http://www.stata.com/statalist/archive/2009-04/msg00142.html 

You just need to get your variables into a mata matrix to start with and you
should be away:

  mata : st_view(x=.,.,("var2","var1","var3"))

NB: Note the inverted order of var1 and var2. This is because the code for
-sparse()- assumes that the first variable provides the row index, and the
second variable provides the column index.

HTH,

Glenn.

Allan Joseph Medwick <amedwick@gmail.com> wrote:

Hi, All,

I have three variables (var1, var2, var3).  I would like to create a
matrix where the values of var1 are the columns (ascending), the
values of var2 are the rows (also ascending), and the values of var3
are the elements in the matrix.  I know there must be a user defined
procedure out there to do this, but I haven't been able to find it.

Thanks,
Allan


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



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index