Calculating the difference between cases

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

Calculating the difference between cases

Veena Nambiar

I have a data file that contains a variable id and score. Id is coded “0” for the target subject and “1” for subjects within the targets group. I would like to create a separate variable diff that takes the difference between the target subject’s score and each of the other subjects in the group. Here is an example below. Is there a way to do this in SPSS?

 

 

id

score

diff

1

82

0

1

75

7

1

82

0

1

61

21

1

66

16

1

92

-10

1

23

59

1

10

72

1

77

5

0

82

              .

1

43

39

1

31

51

1

37

45

1

12

70

1

55

27

1

95

-13

 

 

Veena Nambiar

 

Reply | Threaded
Open this post in threaded view
|

Re: Calculating the difference between cases

David Marso
Administrator
Very difficult to imagine why you want to do this and/or what your full data actually look like since there are multiple subjects.
For the data you present here is a very simple solution.
OTOH you are obviously *NOT* providing adequate information to generate a general solution so this effort may prove to be utterly useless unless you rethink the more general issue (Cartesian product) and redesign your data structure.
data list free / gp score.
begin data
1 82 1 75 1 82 1 61 1 66 1 92 1 23 1 10 1 77 0 82 1 43 1 31 1 37 1 12 1 55 1 95
end data.
COMPUTE @ORDER@=$CASENUM.
SORT CASES BY GP.
DO IF $CASENUM=1.
+  COMPUTE #TARG=score.
ELSE.
+  COMPUTE DIFF=#TARG-SCORE.
END IF.
SORT CASES BY @ORDER@.
LIST.
Veena Nambiar wrote
I have a data file that contains a variable id and score. Id is coded "0" for the target subject and "1" for subjects within the targets group. I would like to create a separate variable diff that takes the difference between the target subject's score and each of the other subjects in the group. Here is an example below. Is there a way to do this in SPSS?


id

score

diff

1

82

0

1

75

7

1

82

0

1

61

21

1

66

16

1

92

-10

1

23

59

1

10

72

1

77

5

0

82

              .

1

43

39

1

31

51

1

37

45

1

12

70

1

55

27

1

95

-13



Veena Nambiar
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: Calculating the difference between cases

David Marso
Administrator
Ponder the following while you are at this:
--
DATA LIST FREE / GP SCORE.
BEGIN DATA
1 20 1 40 1 30 1 65 1 23
2 10 2 15 2 30 2 40
END DATA.

CASES TO VARS /ID=GP.
COMPUTE @=$SYSMIS.
COUNT #MAX=score.1 TO @ (LO THRU HI, SYSMIS).
VECTOR DATA=score.1 TO @ .
LOOP SUBID1=1 TO #MAX.
+ LOOP SUBID2=1 TO #MAX.
+   DO IF NOT(SUBID1 EQ SUBID2) AND NOT MISSING (DATA(SUBID1)) AND NOT MISSING (DATA(SUBID2)).
+     COMPUTE SCORE_1=DATA(SUBID1).
+     COMPUTE SCORE_2=DATA(SUBID2).
+     COMPUTE DIFF= SCORE_2-SCORE_1.
+     XSAVE OUTFILE "TEMP.SAV"
           / KEEP GP SUBID1 SUBID2 SCORE_2 SCORE_1 DIFF.
+   END IF.
+ END LOOP.
END LOOP.
EXECUTE.
GET FILE "TEMP.SAV".
LIST.
David Marso wrote
Very difficult to imagine why you want to do this and/or what your full data actually look like since there are multiple subjects.
For the data you present here is a very simple solution.
OTOH you are obviously *NOT* providing adequate information to generate a general solution so this effort may prove to be utterly useless unless you rethink the more general issue (Cartesian product) and redesign your data structure.
data list free / gp score.
begin data
1 82 1 75 1 82 1 61 1 66 1 92 1 23 1 10 1 77 0 82 1 43 1 31 1 37 1 12 1 55 1 95
end data.
COMPUTE @ORDER@=$CASENUM.
SORT CASES BY GP.
DO IF $CASENUM=1.
+  COMPUTE #TARG=score.
ELSE.
+  COMPUTE DIFF=#TARG-SCORE.
END IF.
SORT CASES BY @ORDER@.
LIST.
Veena Nambiar wrote
I have a data file that contains a variable id and score. Id is coded "0" for the target subject and "1" for subjects within the targets group. I would like to create a separate variable diff that takes the difference between the target subject's score and each of the other subjects in the group. Here is an example below. Is there a way to do this in SPSS?


