Adding/matching

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

Adding/matching

Esther Fujiwara
Hi,
I am searching for a solution to a relatvely basic problem: I need to
combine two datasets, one that contains all possible responses (as cases),
the other one contains individual responses (also as cases).
i.e.,
File 1
varx
1
2
3
4
5
6
7
...
192

File 2
vary
2
5
7
etc.

My new file should contain both variables, but matched onto each other:

File combined
varx   varz
1      0
2      2
3      0
4      0
5      5
6      0
7      7

varz in the new dataset can also be set to missing for all responses that
were not given (i.e., 1,3,4,6) and to 1 for existing responses (i.e.,2,5,7)

Neither the ADD MATCH or UPDATE functions seem to be doing what I need. Any
help would be greatly appreciated!

Esther

=====================
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: Adding/matching

Zdaniuk, Bozena-2
somebody will probably come up with some impressive and elegant macro for this but i will offer my 'low tech' solution anyway :)
1. create a new variable 'var1' in file 2 with constant values using e.g., a statement
COMPUTE VAR1=1.
EXE.
2. rename vary in file 2 to varx.
3. merge var1 from file 2 into file 1 using varx as id variable. Result: var1 will have sysmis values for cases with varx values in file 1 but no such values for vary in file 2.
4. create varz variable in the new file:
COMPUTE varz=varx.
if (sysmis(var1)) varz=0.
exe.

Bozena

________________________________________
From: SPSSX(r) Discussion [[hidden email]] On Behalf Of Esther Fujiwara [[hidden email]]
Sent: Thursday, October 02, 2008 2:00 PM
To: [hidden email]
Subject: Adding/matching

Hi,
I am searching for a solution to a relatvely basic problem: I need to
combine two datasets, one that contains all possible responses (as cases),
the other one contains individual responses (also as cases).
i.e.,
File 1
varx
1
2
3
4
5
6
7
...
192

File 2
vary
2
5
7
etc.

My new file should contain both variables, but matched onto each other:

File combined
varx   varz
1      0
2      2
3      0
4      0
5      5
6      0
7      7

varz in the new dataset can also be set to missing for all responses that
were not given (i.e., 1,3,4,6) and to 1 for existing responses (i.e.,2,5,7)

Neither the ADD MATCH or UPDATE functions seem to be doing what I need. Any
help would be greatly appreciated!

Esther

=====================
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: Adding/matching

Esther Fujiwara
In reply to this post by Esther Fujiwara
Thank you very much! The same has just been suggested to me and it works
beautifully.

I post their solution here (for more details):

If there is no repetition in Vary, you can do this:
- In File 2, rename VarY to VarX, or if you want to preserve the original
variable, do:

COMPUTE VarX=VarY.
EXECUTE.

Run the following syntax (supposing your directory is C:\Temp, and SPSS 15
or above):

GET FILE='C:\Temp\File 1.sav'.
DATASET NAME file1.
GET FILE='C:\Temp\File 2.sav'.
DATASET NAME file2 WINDOW=FRONT.
COMPUTE Answered=1.
EXECUTE.
SORT CASES BY VarX(A).
SAVE OUTFILE='C:\Temp\File 2.sav'
  /COMPRESSED.
DATASET ACTIVATE file1.
SORT CASES BY VarX(A).
SAVE OUTFILE='C:\Temp\File 1.sav'
  /COMPRESSED.
MATCH FILES /FILE=*
  /TABLE='file2'
  /BY  VarX.
EXECUTE.
SAVE OUTFILE='C:\Temp\File 1.sav'
  /COMPRESSED.

It will create a variable 1 for case match, miss for others.

If you need the value of question instead 1's, try:
COMPUTE Answered1 = VarX*Answered.
EXECUTE.
or replace, in line 5,
COMPUTE Answered=1.
for
COMPUTE Answered=VarX.

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