Project

General

Profile

Support #2231 » Compile individual info.do

Luis Ortiz, 04/09/2025 05:05 PM

 

*********************************************************************
************ PROBLEMS WITH PARTNER'S INFORMATION (1) ***************
*********************************************************************



/* Do-file está destinado a seleccionar variables y fusionar ficheros en uno sólo */

* Path del lugar a donde van a ir a parar los ficheros con las variables y datos seleccionados

cd "G:\Mi unidad\Word\Investigación\Proyectos en curso\Ministerio Ccia Innovac (2020)\Datos Understanding Society\Datos net"


* Next, a global macro containing file path to data directory

global inpath_ukhls "G:\Mi unidad\Word\Datos\Understanding Society\US Waves 1_14 (2009_22) BHPS Waves 1_18 (1991_2009)\stata\stata13_se\ukhls"
global inpath_bhps "G:\Mi unidad\Word\Datos\Understanding Society\US Waves 1_14 (2009_22) BHPS Waves 1_18 (1991_2009)\stata\stata13_se\bhps"

global inpath_net "G:\Mi unidad\Word\Investigación\Proyectos en curso\Ministerio Ccia Innovac (2020)\Datos Understanding Society\Datos net"


* EXTRACCIÓN DE VARIABLES INDIVIDUALES y FUSIÓN DE FICHEROS

foreach w in a b c d e f g h i j k l m n {
use using "$inpath_ukhls/`w'_indresp", clear
isvar pidp `w'_ppid `w'_hidp `w'_sex_dv `w'_age_dv `w'_doby_dv `w'_agegr10_dv `w'_agegr13_dv `w'_racel_dv `w'_region ///
`w'_scend_dv `w'_ftendy4 `w'_nhiqual_dv `w'_qfhigh_dv `w'_hiqual_dv `w'_fenow `w'_fetype `w'_isced11_dv ///
`w'_scopfamb `w'_scopfamf `w'_marstat_dv ///
`w'_pno `w'_ppno `w'_gor_dv
keep `r(varlist)'
// for appending the wave specific files into long format we need to
// (ii) create a wave variable
gen wave = strpos("abcdefghijklmn","`w'")

// (iii) drop the wave prefix from all variables that had one
rename `w'_* *

// recode values from -1 to -9 to Stata system missing for all variables
mvdecode _all, mv(-21, -20, -11/-1)

// save each wave specific file
save `w'pjunk.dta, replace
}

// Open the file for wave a and then add the rest of the wave specific files
use apjunk, clear
foreach w in b c d e f g h i j k l m n {
append using `w'pjunk.dta
}
sort pidp wave

save Individual_data2, replace

// get rid of unwanted temporary files
foreach w in a b c d e f g h i j k l m n {
erase `w'pjunk.dta
}


* EXTRACCIÓN DE VARIABLES DE HOGAR Y FUSIÓN DE FICHEROS

foreach w in a b c d e f g h i j k l m n {
use using "$inpath_ukhls/`w'_hhresp", clear
isvar `w'_hidp `w'_hhsize ///
`w'_nkids_dv `w'nch02_dv `w'_nch34_dv `w'_agechy_dv
keep `r(varlist)'
// for appending the wave specific files into long format we need to
// (ii) create a wave variable
gen wave = strpos("abcdefghijklmn","`w'")

// (iii) drop the wave prefix from all variables that had one
rename `w'_* *

// recode values from -1 to -9 to Stata system missing for all variables
mvdecode _all, mv(-21, -20, -11/-1)

// save each wave specific file
save `w'pjunk.dta, replace
}

// Open the file for wave a and then add the rest of the wave specific files
use apjunk, clear
foreach w in b c d e f g h i j k l m n {
append using `w'pjunk.dta
}
sort hidp wave

save Household_data2, replace

// get rid of unwanted temporary files
foreach w in a b c d e f g h i j k l m n {
erase `w'pjunk.dta
}


* FUSIÓN DE FICHEROS DE DATOS INDIVIDUALES Y DE HOGAR

merge 1:m hidp using Individual_data2

* Para ver la posible razón por la que el merge no sale perfecto, ver lo siguiente:
* https://iserredex.essex.ac.uk/support/issues/1642?tab=history

tab _merge

* A continuación podemos ver que, como se responde a la pregunta en el foro, a partir
* de la ola 5 empieza a ver casos raros
* For retrieving household information of individuals WHO DID NOT COMPLETE the household file,
* I was recommended using the 'indall' file

tab _merge wave

keep if _merge==2 | _merge==3

drop _merge

save Prueba_partner, replace



(1-1/3)