id

score

diff

1

82

0

1

75

7

1

82

0

1

61

21

1

66

16

1

92

-10

1

23

59

1

10

72

1

77

5

0

82

              .

1

43

39

1

31

51

1

37

45

1

12

70

1

55

27

1

95

-13



Veena Nambiar
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: Calculating the difference between cases

Bruce Weaver
Administrator
In reply to this post by David Marso
Here's another way without the sorting (although it does leave an extra variable in the file--G0score, which has the Group 0 score written on every case).  It could always be deleted with a DELETE VARIABLES command.

data list free / gp score.
begin data
1 82 1 75 1 82 1 61 1 66 1 92 1 23 1 10 1 77 0 82 1 43 1 31 1 37 1 12 1 55 1 95
end data.

IF (GP EQ 0) G0score = score.
AGGREGATE
  /OUTFILE=* MODE=ADDVARIABLES OVERWRITE=YES
  /G0score=FIRST(G0score).
IF (GP EQ 1) DIFF = G0score - score.
LIST.


David Marso wrote
Very difficult to imagine why you want to do this and/or what your full data actually look like since there are multiple subjects.
For the data you present here is a very simple solution.
OTOH you are obviously *NOT* providing adequate information to generate a general solution so this effort may prove to be utterly useless unless you rethink the more general issue (Cartesian product) and redesign your data structure.
data list free / gp score.
begin data
1 82 1 75 1 82 1 61 1 66 1 92 1 23 1 10 1 77 0 82 1 43 1 31 1 37 1 12 1 55 1 95
end data.
COMPUTE @ORDER@=$CASENUM.
SORT CASES BY GP.
DO IF $CASENUM=1.
+  COMPUTE #TARG=score.
ELSE.
+  COMPUTE DIFF=#TARG-SCORE.
END IF.
SORT CASES BY @ORDER@.
LIST.
Veena Nambiar wrote
I have a data file that contains a variable id and score. Id is coded "0" for the target subject and "1" for subjects within the targets group. I would like to create a separate variable diff that takes the difference between the target subject's score and each of the other subjects in the group. Here is an example below. Is there a way to do this in SPSS?


id

score

diff

1

82

0

1

75

7

1

82

0

1

61

21

1

66

16

1

92

-10

1

23

59

1

10

72

1

77

5

0

82

              .

1

43

39

1

31

51

1

37

45

1

12

70

1

55

27

1

95

-13



Veena Nambiar
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

PLEASE NOTE THE FOLLOWING: 
1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/).
Reply | Threaded
Open this post in threaded view
|

Re: Calculating the difference between cases

Veena Nambiar
In reply to this post by David Marso
Thanks for the response David. I needed to compute these differences for use in another set of calculations that we do @ the state for reporting.

With the help of another SPSS user, I think I have a solution. Here is a step by step of the solution.

I have a data file with ids and scores. The ids and scores for group 1 are in id1 and score1, group 2 are in id2 and score2, and so on. The zero in the id field represents a target case and the 1 represents cases in the target's group. My file structure is as follows:

row id1 score1  id2 score2
1      1        92      1       41
2      0        56      1       75
3      1         45             0       22

1. Restructure the data file so that ids and scores are stacked on top of each other. Create a group id to differentiate between groups.

varstocases
*create a variable caseid that stacks data from id1 to id1000.
/make caseid from id1 to id1000
*create a variable score that stacks data from score1 to score1000.
/make score from score1 score1000
*create a variable that identifies the group id and score belong to.
  /INDEX=groupid (1000)
*keep other important variables from data file.
  /KEEP=y
*drop null values.
  /NULL=DROP.

This is the resulting file:
groupid  id   score
1                1      92
1                0      56
1                1      45
2                1      41
2                1      75
2                0      22

2. Create a variable tscore, which contains the score of the target cases only.

*sort cases by group id, caseid, and score so that all cases in the group are together and the target subject (coded 0 under id) is the first case in each group.
sort cases by groupid(a) caseid(a).

The file looks like this:

groupid  id   score
1               0      56
1               1      92
1               1      45
2               0      22
2               1      75
2               1      41

