SPSS syntax for yoked pair

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

SPSS syntax for yoked pair

Tuerk, Elena
Hi list,

I'm new to yoked pair matching and have received a brief snippet of syntax that I was hoping to confirm/streamline. I will be matching comparison group cases to criteria based on each individual in the treatment group. I need to do this for about 50 participants.

For example, if I matching on the following characteristics that Participant ID 4 has:
age = 4
gender = 1
year = 2006

Do I use the following syntax to find a matching case to yoke?

SELECT IF
age=4,
gender=1,
year=2006 .
EXECUTE .

Also, it seems somewhat inefficient to change the syntax for each case that is being matched (e.g., for another case age=3, gender=0, etc.). Is there a way to write it so that it selects based on whatever filter is on?

Thanks for your help!

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re:SPSS syntax for yoked pair

Jerabek Jindrich
Hello,

it is realy inefficient to look for match case by case.

You could compute an ID based on the participant's characteristic. for example :
COMPUTE CharID = 10*year + 100*age + gender.
Do it both for participants and comparison group and
1) if they are in separate files match them:
MATCH files /file = participants / file = comparison / by CharId.   or
2) If they are in one file - sort the file by CharId plus participant/compare, You will get pairs in subsequent cases.

This all will not work properly if you have participants without exact match in comparison group or have several participants with the same year and age and sex. However in this case neither matching nor your SELECT syntax will work.


best regards
Jindra




> ------------ Původní zpráva ------------
> Od: Tuerk, Elena <[hidden email]>
> Předmět: SPSS syntax for yoked pair
> Datum: 29.5.2008 14:49:22
> ----------------------------------------
> Hi list,
>
> I'm new to yoked pair matching and have received a brief snippet of syntax that
> I was hoping to confirm/streamline. I will be matching comparison group cases to
> criteria based on each individual in the treatment group. I need to do this for
> about 50 participants.
>
> For example, if I matching on the following characteristics that Participant ID
> 4 has:
> age = 4
> gender = 1
> year = 2006
>
> Do I use the following syntax to find a matching case to yoke?
>
> SELECT IF
> age=4,
> gender=1,
> year=2006 .
> EXECUTE .
>
> Also, it seems somewhat inefficient to change the syntax for each case that is
> being matched (e.g., for another case age=3, gender=0, etc.). Is there a way to
> write it so that it selects based on whatever filter is on?
>
> Thanks for your help!
>
> =====================
> To manage your subscription to SPSSX-L, send a message to
> [hidden email] (not to SPSSX-L), with no body text except the
> command. To leave the list, send the command
> SIGNOFF SPSSX-L
> For a list of commands to manage subscriptions, send the command
> INFO REFCARD
>
>
>

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: SPSS syntax for yoked pair

Tuerk, Elena
Thanks so much, Jindra.

Can I trouble you with another question? Let's say the goal is to find ALL cases that match the participant characteristics (and then randomly select one of the matching cases). Is there any way to make the syntax work to find all cases?

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Jerabek Jindrich
Sent: Thursday, May 29, 2008 12:55 PM
To: [hidden email]
Subject: Re:SPSS syntax for yoked pair

Hello,

it is realy inefficient to look for match case by case.

You could compute an ID based on the participant's characteristic. for example :
COMPUTE CharID = 10*year + 100*age + gender.
Do it both for participants and comparison group and
1) if they are in separate files match them:
MATCH files /file = participants / file = comparison / by CharId.   or
2) If they are in one file - sort the file by CharId plus participant/compare, You will get pairs in subsequent cases.

This all will not work properly if you have participants without exact match in comparison group or have several participants with the same year and age and sex. However in this case neither matching nor your SELECT syntax will work.


best regards
Jindra




> ------------ Původní zpráva ------------
> Od: Tuerk, Elena <[hidden email]>
> Předmět: SPSS syntax for yoked pair
> Datum: 29.5.2008 14:49:22
> ----------------------------------------
> Hi list,
>
> I'm new to yoked pair matching and have received a brief snippet of
> syntax that I was hoping to confirm/streamline. I will be matching
> comparison group cases to criteria based on each individual in the
> treatment group. I need to do this for about 50 participants.
>
> For example, if I matching on the following characteristics that
> Participant ID
> 4 has:
> age = 4
> gender = 1
> year = 2006
>
> Do I use the following syntax to find a matching case to yoke?
>
> SELECT IF
> age=4,
> gender=1,
> year=2006 .
> EXECUTE .
>
> Also, it seems somewhat inefficient to change the syntax for each case
> that is being matched (e.g., for another case age=3, gender=0, etc.).
> Is there a way to write it so that it selects based on whatever filter is on?
>
> Thanks for your help!
>
> =====================
> To manage your subscription to SPSSX-L, send a message to
> [hidden email] (not to SPSSX-L), with no body text except
> the command. To leave the list, send the command SIGNOFF SPSSX-L For a
> list of commands to manage subscriptions, send the command INFO
> REFCARD
>
>
>

