Hi All,

Seeking help on adding up variables (columns) with the same values.

I have variables diagnosis_1, diagnosis_2, diagnosis_3, and diagnosis_4, and all the values that can be entered are the same (e.g. "1"=appendicitis, "2"=sepsis, "3"=pneumonia, etc.)
I am trying to find a way to add up the frequency of those values across those variables together to find the total frequency of "1," "2," "3," etc. For example, the frequency of "1" across the diagnosis variables is 12, 7, 5, and 3, respecitvely, so I want to create a variable where the frequency of "1" for diagnosis_total is 12+7+5+3=27.

I figured I could do the following but realized it would take me a long time to manually edit each value from 1 to 77.

gen diagnosis_total=.
replace diagnosis_total=1 if diagnosis_1 == 1 | diagnosis_2 == 1 | diagnosis_3 == 1 | diagnosis_4 == 1
replace diagnosis_total=2 if diagnosis_2 == 2 | diagnosis_2 == 2 | diagnosis_3 == 2 | diagnosis_4 == 2
...
replace diagnosis_total=77 if diagnosis_2 == 77 | diagnosis_2 == 77 | diagnosis_3 == 77 | diagnosis_4 == 77
Any thoughts on a more efficient way to do this would be greatly appreciated.