*select only target subjects identified as 0 under caseid.
DO IF (caseid=0).
*compute a new variable with the scores of target cases.
COMPUTE tscore=score.
*select cases in each target's group, identified as 1 under caseid.
ELSE IF (caseid=1).
*compute the lag of the target score, which populates the variable tscore with the target's score for all cases in the target's group.
COMPUTE tscore = LAG(tscore).
END IF.
execute.

The above syntax yields this:
groupid  id   score      tscore
1        0              56              56
1        1              92              56
1        1              45              56
2        0             22       22
2        1             75               22
2        1             41               22

3. Calculate the difference between the target's score and the score of each person in the group.
*select only those cases in each target's group, coded 1 under caseid.
do if caseid=1.
*compute the difference between the target's score and the score of each case in the target's group.
compute diff=tscore-score.
end if.
execute.

The final file looks like this:
groupid  id   score      tscore      diff
1        0              56              56         .
1        1              92              56         -36
1        1              45              56          11
2        0             22       22          .
2        1             75               22         -53
2        1             41               22        -19


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of David Marso
Sent: Tuesday, April 03, 2012 5:38 AM
To: [hidden email]
Subject: Re: Calculating the difference between cases

Very difficult to imagine why you want to do this and/or what your full data actually look like since there are multiple subjects.
For the data you present here is a very simple solution.
OTOH you are obviously *NOT* providing adequate information to generate a general solution so this effort may prove to be utterly useless unless you rethink the more general issue (Cartesian product) and redesign your data structure.
data list free / gp score.
begin data
1 82 1 75 1 82 1 61 1 66 1 92 1 23 1 10 1 77 0 82 1 43 1 31 1 37 1 12 1 55 1
95
end data.
COMPUTE @ORDER@=$CASENUM.
SORT CASES BY GP.
DO IF $CASENUM=1.
+  COMPUTE #TARG=score.
ELSE.
+  COMPUTE DIFF=#TARG-SCORE.
END IF.
SORT CASES BY @ORDER@.
LIST.

Veena Nambiar wrote

>
> I have a data file that contains a variable id and score. Id is coded "0"
> for the target subject and "1" for subjects within the targets group.
> I would like to create a separate variable diff that takes the
> difference between the target subject's score and each of the other
> subjects in the group. Here is an example below. Is there a way to do this in SPSS?
>
>
> id
>
> score
>
> diff
>
> 1
>
> 82
>
> 0
>
> 1
>
> 75
>
> 7
>
> 1
>
> 82
>
> 0
>
> 1
>
> 61
>
> 21
>
> 1
>
> 66
>
> 16
>
> 1
>
> 92
>
> -10
>
> 1
>
> 23
>
> 59
>
> 1
>
> 10
>
> 72
>
> 1
>
> 77
>
> 5
>
> 0
>
> 82
>
>               .
>
> 1
>
> 43
>
> 39
>
> 1
>
> 31
>
> 51
>
> 1
>
> 37
>
> 45
>
> 1
>
> 12
>
> 70
>
> 1
>
> 55
>
> 27
>
> 1
>
> 95
>
> -13
>
>
>
> Veena Nambiar
>


--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Calculating-the-difference-between-cases-tp5601947p5614983.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
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: Calculating the difference between cases

Bruce Weaver
Administrator
I think this gets you to the same result, but again, without the sorting.

* Read in sample data.
data list list / row id1 score1  id2 score2 .
begin data
1      1        92      1       41
2      0        56      1       75
3      1         45     0       22
end data.

* Given the order of the variables, "id1 TO id2"
* and "score1 TO score2" will not work--the variables
* must be listed individually. Perhaps the variables
* are ordered differently in the actual file with
* 1000 variables.

varstocases
 /make caseid from id1 id2
 /make score from score1 score2
 /INDEX=groupid (2)
 /NULL=DROP
.

IF (caseid EQ 0) tscore = score.
AGGREGATE
  /OUTFILE=* MODE=ADDVARIABLES OVERWRITE=YES
  /BREAK = groupid
  /tscore=FIRST(tscore).
IF (caseid EQ 1) DIFF = tscore - score.
LIST.

OUTPUT:
     row groupid   caseid    score   tscore     DIFF
 
    1.00      1      1.00    92.00    56.00   -36.00
    1.00      2      1.00    41.00    22.00   -19.00
    2.00      1       .00    56.00    56.00      .
    2.00      2      1.00    75.00    22.00   -53.00
    3.00      1      1.00    45.00    56.00    11.00
    3.00      2       .00    22.00    22.00      .
 
