Need Help Creating a Matrix

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Need Help Creating a Matrix

Chao Yawo
Hi,

I have a dataset with the following structure.


ColumnA            ColumnB         ColumnC         
ClassA            OtherStud        WorkWith        

AA                     DD                1         
AA                     EE                0         
AA                     BB                1         
BB                     FF                1         
BB                     GG                1          
BB                     KK                0         
CC                     AA                1         
CC                     BB                1         


ColumnA refers to students in ClassroomA, and Column B refers to "Other
Students" in the school who could act as work and/or playmates.  


Note, ColumnB could also include some of the same students in ColumnA(ClassA) who work with each other (For example, Students: AA and BB).

If a Student in Classroom A works with a student in ClassroomB, ColumnC
takes the value of 1, and 0(zero) if otherwise

So, looking at ColumnA, we find that there are three students:  AA, BB and
CC. Student_AA for instance interacts with three students <DD, EE, BB> but only
works with DD and BB.  Similarly, Student_CC interacts with two students
<AA, and BB> and works and plays with each of them.

Now, I am interested in constructing a matrix indicating which
students in ClassroomA work with each other. This means
that student_AA for instance works with student_BB, who is in his/her
classroom, hence the cell in their matrix will have a "1".  
Again, Student_CC in ClassroomA works with 2 other members of
his/her own class<ie, AA and BB>.  So CC would have two "1s" in the matrix.

The resulting matrix for the "Works With" relation (ColumnC) among the 3
students in ClassroomA would look like this.

        AA    BB      CC
AA      0     1        0
BB      0     0        0
CC      1     1        0

This matrix is the output I am interested in, and need to produce for the relationship specified in Column C.
I would certainly appreciate some ideas to help me produce this.


Thanks in advance for your assistance.

Sincerely, Cy

------------------------------------------------------------------

Reply | Threaded
Open this post in threaded view
|

Re: Need Help Creating a Matrix

Ruben Geert van den Berg
Dear Yawo,
 
I'm not exactly sure what you want, but perhaps you could try the syntax below (I somewhat modified the data)?
 
Kind regards,
 
Ruben van den Berg
 
 
data list free/ ClassA OtherStud (2a10) WorkWith (F2).
begin data
AA AA 0
AA BB 1
AA CC 1
BB AA 1
BB BB 0
BB CC 0
CC AA 1
CC BB 0
CC CC 0
end data.
 
sor cas by classa otherstud.
casestovars
/id=classa
/index=otherstud
/groupby=index.




 



 

Date: Mon, 26 Oct 2009 09:38:56 -0400
From: [hidden email]
Subject: Need Help Creating a Matrix
To: [hidden email]

Hi,

I have a dataset with the following structure.


ColumnA            ColumnB         ColumnC         
ClassA            OtherStud        WorkWith        

AA                     DD                1         
AA                     EE                0         
AA                     BB                1         
BB                     FF                1         
BB                     GG                1          
BB                     KK                0         
CC                     AA                1         
CC                     BB                1         


ColumnA refers to students in ClassroomA, and Column B refers to "Other
Students" in the school who could act as work and/or playmates.  

Note, ColumnB could also include some of the same students in ColumnA(ClassA) who work with each other (For example, Students: AA and BB).

If a Student in Classroom A works with a student in ClassroomB, ColumnC
takes the value of 1, and 0(zero) if otherwise

So, looking at ColumnA, we find that there are three students:  AA, BB and
CC. Student_AA for instance interacts with three students <DD, EE, BB> but only
works with DD and BB.  Similarly, Student_CC interacts with two students
<AA, and BB> and works and plays with each of them.

Now, I am interested in constructing a matrix indicating which
students in ClassroomA work with each other. This means
that student_AA for instance works with student_BB, who is in his/her
classroom, hence the cell in their matrix will have a "1".  
Again, Student_CC in ClassroomA works with 2 other members of
his/her own class<ie, AA and BB>.  So CC would have two "1s" in the matrix.

The resulting matrix for the "Works With" relation (ColumnC) among the 3
students in ClassroomA would look like this.

        AA    BB      CC
AA      0     1        0
BB      0     0        0
CC      1     1        0

This matrix is the output I am interested in, and need to produce for the relationship specified in Column C.
I would certainly appreciate some ideas to help me produce this.


Thanks in advance for your assistance.

Sincerely, Cy

------------------------------------------------------------------



New Windows 7: Find the right PC for you. Learn more.
Reply | Threaded
Open this post in threaded view
|

Re: Need Help Creating a Matrix

Chao Yawo
Ruben, thanks very much for your response.  the modification is ok ... I will try out the code later tonight and report back.

rgds, Cy
------------------------------------------------------------------


On Mon, Oct 26, 2009 at 1:46 PM, Ruben van den Berg <[hidden email]> wrote:
Dear Yawo,
 
I'm not exactly sure what you want, but perhaps you could try the syntax below (I somewhat modified the data)?
 
Kind regards,
 
Ruben van den Berg
 
 
data list free/ ClassA OtherStud (2a10) WorkWith (F2).
begin data
AA AA 0
AA BB 1
AA CC 1
BB AA 1
BB BB 0
BB CC 0
CC AA 1
CC BB 0
CC CC 0
end data.
 
sor cas by classa otherstud.
casestovars
/id=classa
/index=otherstud
/groupby=index.




 



 

Date: Mon, 26 Oct 2009 09:38:56 -0400
From: [hidden email]
Subject: Need Help Creating a Matrix
To: [hidden email]


Hi,

I have a dataset with the following structure.


ColumnA            ColumnB         ColumnC         
ClassA            OtherStud        WorkWith        

AA                     DD                1         
AA                     EE                0         
AA                     BB                1         
BB                     FF                1         
BB                     GG                1          
BB                     KK                0         
CC                     AA                1         
CC                     BB                1         


ColumnA refers to students in ClassroomA, and Column B refers to "Other
Students" in the school who could act as work and/or playmates.  

Note, ColumnB could also include some of the same students in ColumnA(ClassA) who work with each other (For example, Students: AA and BB).

If a Student in Classroom A works with a student in ClassroomB, ColumnC
takes the value of 1, and 0(zero) if otherwise

So, looking at ColumnA, we find that there are three students:  AA, BB and
CC. Student_AA for instance interacts with three students <DD, EE, BB> but only
works with DD and BB.  Similarly, Student_CC interacts with two students
<AA, and BB> and works and plays with each of them.

Now, I am interested in constructing a matrix indicating which
students in ClassroomA work with each other. This means
that student_AA for instance works with student_BB, who is in his/her
classroom, hence the cell in their matrix will have a "1".  
Again, Student_CC in ClassroomA works with 2 other members of
his/her own class<ie, AA and BB>.  So CC would have two "1s" in the matrix.

The resulting matrix for the "Works With" relation (ColumnC) among the 3
students in ClassroomA would look like this.

        AA    BB      CC
AA      0     1        0
BB      0     0        0
CC      1     1        0

This matrix is the output I am interested in, and need to produce for the relationship specified in Column C.
I would certainly appreciate some ideas to help me produce this.


Thanks in advance for your assistance.

Sincerely, Cy

------------------------------------------------------------------



New Windows 7: Find the right PC for you. Learn more.