David A. Kenny
May 15, 2010
Data Restructuring Macros
This page describes two macros
for restructuring dyadic data. They are as follows:
Pairwise: Take Individual Data and turn it into a Pairwise Data Set
IndToDyad: Take Individual Data and turn it into a Dyad Data Set
(see Kenny, Kashy, & Cook Chapter 1 for definitions)
To understand how to run a macro, go to the DataToText page.
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.
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 a 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 seems to
handle missing data properly.
All results should be checked and there is no guarantee
of accuracy.
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.