Hi group members
I want to merge two data sets: one is on household level and the other is on individual level. The household level data has details about expenditure on around 42 items and individual data set have sociodemographic information individuals in a particular household. Both data sets have household id (hhid) but this variable is not unique due to which the data is not merging. Please suggest how can I merge these files:
.Data set 1
* Example generated by -dataex-. To install: ssc install dataex
clear
input str38 hhid int item_code
"HCES2022655621010121713017 101111 301" 139
"HCES2022655621010121713017 101111 310" 139
"HCES2022655621010121713017 101111 311" 139
"HCES2022655621010121713017 101111 313" 139
"HCES2022655371010122023014 201111 202" 139
"HCES2022655261010122023016 101112 201" 139
"HCES2022655261010122023016 101112 301" 139
"HCES2022655261010122023016 101112 303" 139
"HCES2022655261010122023016 101112 306" 139
"HCES2022655261010122023016 101112 307" 139
"HCES2022655261010122023016 101112 308" 139
"HCES2022655261010122023016 101112 309" 139
"HCES2022655261010122023016 101112 310" 139
"HCES2022655261010122023016 101112 311" 139
Data set 2
* Example generated by -dataex-. To install: ssc install dataex
clear
input str38 hhid float person_no
"HCES2022310002282831212025 228111 301" 1
"HCES2022310002282831212025 228111 302" 5
"HCES2022310002282831212025 228111 302" 3
"HCES2022310002282831212025 228111 302" 4
"HCES2022310002282831212025 228111 302" 2
"HCES2022310002282831212025 228111 302" 1
"HCES2022310002282831212025 228111 303" 2
"HCES2022310002282831212025 228111 303" 5
"HCES2022310002282831212025 228111 303" 4
"HCES2022310002282831212025 228111 303" 1
"HCES2022310002282831212025 228111 303" 3
"HCES2022310002282831212025 228111 304" 2
"HCES2022310002282831212025 228111 304" 1
"HCES2022310002282831212025 228111 305" 1
"HCES2022310002282831212025 228111 306" 1
"HCES2022310002282831212025 228111 307" 1
Comment