Matching Files
Two sample programs (Examples 1 and 2) are provided below in SAS and SPSS respectively for matching the household and responding person files together. Example 3 provides a STATA program for matching the household, responding person and enumerated person files together.
Example 1: SAS program to match wave 1 household and responding person files
|
/* ************************************************************* */
/* Created by: Simon Freidin (Updated by: Nicole Watson)*/
/* ************************************************************* */
libname w1 'e:\release6.0\a60c';
data w1p;
set w1.rperson_a60c;
data w1h;
set w1.household_a60c (keep=ahhrhid ahifefn ahifefp ahifdip ahifdin);
proc sort data = w1p; by ahhrhid;
proc sort data = w1h; by ahhrhid;
data w1p;
merge w1p w1h;
by ahhrhid;
|
Example 2: SPSS program to match wave 1 household and responding person files
|
/* ************************************************************* */
/* Created by: Simon Freidin (Updated by: Nicole Watson) */
/* ************************************************************* */
file handle w1p /name='e:\release4.0\a60c\Rperson a60c.sav'.
file handle w1h /name='e:\release6.0\a60c\Household a60c.sav'.
file handle w1psort /name='e:\release6.0\a60c\Rperson sorted a60c.sav'.
file handle w1hsort /name='e:\release6.0\a60c\Household sorted a60c.sav'.
get file=w1h / keep= ahhrhid ahifefn ahifefp ahifdip ahifdin.
sort cases by ahhrhid.
save outfile=w1hsort.
get file=w1p.
sort cases by ahhrhid.
save outfile=w1psort.
match files file=w1psort / table=w1hsort / by ahhrhid.
exe.
|
Example 3: Stata program to match wave 1 household, enumerated and responding person files
|
/* ************************************************************* */
/* Created by: Alison Goode (Updated by: Nicole Watson) */
/* ************************************************************* */
*Enumerated Person File/
use "C:\eperson a60c.dta",clear
sort ahhrpid
save "C:\eperson_2001.dta", replace
clear
*Responding Person File
use "C:\rperson a60c.dta",clear
sort ahhrpid
save "C:\rperson_2001.dta", replace
clear
*Household File
use "C:\household a60c.dta",clear
sort ahhrhid
save" C:\household_2001.dta", replace
clear
/*1: merge enumerated and responding person files*/
use "C:\eperson_2001.dta",clear
merge ahhrpid using "C:\rperson_2001.dta"
drop _merge
sort ahhrhid
/*2: merge new file with household file*/
merge ahhrhid using "C:\household_2001.dta"
drop _merge
sort xwaveid
/*3: now save cross-section of combined files*/
save "C:\Wave1.dta", replace
erase "C:\eperson_2001.dta"
erase "C:\rperson_2001.dta"
erase "C:\household_2001.dta"
clear
|
Matching Partner Information to Files
Some users may want to include variables for a respondent's partner in their analyses. The following sample programs in SAS, SPSS and STATA (Examples 4, 5 and 6 respectively) show how to utilise the partner's cross-wave identifier _hhpxid to add partner variables onto the responding person file.
Example 4: SAS program to add partner variables
|
/* ************************************************************* */
/* Created by: Clinton Hayes (Updated by: Nicole Watson) */
/* ************************************************************* */
* Merge partner details on to the responding person file;
libname w5 "X:\HILDA\Release 60\files\SAS e60c" access=readonly;
*extract and sort the responding person file;
proc sort data=w5.rperson_e60c out=rperson; by xwaveid; run ;
* Select hours worked, age and sex;
* rename and merge back with the main file;
data partners;
set rperson (keep = ehhpxid ehgage ehgsex ejbhruc
rename=(ehhpxid=xwaveid
ejbhruc = parthour
ehgage = partage
ehgsex = partsex ));
where xwaveid ne '';
run;
proc sort data=partners; by xwaveid; run ;
data rperson;
merge partners rperson (in=a);
by xwaveid;
if a;
run;
|
Example 5: SPSS program to add partner variables
|
/* ************************************************************* */
/* Created by: Simon Freidin (Updated by: Nicole Watson) */
/* ************************************************************* */
/* Sort the responding person file by xwaveid and save the sorted file */
get file='X:\HILDA\Release 60\files\SPSS e60c\Rperson e60c.sav'.
sort cases by xwaveid.
save outfile='E:\working\Rperson e60c.sav'.
get file='X:\HILDA\Release 60\files\SPSS e60c\Rperson e60c.sav'
/keep= ehhpxid ehgage ehgsex ejbhruc .
sel if ehhpxid ne ''.
rename vars
(ehhpxid = xwaveid)
(ejbhruc = parthour)
(ehgage = partage)
(ehgsex = partsex).
sort cases by xwaveid.
match file table=*/file='E:\working\Rperson e60c.sav'/by xwaveid.
exe.
|
Example 6: STATA program to add partner variables
|
/* ************************************************************* */
/* Created by: Clinton Hayes (Updated by: Nicole Watson) */
/* ************************************************************* */
use "X:\HILDA\Release 60\files\STATA e60c\Rperson_e60c.dta", clear
sort xwaveid
save "E:\working\rperson.dta", replace
use "E:\working\rperson.dta", clear
keep ehhpxid ehgage ehgsex ejbhruc
drop if ehhpxid ==""
rename ehhpxid xwaveid
rename ejbhruc parthour
rename ehgage partage
rename ehgsex partsex
sort xwaveid
save "E:\working\partner.dta", replace
use "E:\working\rperson.dta"
sort xwaveid
merge xwaveid using "E:\working\partner.dta"
drop if _merge==2
drop _merge
save "E:\working\rperson.dta", replace
|
PanelWhiz
PanelWhiz is a collection of STATA/SE Add–On scripts to make using panel datasets easier. The package allows the user to easily select vectors of variables across waves. Matching and merging of the files is done automatically to create a long file (with one record per person per wave). More information and how to order PanelWhiz can be found at: http://www.melbourneinstitute.com/hilda/doc/doc_panelwhiz.htm.
|