Number of cases read:  6    Number of cases listed:  6


Veena Nambiar wrote
Thanks for the response David. I needed to compute these differences for use in another set of calculations that we do @ the state for reporting.

With the help of another SPSS user, I think I have a solution. Here is a step by step of the solution.

I have a data file with ids and scores. The ids and scores for group 1 are in id1 and score1, group 2 are in id2 and score2, and so on. The zero in the id field represents a target case and the 1 represents cases in the target's group. My file structure is as follows:

row id1 score1  id2 score2
1      1        92      1       41
2      0        56      1       75
3      1         45             0       22

1. Restructure the data file so that ids and scores are stacked on top of each other. Create a group id to differentiate between groups.

varstocases
*create a variable caseid that stacks data from id1 to id1000.
/make caseid from id1 to id1000
*create a variable score that stacks data from score1 to score1000.
/make score from score1 score1000
*create a variable that identifies the group id and score belong to.
  /INDEX=groupid (1000)
*keep other important variables from data file.
  /KEEP=y
*drop null values.
  /NULL=DROP.

This is the resulting file:
groupid  id   score
1                1      92
1                0      56
1                1      45
2                1      41
2                1      75
2                0      22

2. Create a variable tscore, which contains the score of the target cases only.

*sort cases by group id, caseid, and score so that all cases in the group are together and the target subject (coded 0 under id) is the first case in each group.
sort cases by groupid(a) caseid(a).

The file looks like this:

groupid  id   score
1               0      56
1               1      92
1               1      45
2               0      22
2               1      75
2               1      41

*select only target subjects identified as 0 under caseid.
DO IF (caseid=0).
*compute a new variable with the scores of target cases.
COMPUTE tscore=score.
*select cases in each target's group, identified as 1 under caseid.
ELSE IF (caseid=1).
*compute the lag of the target score, which populates the variable tscore with the target's score for all cases in the target's group.
COMPUTE tscore = LAG(tscore).
END IF.
execute.

The above syntax yields this:
groupid  id   score      tscore
1        0              56              56
1        1              92              56
1        1              45              56
2        0             22       22
2        1             75               22
2        1             41               22

3. Calculate the difference between the target's score and the score of each person in the group.
*select only those cases in each target's group, coded 1 under caseid.
do if caseid=1.
*compute the difference between the target's score and the score of each case in the target's group.
compute diff=tscore-score.
end if.
execute.

The final file looks like this:
groupid  id   score      tscore      diff
1        0              56              56         .
1        1              92              56         -36
1        1              45              56          11
2        0             22       22          .
2        1             75               22         -53
2        1             41               22        -19


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of David Marso
Sent: Tuesday, April 03, 2012 5:38 AM
To: [hidden email]
Subject: Re: Calculating the difference between cases

Very difficult to imagine why you want to do this and/or what your full data actually look like since there are multiple subjects.
For the data you present here is a very simple solution.
OTOH you are obviously *NOT* providing adequate information to generate a general solution so this effort may prove to be utterly useless unless you rethink the more general issue (Cartesian product) and redesign your data structure.
data list free / gp score.
begin data
1 82 1 75 1 82 1 61 1 66 1 92 1 23 1 10 1 77 0 82 1 43 1 31 1 37 1 12 1 55 1
95
end data.
COMPUTE @ORDER@=$CASENUM.
SORT CASES BY GP.
DO IF $CASENUM=1.
+  COMPUTE #TARG=score.
ELSE.
+  COMPUTE DIFF=#TARG-SCORE.
END IF.
SORT CASES BY @ORDER@.
LIST.

Veena Nambiar wrote
>
> I have a data file that contains a variable id and score. Id is coded "0"
> for the target subject and "1" for subjects within the targets group.
> I would like to create a separate variable diff that takes the
> difference between the target subject's score and each of the other
> subjects in the group. Here is an example below. Is there a way to do this in SPSS?
>
>
> id
>
> score
>
> diff
>
> 1
>
> 82
>
> 0
>
> 1
>
> 75
>
> 7
>
> 1
>
> 82
>
> 0
>
> 1
>
> 61
>
> 21
>
> 1
>
> 66
>
> 16
>
> 1
>
> 92
>
> -10
>
> 1
>
> 23
>
> 59
>
> 1
>
> 10
>
> 72
>
> 1
>
> 77
>
> 5
>
> 0
>
> 82
>
>               .
>
> 1
>
> 43
>
> 39
>
> 1
>
> 31
>
> 51
>
> 1
>
> 37
>
> 45
>
> 1
>
> 12
>
> 70
>
> 1
>
> 55
>
> 27
>
> 1
>
> 95
>
> -13
>
>
>
> Veena Nambiar
>


