jeudi 13 août 2020

how can i create new variable which will add the values of columns conditional on other set of variables ? (Example provided)

I have four variable for individual members age Of household, age_01,age_02,age_03 and age_04 and four variable for their working hour, work_hr_01, work_hr_02, work_hr_03 and work_hr_04. i want to create new variable for total working hour for members age 16 and 17 of the households. i have following data:

id   age_01 age_02 age_03 age_04 work_hr_01 work_hr_02 work_hr_03 work_hr_04  
 1     24      16      22     16      33         45         55        40
 2     33      17      18     17      40         33         35        39         
 3     33      17      16     16      40         33         34        42

desired outcome with two new variable, work_hr_by_16 and work_hr_by_17

ID age_01 age_02 age_03 age_04 work_hr_01 work_hr_02 work_hr_03 work_hr_04  work_hr_by_16   work_hr_by_17
1    24      16      22     16      33         45         55        40              73            na
2    33      17      18     17      40         33         35        39              na            72
3    33      17      16     16      40         33         34        42              76            33

Aucun commentaire:

Enregistrer un commentaire