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]
RE: st: One varlist into a matrix with multiple columns
From
Joe Canner <[email protected]>
To
"[email protected]" <[email protected]>
Subject
RE: st: One varlist into a matrix with multiple columns
Date
Wed, 14 Aug 2013 21:16:08 +0000
But, Scott's suggestion using -reshape- could be followed by the following Mata command (or similar):
a=st_data(.,"x1-x10")
which I think would achieve the desired result and be a little easier to understand. Of course, -reshape- may not be the best option if the matrix is sparse or the indices irregular.
Joe Canner
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Sergiy Radyakin
Sent: Wednesday, August 14, 2013 5:01 PM
To: [email protected]
Subject: Re: st: One varlist into a matrix with multiple columns
No he wants a matrix:
clear
set obs 10
gen i = _n
expand 10
bys i: gen j = _n
gen x = rnormal()
*** this is only one possible way of determining the matrix size **** sum i local rows=r(max) sum j local cols=r(max) matrix M=J(`rows',`cols',.)
*********************************************************************
forval z=1/`=_N' {
local tr=i[`z']
local tc=j[`z']
matrix M[`tr',`tc']=x[`z']
}
matrix list M
On Wed, Aug 14, 2013 at 4:48 PM, Scott Merryman <[email protected]> wrote:
> Do you mean something like:
>
> clear
> set obs 10
> gen i = _n
> expand 10
> bys i: gen j = _n
> gen x = rnormal()
> reshape wide x , i(i) j(j)
> l
>
> Scott
>
>
> On Wed, Aug 14, 2013 at 3:15 PM, Samuel Bailey <[email protected]> wrote:
>> Hello,
>>
>> I have a dataset with three columns: the first two are the i and j
>> coordinates of a potential matrix, and the third is the data that
>> would go into the (i,j)th spot. Is there a way (in Stata or Mata) to
>> create a matrix directly from these three variables? I've tried using
>> -mkmat- to create a column vector which gets sent to Mata, where it's
>> looped through into a new matrix. However, as a column vector the
>> data exceeds the maximum matrix size in my version of Stata (though
>> as a square matrix it would not).
>>
>> Sincerely,
>> Sam Bailey
> *
> * For searches and help try:
> * http://www.stata.com/help.cgi?search
> * http://www.stata.com/support/faqs/resources/statalist-faq/
> * http://www.ats.ucla.edu/stat/stata/
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/