Helo I would like to aggregate individual level data of working_days from working_days1 - working_days9 then collapse it per HHID and wave. Then, I would like to merge it back to the individual level data. I tried using this command but it keeps having an error on generating the totdays. I also used rowtotal but it does not work.
preserve
drop if participation_confirm == 0
gen totdays = days_worked_1 + days_worked_2 + days_worked_3 + days_worked_4 + days_worked_5 + days_worked_6 + days_worked_7 + days_worked_8 + days_worked_9
collapse (sum) totdays, by(hhid wave)
tempfile `dayswork', replace
restore
merge 1:1 hhid wave using `dayswork'
drop if _merge == 2
drop _merge
Later on I would also like to loop it for different variables like earned_income and in-kind money (again, from 1-9). How can I do this too?
Thanks so much~
preserve
drop if participation_confirm == 0
gen totdays = days_worked_1 + days_worked_2 + days_worked_3 + days_worked_4 + days_worked_5 + days_worked_6 + days_worked_7 + days_worked_8 + days_worked_9
collapse (sum) totdays, by(hhid wave)
tempfile `dayswork', replace
restore
merge 1:1 hhid wave using `dayswork'
drop if _merge == 2
drop _merge
Later on I would also like to loop it for different variables like earned_income and in-kind money (again, from 1-9). How can I do this too?
Thanks so much~
Comment