Quantcast
Channel: Statalist
Viewing all articles
Browse latest Browse all 65540

Count how often each household member was mentioned per activity

$
0
0
Dear Statalist,
within my survey data set, I asked each respondent who in the household was responsible for specific activities and I would like to know for each household member, how often that household member was named for a specific activity.

hh_id ind_id activity1 activity2
1 11 . .
1 12 11 12
1 13 11 12
2 21 21 .
2 22 21 .
3 31 31 .
3 32 31 .
3 33 31 .
4 41 41 42
4 42 41 42
4 43 41 42
4 44 42 .

I think that I have to loop over the individuals and count how often each individual has been named. I'm just not sure how to do this. The FAQ on"How do I create variables summarizing for each individual property of the other members of a group? (http://www.stata.com/support/faqs/da...ng-properties/) was of some help, but I couldn't get the code running. Stata would not accept the delimit expressions.

by hh_id activity1, sort: gen smex1 = _N activity1<.
by hh_id activity2, sort: gen smex2 = _N if activity2<.
gen byte smex1_n = 0
gen byte smex2_n = 0

forval i = 1 / `r(max)' {
replace smex2_n = (m_hhex_indid == `i' | (j_hhex_indid == `i'))
#delimit ;
qui by hh_id (smex2_n), sort:
replace smex1_n =
cond(activity2[_N] == `i', smex2[_N], smex1[_N])
if person == `i' & smex2_n[_N] ;
#delimit cr
}

Also, I would like to create a variable which counts over both of my activities, so it should contain for each individual how often they have been mentioned within the vars activity1 and activity2.
I would very much appreciate your help!
Best,
Laura



Viewing all articles
Browse latest Browse all 65540

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>