Hi all, I have a complex dataset with multiple levels of loops. Here are the details:
A. Two individuals per row (e.g., b4_tribe_1, b4_tribe_2, b8b_leave_rsn_1, b8b_leave_rsn_2)
B. Multi-select responses (e.g. b8b_leave_rsn_1_1 b8b_leave_rsn_2_1, b8b_leave_rsn_3_1 for the first person and , b8b_leave_rsn_2_2, b8b_leave_rsn_3_2 for the second person)
C. Looped questions per individual and option (e.g., b34a_eco_act_1_1, b34a_eco_act_1_2, b34a_eco_act_2_1, b34a_eco_act_2_2)
I want to clean the dataset so that for each row, I have one variable, so that my variables look like the following:
b4_tribe
b8b_leave_rsn
b8b_leave_rsn_1_
b8b_leave_rsn_2_
b8b_leave_rsn_3_
b22b_main_tasks__1 //first main tasks for each person
b22b_main_tasks__2 //second main tasks for each person
b22b_main_tasks__3 //third main tasks for each person
The issue is that for variables in category C above, I would have to rename each of them so that the last number represents the person instead of the activity number. I have 7000+ similar variables, so this would be an extremely cumbersome process. Is there an alternative way to approach this? Below is the code I am currently using.
rename b34a_eco_act_1_1 b34a_eco_act1_1
rename b34a_eco_act_1_2 b34a_eco_act2_1
rename b34a_eco_act_2_1 b34a_eco_act1_2
rename b34a_eco_act_2_2 b34a_eco_act2_2
* Reshape person-level data to long format
reshape long ///
a16_refugee_no_ a17_fayda_owned_ a18_fayda_no_ ///
b7a_oth_native_ lbl_native_lang_ b12_sp_lang_ ///
b12_sp_lang_1_ b12_sp_lang_2_ b12_sp_lang_3_ ///
b12_sp_lang_4_ b12_sp_lang_5_ b34a_eco_act1_ b34a_eco_act2_, ///
i(calc_suid) j(person)
A. Two individuals per row (e.g., b4_tribe_1, b4_tribe_2, b8b_leave_rsn_1, b8b_leave_rsn_2)
B. Multi-select responses (e.g. b8b_leave_rsn_1_1 b8b_leave_rsn_2_1, b8b_leave_rsn_3_1 for the first person and , b8b_leave_rsn_2_2, b8b_leave_rsn_3_2 for the second person)
C. Looped questions per individual and option (e.g., b34a_eco_act_1_1, b34a_eco_act_1_2, b34a_eco_act_2_1, b34a_eco_act_2_2)
I want to clean the dataset so that for each row, I have one variable, so that my variables look like the following:
b4_tribe
b8b_leave_rsn
b8b_leave_rsn_1_
b8b_leave_rsn_2_
b8b_leave_rsn_3_
b22b_main_tasks__1 //first main tasks for each person
b22b_main_tasks__2 //second main tasks for each person
b22b_main_tasks__3 //third main tasks for each person
The issue is that for variables in category C above, I would have to rename each of them so that the last number represents the person instead of the activity number. I have 7000+ similar variables, so this would be an extremely cumbersome process. Is there an alternative way to approach this? Below is the code I am currently using.
rename b34a_eco_act_1_1 b34a_eco_act1_1
rename b34a_eco_act_1_2 b34a_eco_act2_1
rename b34a_eco_act_2_1 b34a_eco_act1_2
rename b34a_eco_act_2_2 b34a_eco_act2_2
* Reshape person-level data to long format
reshape long ///
a16_refugee_no_ a17_fayda_owned_ a18_fayda_no_ ///
b7a_oth_native_ lbl_native_lang_ b12_sp_lang_ ///
b12_sp_lang_1_ b12_sp_lang_2_ b12_sp_lang_3_ ///
b12_sp_lang_4_ b12_sp_lang_5_ b34a_eco_act1_ b34a_eco_act2_, ///
i(calc_suid) j(person)
Comment