--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Calculating-the-difference-between-cases-tp5601947p5614983.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
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
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

PLEASE NOTE THE FOLLOWING: 
1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/).
Reply | Threaded
Open this post in threaded view
|

Re: Calculating the difference between cases

Veena Nambiar
Yes, you are correct Bruce - the syntax wouldn't work given the order of the sample - my actual file has the variables in the appropriate order so I can use "TO".

AGGREGATE works perfectly - a much cleaner solution than what I was using. I changed my syntax to use AGGREGATE.
Veena

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Bruce Weaver
Sent: Tuesday, April 03, 2012 11:43 AM
To: [hidden email]
Subject: Re: Calculating the difference between cases

I think this gets you to the same result, but again, without the sorting.

* Read in sample data.
data list list / row id1 score1  id2 score2 .
begin data
1      1        92      1       41
2      0        56      1       75
3      1         45     0       22
end data.

* Given the order of the variables, "id1 TO id2"
* and "score1 TO score2" will not work--the variables
* must be listed individually. Perhaps the variables
* are ordered differently in the actual file with
* 1000 variables.

varstocases
 /make caseid from id1 id2
 /make score from score1 score2
 /INDEX=groupid (2)
 /NULL=DROP
.

IF (caseid EQ 0) tscore = score.
AGGREGATE
  /OUTFILE=* MODE=ADDVARIABLES OVERWRITE=YES
  /BREAK = groupid
  /tscore=FIRST(tscore).
IF (caseid EQ 1) DIFF = tscore - score.
LIST.

OUTPUT:
     row groupid   caseid    score   tscore     DIFF

    1.00      1      1.00    92.00    56.00   -36.00
    1.00      2      1.00    41.00    22.00   -19.00
    2.00      1       .00    56.00    56.00      .
    2.00      2      1.00    75.00    22.00   -53.00
    3.00      1      1.00    45.00    56.00    11.00
    3.00      2       .00    22.00    22.00      .

Number of cases read:  6    Number of cases listed:  6



Veena Nambiar wrote