=====================
To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: SPSS syntax for yoked pair

Jerabek Jindrich
Hello,

Because I dont know how your files are structered and am not aware of the yoked design I will make some assumption:

Let's say You have two files, participants and comparison. In the participants the cases are unique in the sense that there are not two cases with the same year, age and sex. In the comparison file there are one or many cases matching for each participant case.
Is it true? You want to select randomly one match of many possible for each participant.

In this situation the probably easiest way is to randomly select one comparisoncase for each characteristic combination in the comparison file.

In the comparison file compute a random variable and CharID:
COMPUTE r=uniform(1).
COMPUTE CharID = 10*year + 100*age + gender.
SORT CASES by CharID r.

Now you can select the first case for each group with the same CharId. It is a random selection, based on the value of random variable r.

COMPUTE filtr = 0.
IF $casenum = 1 filtr = 1.
IF $casenum gt 1  and CharID  ne lag(CharId,1) filtr = 1.
SELECT if filtr.

If above assumptions are true, this will leave at least 50 cases in the comparison file, randomly selected for matching with Participant. There might be more cases if some characteristics in the comparison file do not match any participant.

Last step is matching the two files:
MATCH files /table = participant / file = comparison / by CharID.

The syntax is NOT tested.

Best regards
Jindra


> ------------ Původní zpráva ------------
> Od: Tuerk, Elena <[hidden email]>
> Předmět: Re: SPSS syntax for yoked pair
> Datum: 29.5.2008 19:18:25
> ----------------------------------------
> Thanks so much, Jindra.
>
> Can I trouble you with another question? Let's say the goal is to find ALL cases
> that match the participant characteristics (and then randomly select one of the
> matching cases). Is there any way to make the syntax work to find all cases?
>
> -----Original Message-----
> From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Jerabek
> Jindrich
> Sent: Thursday, May 29, 2008 12:55 PM
> To: [hidden email]
> Subject: Re:SPSS syntax for yoked pair
>
> Hello,
>
> it is realy inefficient to look for match case by case.
>
> You could compute an ID based on the participant's characteristic. for example
> :
> COMPUTE CharID = 10*year + 100*age + gender.
> Do it both for participants and comparison group and
> 1) if they are in separate files match them:
> MATCH files /file = participants / file = comparison / by CharId.   or
> 2) If they are in one file - sort the file by CharId plus participant/compare,
> You will get pairs in subsequent cases.
>
> This all will not work properly if you have participants without exact match in
> comparison group or have several participants with the same year and age and
> sex. However in this case neither matching nor your SELECT syntax will work.
>
>
> best regards
> Jindra
>
>
>
>
> > ------------ Původní zpráva ------------
> > Od: Tuerk, Elena <[hidden email]>
> > Předmět: SPSS syntax for yoked pair
> > Datum: 29.5.2008 14:49:22
> > ----------------------------------------
> > Hi list,
> >
> > I'm new to yoked pair matching and have received a brief snippet of
> > syntax that I was hoping to confirm/streamline. I will be matching
> > comparison group cases to criteria based on each individual in the
> > treatment group. I need to do this for about 50 participants.
> >
> > For example, if I matching on the following characteristics that
> > Participant ID
> > 4 has:
> > age = 4
> > gender = 1
> > year = 2006
> >
> > Do I use the following syntax to find a matching case to yoke?
> >
> > SELECT IF
> > age=4,
> > gender=1,
> > year=2006 .
> > EXECUTE .
> >
> > Also, it seems somewhat inefficient to change the syntax for each case
> > that is being matched (e.g., for another case age=3, gender=0, etc.).
> > Is there a way to write it so that it selects based on whatever filter is on?
> >
> > Thanks for your help!
> >
> > =====================
> > To manage your subscription to SPSSX-L, send a message to
> > [hidden email] (not to SPSSX-L), with no body text except
> > the command. To leave the list, send the command SIGNOFF SPSSX-L For a
> > list of commands to manage subscriptions, send the command INFO
> > REFCARD
> >
> >
> >
>
> =====================
> To manage your subscription to SPSSX-L, send a message to
> [hidden email] (not to SPSSX-L), with no body text except the
> command. To leave the list, send the command SIGNOFF SPSSX-L For a list of
> commands to manage subscriptions, send the command INFO REFCARD
>
> =====================
> To manage your subscription to SPSSX-L, send a message to
> [hidden email] (not to SPSSX-L), with no body text except the
> command. To leave the list, send the command
> SIGNOFF SPSSX-L
> For a list of commands to manage subscriptions, send the command
> INFO REFCARD
>
>
>

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: SPSS syntax for yoked pair

