The DHS Program User Forum
Discussions regarding The DHS Program data and results
Home » Data » Merging data files » SPSS - Merging Household variables with Individual Women's dataset
SPSS - Merging Household variables with Individual Women's dataset [message #2404] Fri, 13 June 2014 05:02 Go to next message
aligazan
Messages: 24
Registered: June 2014
Location: UK
Member
Hello,

I do realise that there have already been lots of posts on this subject. I have read them all, but I am still struggling to understand exactly how to do this on SPSS.

I want to add variables from the HH dataset into the Women's dataset (for Mali 2006). The particular variables I am interested in are to do with the relationships of the household members, and I would ultimately like to know which relatives each woman in the individual dataset, is living with (e.g. no other adult, living with husband, with co-wife, with parent, with parent-in-law, etc.).

This relationship is found from the variables HV101$01 etc. on the HH dataset.

I have seen the code below, but as I am relatively new to SPSS I have been unable to work out how to adapt this for the objective that I am trying to achieve.

I would really appreciate any help with this. THANKS!

Below is an example syntax for merging the HIV Test data with the Women's data in SPSS.

GET FILE='C:\DATAUSER\ZMAR51FL.SAV'.
SORT CASES BY
HIVCLUST (A) HIVNUMB (A) HIVLINE (A).
SAVE OUTFILE='C:\DATAUSER\HIV.sav'
/COMPRESSED.

GET FILE='C:\DATAUSER\ZMIR51FL.SAV'.
SORT CASES BY
V001 (A) V002 (A) V003 (A) .
SAVE OUTFILE='C:\DATAUSER\WOMEN.sav'
/RENAME(V001 V002 V003=
HIVCLUST HIVNUMB HIVLINE)
/COMPRESSED.

GET FILE='C:\DATAUSER\WOMEN.sav'.
MATCH FILES /FILE=*
/TABLE='C:\DATAUSER\HIV.sav'
/BY HIVCLUST HIVNUMB HIVLINE.
EXECUTE.
SAVE OUTFILE='C:\DATAUSER\ZMAR_IR.SAV'
/COMPRESSED.
Re: SPSS - Merging Household variables with Individual Women's dataset [message #2405 is a reply to message #2404] Fri, 13 June 2014 09:14 Go to previous messageGo to next message
Bridgette-DHS is currently offline  Bridgette-DHS
Messages: 3035
Registered: February 2013
Senior Member
Following is an example code:

get file = 'ETIR61FL.SAV'.
STRING HHID (A12).
COMPUTE HHID = SUBSTR(CASEID,1,12).
VARIABLE LABELS HHID 'Household ID' .
EXECUTE .
MATCH FILES /FILE=*
/TABLE='ETHR61FL.SAV'
/BY hhid.
EXECUTE.
SAVE OUTFILE='HR_IR.SAV'
/COMPRESSED.

I hope this helps.

Bridgette-DHS

Re: SPSS - Merging Household variables with Individual Women's dataset [message #2457 is a reply to message #2405] Fri, 20 June 2014 06:42 Go to previous messageGo to next message
aligazan
Messages: 24
Registered: June 2014
Location: UK
Member
Dear Bridgette,

Thanks so much for your reply. I have done as you suggested but I get the message shown below. Does this mean there is a correction needed to the syntax?

Thanks again so much for your help.

Janet



Variable(s) incorrectly used in 'BY'

------Input1------ ------Input2------
Result Type Variable name Type Variable name

HHID s12 HHID s36 HHID

Codes: num = numeric; sn = string of length n

>Error # 5126
>The BY variable list is invalid. All the variables on the list must exist on
>all the input files, and each variable must be of the same type (numeric, or
>strings of the same length) on all the input files.
>Execution of this command stops.


Variable(s) with conflicting type:

-------Input1------- -------Input2-------
Result Type Variable name Type Variable name

HHID s12 HHID s36 HHID

Codes: num = numeric; sn = string of length n

>Error # 5127
>Mismatched variable types on the input files.

>Note # 5145
>The working file has been restored, and subsequent commands may access the
>working file.
EXECUTE.
SAVE OUTFILE='C:\Users\Janet\Documents\0 MPhil\DHS\Mali datasets\MLIR52sv\MLhR_iR.SAV'
/COMPRESSED.

Re: SPSS - Merging Household variables with Individual Women's dataset [message #2458 is a reply to message #2457] Fri, 20 June 2014 06:47 Go to previous messageGo to next message
aligazan
Messages: 24
Registered: June 2014
Location: UK
Member
Bridgette

PS - the only result of using the previous syntax was one extra variable within the IR file called HHID, but none of the HHID variables from the HR file had been copied into the IR file.

Thanks again
Re: SPSS - Merging Household variables with Individual Women's dataset [message #2464 is a reply to message #2458] Mon, 23 June 2014 13:43 Go to previous message
Bridgette-DHS is currently offline  Bridgette-DHS
Messages: 3035
Registered: February 2013
Senior Member
Where are you getting the variables: "s12" and "s36" from (in your syntax)?

The syntax we posted seems perfectly fine, and all you have to do is modify the file names and the path for the file location. See modified syntax below:

get file = 'c:\testing\MLIR52FL.SAV'.
STRING HHID (A12).
COMPUTE HHID = SUBSTR(CASEID,1,12).
VARIABLE LABELS HHID 'Household ID' .
EXECUTE .
MATCH FILES /FILE=*
/TABLE='c:\testing\MLHR52FL.SAV'
/BY hhid.
EXECUTE.
SAVE OUTFILE='c:\testing\HR_IR.SAV'
/COMPRESSED.

[Updated on: Thu, 25 June 2015 13:38]

Report message to a moderator

Previous Topic: Merge HIV and Couples
Next Topic: mv001, mv002 and mv034_1 do not uniquely identify observations
Goto Forum:
  


Current Time: Sat Apr 20 00:53:35 Coordinated Universal Time 2024