May 28, 2006

Attaching spousal characteristics for IPUMS datasets in Stata

First draft of a program for attaching spousal characteristics in IPUMS datasets using Stata

capture program drop spousal_char
program spousal_char, sortpreserve
capture drop _merge
tempfile spouses
sort year serial pernum
keep year serial sploc `0'
rename sploc pernum
foreach i of local 0 {
capture drop sp_`i'
rename `i' sp_`i'
label var sp_`i' "Spouse's `i'"

sort year serial pernum
drop if pernum==0
save "`spouses'", replace

merge year serial pernum using "`spouses'"

Once you have run the program you can attach spousal characteristics by typing
spousal_char [varlist]

Obviously some improvements could be made ... at a later date.

Posted by eroberts at May 28, 2006 6:16 PM