Dear All,
I have several categorical variables for each member of the hh indicating whether the person leave in the house within the farm, or close to the farm etc.
I would like to construct new variables counting the number of person leaving in the household with the interviewed. That is sum-up to q26_1_6==1 to q26_@_6==1, if q26_1_6==2 then sum all the q26_@_6==2 and so on.
I tried this:
But it does not work.
I copy a part of the dataset. Any help?
thanks in advance
I have several categorical variables for each member of the hh indicating whether the person leave in the house within the farm, or close to the farm etc.
I would like to construct new variables counting the number of person leaving in the household with the interviewed. That is sum-up to q26_1_6==1 to q26_@_6==1, if q26_1_6==2 then sum all the q26_@_6==2 and so on.
I tried this:
Code:
foreach var of varlist q26_1_6 q26_2_6 q26_3_6 q26_4_6 q26_5_6 q26_6_6 q26_7_6 q26_8_6 q26_9_6 q26_10_6 q26_11_6 q26_12_6 { forvalues j=1/4 { egen hh_member`j'=rowtotal (`var') if `var'==`j' } }
I copy a part of the dataset. Any help?
thanks in advance
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input byte(q26_1_6 q26_2_6 q26_3_6 q26_4_6 q26_5_6 q26_6_6 q26_7_6 q26_8_6 q26_9_6 q26_10_6 q26_11_6 q26_12_6) 1 1 . . 3 . . . 1 4 . . 1 1 . . 2 . . . 1 . . . 1 1 . . . . . . 2 . . . 1 1 . . 2 . . . 2 3 . . 1 1 . . 2 . . . 1 . . . 1 . . 1 2 . . . . . . . 1 1 . . . . . . 4 . . . 2 . . . 4 . . . . . . . 1 1 . . 2 2 . . 1 . . . 1 1 . . 2 . . . 3 . . . 1 1 . . 4 4 . . 3 3 . . 1 1 . . 2 4 . . 1 . . . 1 1 . . 4 . . . 4 . . . 1 . 2 . . . . . . . . . 1 . . . . . . . 1 . . . 1 . 1 . . . . . . . . . 1 . 1 . . . . . . . . . 1 . 2 . . . . . . . . . 1 . . . 1 . . . . . . . 1 . 1 . . . . . . . . . 2 . 1 . . . . . . . . . 1 . 1 . . . . . . . . . 1 . . . . . . . . . . . 1 . 2 . . . . . . . . . 1 . . . . . . . . . . . 1 . . . . . . . . . . . 1 . . . . . . . . . . . 1 1 . . . . . . 4 1 . . 1 . 1 . . . . . . . . . 1 1 . . . . . . . . . . 1 . 2 . . . . . . . . . 1 . 2 . . . . . . . . . 1 . . . . . . . . . . . 1 1 . . . . . . 1 . . . 1 . . . . . . . . . . . 1 . . . . . . . . . . . 1 1 1 . . . . . . . . . 1 1 . . . . . . 1 . . . 1 1 . . . . . . 2 1 . . 1 1 . . . . . . 1 1 . . 1 . . . . . . . 2 2 . . 1 . . . . . . . 2 1 . . 1 1 . . . . . . . . . . 1 1 . . . . . . . . . . 1 1 . . . . . . . . . . 1 1 . . . . . . 1 1 . . 1 1 . . . . . . 1 1 . . 1 1 . . . . . . . . . . 1 1 . . . . . . . . . . 1 . . . 1 . . . . . . . 1 1 . . . . . . 1 . . . 1 1 2 . . . . . . . . . 1 . 2 . . . . . . . . . 1 . 1 . . . . . . . . . 1 . . . . . . . 2 . . . 1 1 1 . . . . . . . . . 1 1 . . . . . . 1 4 . . 1 1 . . . . . . 1 . . . 1 . 1 . . . . . . . . . 1 1 . . . . . . 1 1 . . 1 1 . . . . . . 1 1 . . 1 . . . . . . . . . . . 1 . . . . . . . . . . . 1 . . . . . . . 2 3 . . 1 1 . . . . . . . . . . 1 1 2 . . . . . . . . . 1 1 1 1 . . . . . . . . 1 1 . . . . . . . . . . 1 . 1 . . . . . . . . . 1 . . . . . . . . . . . 1 . 2 . . . . . . . . . 1 1 . . . . . . . . . . 1 . . . . . . . . . . . 1 . 1 . . . . . . . . . 1 . . . 1 . . . . . . . 1 . . . . . . . . . . . 1 1 . . . . . . 1 1 . . 1 . . . . . . . 1 1 . . 1 . . . . . . . 1 1 . . 1 1 . . . . . . 2 . . . 1 1 . . . . . . . . . . 1 . . . . . . . . . . . 1 1 . . . . . . 1 . . . 1 . . . . . . . 2 . . . 1 1 . . . . . . . . . . 1 . . . 1 . . . . . . . 1 . 1 . . . . . . . . . 1 . . . . . . . . . . . 1 . . . . . . . 2 . . . 1 1 . . . . . . 1 1 . . 1 . . . . . . . 2 1 . . 2 2 . . . . . . 2 . . . 1 1 . . . . . . 1 1 . . 1 . . . . . . . . . . . 1 1 . . 4 . . . . . . . 1 1 . . 4 . . . 2 . . . 1 1 . . . . . . 4 4 4 . 1 1 . . 1 . . . 1 . . . 1 2 . . 2 . . . 4 . . . 2 2 . . 4 . . . 2 . . . end label values q26_1_6 q26_1_6 label def q26_1_6 1 "home within the farm", modify label def q26_1_6 2 "home close to the farm", modify label values q26_2_6 q26_2_6 label def q26_2_6 1 "home within the farm", modify label def q26_2_6 2 "home close to the farm", modify label values q26_3_6 q26_3_6 label def q26_3_6 1 "home within the farm", modify label def q26_3_6 2 "home close to the farm", modify label values q26_4_6 q26_4_6 label def q26_4_6 1 "home within the farm", modify label values q26_5_6 q26_5_6 label def q26_5_6 1 "home within the farm", modify label def q26_5_6 2 "home close to the farm", modify label def q26_5_6 3 "home in a town/village easy to reach from the farm", modify label def q26_5_6 4 "further residences", modify label values q26_6_6 q26_6_6 label def q26_6_6 2 "home close to the farm", modify label def q26_6_6 4 "further residences", modify label values q26_7_6 q26_7_6 label values q26_8_6 q26_8_6 label values q26_9_6 q26_9_6 label def q26_9_6 1 "home within the farm", modify label def q26_9_6 2 "home close to the farm", modify label def q26_9_6 3 "home in a town/village easy to reach from the farm", modify label def q26_9_6 4 "further residences", modify label values q26_10_6 q26_10_6 label def q26_10_6 1 "home within the farm", modify label def q26_10_6 2 "home close to the farm", modify label def q26_10_6 3 "home in a town/village easy to reach from the farm", modify label def q26_10_6 4 "further residences", modify label values q26_11_6 q26_11_6 label def q26_11_6 4 "further residences", modify label values q26_12_6 q26_12_6
Comment