David A. Kenny

September 10, 2014

 

Data Restructuring Macros

 

      This page describes two different macros for restructuring dyadic data. They are as follows:

 

Pairwise.sps: Take an individual dataset and turn it into a pairwise dataset

IndToDyad: Take an individual dataset and turn it into a dyad dataset

 

      There is program written in R (free!) that can not only be used to restructure dyadic data but also to provide text output describing the data. Also, it can restructure a dyad dataset into a pairwise dataset. The program is called RDDD: Click here to go to a description of that program.

      See Kenny, Kashy, and Cook's Chapter 1 or view the Dyad Structures webinar for definitions of the different data structures. Also watch the Restructuring Dyadic Data webinar.   (There is a small charge if you view more than one webinar; there is also a powerpoint on Restructuring Dyadic Data.)

 

      To understand how to run an SPSS macro, go to the DataToText page.

 

 

Pairwise

 

Before running this macro make sure you have a backup copy of your original data! This macro turns an individual dataset into a pairwise data set. Here are the files you need to download (you need SPSS for each):

 

The macro: pairwise.sps

Macro call: callpairwise.sps  

You can also download these file to see an example of this macro (you need SPSS for each):  

Sample data: indiv.sav

Output data: pairwise.sav  

To run a macro you need to do the following:
      1 Download the macro syntax of pairwise.sps.
      2. Download the call statement of call pairwise.sps.
      3. Open SPSS.
      4. Open (Load) your data file using the menu: File>Open>Data
      5. Open a Syntax Window using the menu: File>Syntax
      6. Find the macro that you downloaded in Step 1 (i.e. pairwise.sps) and open it.
      7. Run the macro. To do so, use the menu: Run>All
      8. Open a Syntax Window using the menu: File>Syntax
      9. Find the call statement (e.g., callpairwise.sps) and open it.
      10. Put in the names of variables and other information for your run.
      11. Run the syntax: Run>All
      12. When done, find and look at the restructured dataset.

There are five variables in the macro: The dyad identification code (dyadid), an index for actor (i1), an index for partner (i2), the name and place of the restructured file (use quotes and defaults to c:\pairwise.sav), and temporary directory to write scratch files (use quotes and defaults to c:\). For instance you might say in an SPSS syntax file:

 

Pairwise dyadid =dyadcode i1 = 'A' i2='P'.

 

where dyadid is a variable called dyadcode in the SPSS data file, there are quotes around A and P, and blanks separate the three arguments. In the output data file, note that the A variables will be written before the P variables. However, if the index was P (for person) and O (for other), the O variables will be written first, as they are ordered alphabetically.    For example, if there is a variable Satis in the data file, the pairwise data file will have two variables Satis_A and Satis_P.  The macro recognizes between-dyads variables and does not create two variables for them, but it does create two variables for within-dyads variables.

 

All variables in the data file must be numeric and not string or character variables.  Also make sure that there are no more than two cases per each “dyadid.”

 

The defaults for the pairwise macro are as follows:

dyadid: dyadid

i1: A

i2: P

directory: ‘C:\’

ofile: ‘c:\pairwise.sav

Make sure that no "dyads" have more than two cases and at least some dyads have two cases. Note also the variable Partnum is created that gives one member a "1" and the other a "2." Such a variable can be useful in some applications.  The programs seem to handle missing data properly.

 

All results should be checked and there is no guarantee of accuracy.

 

IndToDyad

 

Before running this macro make sure you have a backup copy of your original data! This macro turns an individual dataset into a dyad data set.  This program has not been extensively checked and results should be carefully reviewed.  Here are some files to download (you need SPSS for each):

 

The macro: indtodyad.sps

Sample data: indiv.sav

Macro call: callindtodyad.sps

Output data: dyad.sav

 

There are six macro variables:

dyad identification code in the SPSS file (dyadid),

name of the distinguishing variable in the SPSS file (distvar)

an index for person 1 (i1),

an index for person 2(i2),

the name and place of the restructured file (use quotes and defaults to c:\pairwise),

and temporary directory to write scratch files (use quotes and defaults to c:\).

 

For instance you might say in an SPSS syntax file:

 

IndToDyad dyadid =dyadcode distvar= gender i1 = 'F' i2='M'.

 

where dyadid is a variable called dyadcode in the SPSS data file, there are quotes around F and M, and blanks separate the three arguments. In the output data file, note that the F variables will be written before the M variables. However, if the index was W (for wife) and H (for husband), the H variables will be written first, as they are ordered alphabetically. The defaults for dyadid is dyadid, for i1 is 1, and for i2 is 2; thus, we would only need IndToDyad dyadid=dyadcode and if the code for dyad is dyadid, we need only “IndToDyad.” Make sure that no "dyads" have more than two cases and at least some dyads have two cases. Note that the meaning of i1 and i2 is very different in IndToDyad and Pairwise.

 

Note i1 should refer to the “first” value of the distinguishing variable and i2 to the “second.”  So if the distinguishing variable was Role, coded 1 and 2, then i2 refers to the 1s and i2 to the twos.

 

Note also if there are missing data there can be problems with this macro.  You will need to create dummy cases that have the dyadic and the code for the missing value.    

 

 

Return to Chapter 1 Page