Jerabek Jindrich
In reply to this post by Tuerk, Elena
Oops,
thinking again about the merging - I made the assumption that the cases in participant file are unique. It might be easily false, but then the way offered to select matching cases would be completely wrong. Please do NOT use it if you do not have uniqe characteristics in participant files.


Jindra

> ------------ Původní zpráva ------------
> Od: Tuerk, Elena <[hidden email]>
> Předmět: Re: SPSS syntax for yoked pair
> Datum: 29.5.2008 19:18:25
> ----------------------------------------
> Thanks so much, Jindra.
>
> Can I trouble you with another question? Let's say the goal is to find ALL cases
> that match the participant characteristics (and then randomly select one of the
> matching cases). Is there any way to make the syntax work to find all cases?
>
> -----Original Message-----
> From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Jerabek
> Jindrich
> Sent: Thursday, May 29, 2008 12:55 PM
> To: [hidden email]
> Subject: Re:SPSS syntax for yoked pair
>
> Hello,
>
> it is realy inefficient to look for match case by case.
>
> You could compute an ID based on the participant's characteristic. for example
> :
> COMPUTE CharID = 10*year + 100*age + gender.
> Do it both for participants and comparison group and
> 1) if they are in separate files match them:
> MATCH files /file = participants / file = comparison / by CharId.   or
> 2) If they are in one file - sort the file by CharId plus participant/compare,
> You will get pairs in subsequent cases.
>
> This all will not work properly if you have participants without exact match in
> comparison group or have several participants with the same year and age and
> sex. However in this case neither matching nor your SELECT syntax will work.
>
>
> best regards
> Jindra
>
>
>
>
> > ------------ Původní zpráva ------------
> > Od: Tuerk, Elena <[hidden email]>
> > Předmět: SPSS syntax for yoked pair
> > Datum: 29.5.2008 14:49:22
> > ----------------------------------------
> > Hi list,
> >
> > I'm new to yoked pair matching and have received a brief snippet of
> > syntax that I was hoping to confirm/streamline. I will be matching
> > comparison group cases to criteria based on each individual in the
> > treatment group. I need to do this for about 50 participants.
> >
> > For example, if I matching on the following characteristics that
> > Participant ID
> > 4 has:
> > age = 4
> > gender = 1
> > year = 2006
> >
> > Do I use the following syntax to find a matching case to yoke?
> >
> > SELECT IF
> > age=4,
> > gender=1,
> > year=2006 .
> > EXECUTE .
> >
> > Also, it seems somewhat inefficient to change the syntax for each case
> > that is being matched (e.g., for another case age=3, gender=0, etc.).
> > Is there a way to write it so that it selects based on whatever filter is on?
> >
> > Thanks for your help!
> >
> > =====================
> > To manage your subscription to SPSSX-L, send a message to
> > [hidden email] (not to SPSSX-L), with no body text except
> > the command. To leave the list, send the command SIGNOFF SPSSX-L For a
> > list of commands to manage subscriptions, send the command INFO
> > REFCARD
> >
> >
> >
>
> =====================
> To manage your subscription to SPSSX-L, send a message to
> [hidden email] (not to SPSSX-L), with no body text except the
> command. To leave the list, send the command SIGNOFF SPSSX-L For a list of
> commands to manage subscriptions, send the command INFO REFCARD
>
> =====================
> To manage your subscription to SPSSX-L, send a message to
> [hidden email] (not to SPSSX-L), with no body text except the
> command. To leave the list, send the command
> SIGNOFF SPSSX-L
> For a list of commands to manage subscriptions, send the command
> INFO REFCARD
>
>
>

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: SPSS syntax for yoked pair

Richard Ristow
At 04:17 PM 5/29/2008, Jerabek Jindrich wrote:

>I made the assumption that the cases in participant file are unique.
>It might be easily false, but then the way offered to select
>matching cases would be completely wrong.

It should be fixable, though. I'll outline, rather than writing code.

Here, I assume that (a) There are enough controls to match every
participant; (b) If you have two participants with the same
characteristics, you want to assign a matching control to each, both
selected randomly from the set of matching controls.

By the way, there's no need for something like
COMPUTE CharID = 10*year + 100*age + gender.