>
> Thanks for the response David. I needed to compute these differences
> for use in another set of calculations that we do @ the state for reporting.
>
> With the help of another SPSS user, I think I have a solution. Here is
> a step by step of the solution.
>
> I have a data file with ids and scores. The ids and scores for group 1
> are in id1 and score1, group 2 are in id2 and score2, and so on. The
> zero in the id field represents a target case and the 1 represents
> cases in the target's group. My file structure is as follows:
>
> row id1 score1  id2 score2
> 1      1        92      1       41
> 2      0        56      1       75
> 3      1         45             0       22
>
> 1. Restructure the data file so that ids and scores are stacked on top
> of each other. Create a group id to differentiate between groups.
>
> varstocases
> *create a variable caseid that stacks data from id1 to id1000.
> /make caseid from id1 to id1000
> *create a variable score that stacks data from score1 to score1000.
> /make score from score1 score1000
> *create a variable that identifies the group id and score belong to.
>   /INDEX=groupid (1000)
> *keep other important variables from data file.
>   /KEEP=y
> *drop null values.
>   /NULL=DROP.
>
> This is the resulting file:
> groupid  id   score
> 1                1      92
> 1                0      56
> 1                1      45
> 2                1      41
> 2                1      75
> 2                0      22
>
> 2. Create a variable tscore, which contains the score of the target
> cases only.
>
> *sort cases by group id, caseid, and score so that all cases in the
> group are together and the target subject (coded 0 under id) is the
> first case in each group.
> sort cases by groupid(a) caseid(a).
>
> The file looks like this:
>
> groupid  id   score
> 1               0      56
> 1               1      92
> 1               1      45
> 2               0      22
> 2               1      75
> 2               1      41
>
> *select only target subjects identified as 0 under caseid.
> DO IF (caseid=0).
> *compute a new variable with the scores of target cases.
> COMPUTE tscore=score.
> *select cases in each target's group, identified as 1 under caseid.
> ELSE IF (caseid=1).
> *compute the lag of the target score, which populates the variable
> tscore with the target's score for all cases in the target's group.
> COMPUTE tscore = LAG(tscore).
> END IF.
> execute.
>
> The above syntax yields this:
> groupid  id   score      tscore
> 1        0              56              56
> 1        1              92              56
> 1        1              45              56
> 2        0             22       22
> 2        1             75               22
> 2        1             41               22
>
> 3. Calculate the difference between the target's score and the score
> of each person in the group.
> *select only those cases in each target's group, coded 1 under caseid.
> do if caseid=1.
> *compute the difference between the target's score and the score of
> each case in the target's group.
> compute diff=tscore-score.
> end if.
> execute.
>
> The final file looks like this:
> groupid  id   score      tscore      diff
> 1        0              56              56         .
> 1        1              92              56         -36
> 1        1              45              56          11
> 2        0             22       22          .
> 2        1             75               22         -53
> 2        1             41               22        -19
>
>
> -----Original Message-----
> From: SPSSX(r) Discussion [mailto:SPSSX-L@.UGA] On Behalf Of David
> Marso
> Sent: Tuesday, April 03, 2012 5:38 AM
> To: SPSSX-L@.UGA
> Subject: Re: Calculating the difference between cases
>
> Very difficult to imagine why you want to do this and/or what your
> full data actually look like since there are multiple subjects.
> For the data you present here is a very simple solution.
> OTOH you are obviously *NOT* providing adequate information to
> generate a general solution so this effort may prove to be utterly
> useless unless you rethink the more general issue (Cartesian product)
> and redesign your data structure.
> data list free / gp score.
> begin data
> 1 82 1 75 1 82 1 61 1 66 1 92 1 23 1 10 1 77 0 82 1 43 1 31 1 37 1 12
> 1 55
> 1
> 95
> end data.
> COMPUTE @ORDER@=$CASENUM.
> SORT CASES BY GP.
> DO IF $CASENUM=1.
> +  COMPUTE #TARG=score.
> ELSE.
> +  COMPUTE DIFF=#TARG-SCORE.
> END IF.
> SORT CASES BY @ORDER@.
> LIST.
>
> Veena Nambiar wrote
>>
>> I have a data file that contains a variable id and score. Id is coded "0"
>> for the target subject and "1" for subjects within the targets group.
>> I would like to create a separate variable diff that takes the
>> difference between the target subject's score and each of the other
>> subjects in the group. Here is an example below. Is there a way to do
>> this in SPSS?
>>
>>
>> id
>>
>> score
>>
>> diff
>>
>> 1
>>
>> 82
>>
>> 0
>>
>> 1
>>
>> 75
>>
>> 7
>>
>> 1
>>
>> 82
>>
>> 0
>>
>> 1
>>
>> 61
>>
>> 21
>>
>> 1
>>
>> 66
>>
>> 16
>>
>> 1
>>
>> 92
>>
>> -10
>>
>> 1
>>
>> 23
>>
>> 59
>>
>> 1
>>
>> 10
>>
>> 72
>>
>> 1
>>
>> 77
>>
>> 5
>>
>> 0
>>
>> 82
>>
>>               .
>>
>> 1
>>
>> 43
>>
>> 39
>>
>> 1
>>
>> 31
>>
>> 51
>>
>> 1
>>
>> 37
>>
>> 45
>>
>> 1
>>
>> 12
>>
>> 70
>>
>> 1
>>
>> 55
>>
>> 27
>>
>> 1
>>
>> 95
>>
>> -13
>>
>>
>>
>> Veena Nambiar
>>
>
>
> --
> View this message in context:
> http://spssx-discussion.1045642.n5.nabble.com/Calculating-the-differen
> ce-between-cases-tp5601947p5614983.html
> Sent from the SPSSX Discussion mailing list archive at Nabble.com.
>
> =====================
> To manage your subscription to SPSSX-L, send a message to
> LISTSERV@.UGA (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
> LISTSERV@.UGA (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
>


-----
--
Bruce Weaver
[hidden email]
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.

--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Calculating-the-difference-between-cases-tp5601947p5616079.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
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