Tuesday, June 29, 2021

How to count each binary variables and only generate one variable to include all count information?

Hi there,

I have a set of binary variables and each of them stands for a certain health disease (e.g. heart = heart disease, dep = depression, asth = asthma...).
I also have a variable phi with three values (1, 2, 3) which means three different kind of insurance.

Currently, I want to look at the three insurance distribution, by diseases

I wonder:

1. How to get the number of patients for each disease and put the count information into a new variable count? Or is there an easier way to show how many patients there are for each disease? The below code I tried will overwrite the values of former disease if the respondent has two or more diseases. It cannot calculate the number of patient with a certain disease correctly.
Code:
gen diagnosed=.
replace diagnosed = 1 if heart == 1
replace diagnosed = 2 if dep  == 2
replace diagnosed = 3 if asth == 3
....
2. How to get the insurance distribution by diseases? e.g. for patients with each disease, how many people buy 1st insurance, how many people buy 2nd insurance?


Thanks in advance!

No comments:

Post a Comment