Bookmark and Share

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: Converting table into matrix


From   R Zhang <[email protected]>
To   [email protected]
Subject   Re: st: Converting table into matrix
Date   Sun, 23 Mar 2014 21:52:24 -0400

Thank you Sergiy very much !!!

1. is your program written with MATA?

concerning the points you raised at the beginning of your program:

1) rows and columns sets - overlapping or same or non-overlapping;
- I am not sure what you mean here. Basically the row variables will
also appear as columns variables  in the same order in the matrix


2) which variable goes to rows and which to cols;

-Basically the row variables will also appear as columns variables  in
the same order in the matrix

3) whether you want 0 or missings for non-mentioned cells;

- I want a symmetric matrix, that is fill A[1,2]  with the value of
A[2,1]. this may require additional programming


4) whether you want to reflect the negative values (instead
ofA[1,2]=-3 write A[2,1]=3)

- I may have misinterpreted your comment.  my dataset does not have
negative values.

5) adding column and row names instead of codes.

- yes i like to keep column and row names

On Fri, Mar 21, 2014 at 10:22 PM, Sergiy Radyakin
<[email protected]> wrote:
> Rongrong, below is a skeleton of the program. You will have to take
> care about the following:
> 1) rows and columns sets - overlapping or same or non-overlapping;
> 2) which variable goes to rows and which to cols;
> 3) whether you want 0 or missings for non-mentioned cells;
> 4) whether you want to reflect the negative values (instead of
> A[1,2]=-3 write A[2,1]=3)
> 5) adding column and row names instead of codes.
> So use code below as a starting point.
> Best, Sergiy Radyakin
>
> clear all
> input str20 C_industry str20 S_industry int x
> Forestrysupport Forestrysupport 0
> Forestrysupport Forestrynursery 0
> Forestrysupport logging 0
> Forestrynursery Forestrysupport 64
> Forestrynursery Forestrynursery 1
> Forestrynursery logging 1
> logging Forestrysupport 7
> logging Forestrynursery 29
> logging logging 41
> end
>
> list
> encode C_industry, gen(c)
> encode S_industry, gen(s)
> drop C_ S_
> list
> levelsof c, local(levs)
> local rows : word count `levs'
> matrix A=J(`rows',`rows',.)
> matrix list A
>
> forval i=1/`=_N' {
>   local r=c[`i']
>   local c=s[`i']
>   matrix A[`r',`c']=x[`i']
> }
>
> matrix list A
>
> *******************************************
>
> A[3,3]
>     c1  c2  c3
> r1   1  64   1
> r2   0   0   0
> r3  29   7  41
>
>
> On Fri, Mar 21, 2014 at 10:08 PM, R Zhang <[email protected]> wrote:
>> Dear All,
>>
>> I need to convert a 470*470 table into matrix. Below I supplied a 3 *3
>> table and desired matrix output. I never used matrix in stata. if you
>> could suggest a sample program that will be great .
>>
>> thank you in advance !!
>>
>> ++++++++++ what I have +++++++++++
>>
>> C_industry S_industry input
>> Forestrysupport Forestrysupport 0
>> Forestrysupport Forestrynursery 0
>> Forestrysupport logging 0
>> Forestrynursery Forestrysupport 64
>> Forestrynursery Forestrynursery 1
>> Forestrynursery logging 1
>> logging Forestrysupport 7
>> logging Forestrynursery 29
>> logging logging 41
>>
>>
>>
>> ++++++++++ what I like to have +++++++++++
>> Forestrysupport Forestrynursery logging
>> Forestrysupport 0 0 0
>> Forestrynursery 64 1 1
>> logging 7 29 41
>>
>>
>>
>> Thank you !
>>
>> rongrong
>> *
>> *   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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index