Reputation: 1
I have a dataset in Stata with information on whether or not a participant has experienced a specific side effect. The dataset contains about 900 participants and there are 20 side effects captured for each participant. The values for each side effect are "0" denoting the participant did not experience the side effect and "1" denoting the participant did experience the side effect. I want to count the number of "1"s for each participant and ultimately summarize the number of participants that experienced one side effect, two side effects, three side effects, etc.
I tried the count if
command but that does not allow me to get the number of "1"s for each participant across the 20 side effects.
Upvotes: 0
Views: 98
Reputation: 37183
If your (0, 1) variables are all numeric then the number of values of 1 is identical to the row sum across variables. Hence
egen wanted = rowtotal(sideeffect*)
where sideeffect*
is a wild guess on variable names, as you don't give a data example or mention any names.
Putting 0 and 1 within " "
in your question may indicate that you are holding these as string variables. If so, you need to destring
those variables first.
Upvotes: 1