You can use the three variables 'year', 'age' and 'gender' together
as the key. MATCH FILES and other SPSS commands accept
multiple-variable keys just fine.

1. Sort the participants by year, age and gender. Use any of several
techniques to assign sequential numbers (1, 2, ...) within sets of
participants with the same key variables. (It doesn't matter what
order the participants are in, for this.)

2. Get a table of keys occurring in the participant file:

AGGREGATE
   /OUTFILE=PtcpKeys
   /BREAK  = year age gender
   /NPart 'Number of participants with this key' = NU.

3. Now do your MATCH FILES, like this:

MATCH files /table = PtcpKeys
             / file = comparison
             / by year age gender.

4. Now, with each key value in the Comparison file, you'll know how
many you need to match participants (it's the value of variable
NPart). Randomly select that many, and sequentially number them
within the keys, as in step 2. Call this Controls

5. If you want to keep 'long' organization, then interleave
participants and their controls like this:


ADD FILE
    /FILE=Participant /IN=CASE
    /FILE=Controls
    /BY year age gender SeqnNumb.

(Here, 'SeqnNumb' is the sequential number from step 1. and 4. Both
files must be in order by SeqnNumb within year, age and gender.)

Then, 'CASE' is 1 for participants, 0 for controls; and you should
have a matched control for every participant.

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Case-Control Matching

Peck, Jon
In reply to this post by Jerabek Jindrich
Since case-control matching seems to come up a lot, I have written a general Python function to deal with this.  (I'll continue working on it and make it an extension command for those who don't want to deal with Python code.)

The function takes two datasets as input: one is the set of demanders, that is, the cases that want a match.  The other is the set of suppliers, that is, cases that could provide a match (typically much larger).  It also takes a list of variables to match on and a few optional parameters.  It can match with or without replacement from the supplier dataset.  It can randomize the order of the demander cases before matching, which could be relevant if matching without replacement and you might run out of matching cases for some demander.  It builds a number of casewise tables in memory, but it is smart about minimizing the number of match candidates it keeps from the supplier dataset while giving all appropriate candidates equal probability of selection.  No sorting is required.

From among all the supplier cases that are exact matches for a demander case, it picks one (or m) at random and adds their id values to the demander case.  It can also create a new dataset consisting of exactly those supplier cases that were used in matching, so the actual cases can be merged in easily if desired.

This function takes great advantage of the new Dataset class in SPSS 16, which is required.

I expect to finish and post this to SPSS Developer Central within a few days.

Regards,
Jon Peck

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Jerabek Jindrich
Sent: Thursday, May 29, 2008 10:55 AM
To: [hidden email]
Subject: [SPSSX-L] Re:SPSS syntax for yoked pair

Hello,

it is really inefficient to look for match case by case.

You could compute an ID based on the participant's characteristic. for example :
COMPUTE CharID = 10*year + 100*age + gender.
Do it both for participants and comparison group and
1) if they are in separate files match them:
MATCH files /file = participants / file = comparison / by CharId.   or
2) If they are in one file - sort the file by CharId plus participant/compare, You will get pairs in subsequent cases.

This all will not work properly if you have participants without exact match in comparison group or have several participants with the same year and age and sex. However in this case neither matching nor your SELECT syntax will work.


best regards
Jindra




> ------------ Původní zpráva ------------
> Od: Tuerk, Elena <[hidden email]>
> Předmět: SPSS syntax for yoked pair
> Datum: 29.5.2008 14:49:22
> ----------------------------------------
> Hi list,
>
> I'm new to yoked pair matching and have received a brief snippet of syntax that
> I was hoping to confirm/streamline. I will be matching comparison group cases to
> criteria based on each individual in the treatment group. I need to do this for
> about 50 participants.
>
> For example, if I matching on the following characteristics that Participant ID
> 4 has:
> age = 4
> gender = 1
> year = 2006
>
> Do I use the following syntax to find a matching case to yoke?
>
> SELECT IF
> age=4,
> gender=1,
> year=2006 .
> EXECUTE .
>
> Also, it seems somewhat inefficient to change the syntax for each case that is
> being matched (e.g., for another case age=3, gender=0, etc.). Is there a way to
> write it so that it selects based on whatever filter is on?
>
> Thanks for your help!
>
> =====================
> To manage your subscription to SPSSX-L, send a message to
> [hidden email] (not to SPSSX-L), with no body text except the
> command. To leave the list, send the command
> SIGNOFF SPSSX-L
> For a list of commands to manage subscriptions, send the command
> INFO REFCARD
>
>
>

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD