Good morning everybody. I have a dataset containing hospitals (each hospital is numbered with one individual ik-number) and Procedures (ICD). I want to group the hospitals in 5 Quintiles, depending on how many patients they treated. In my following code, I generate a new variable n_patients_1, which tells me how many patients are treated in one specific hospital (ik).
Now i want to create 5 Quintiles of the hospitals depending on how many patients are treated.
The code i want to use should be something like this: "xtile quint = n_patients1, nquantiles(5)"
My question: How do I create this Quintiles, telling Stata not to count the empty variables (.), but without simply dropping the empty variables (because I would lose my procedures (ICD))?
Thanks for your help!!
Now i want to create 5 Quintiles of the hospitals depending on how many patients are treated.
The code i want to use should be something like this: "xtile quint = n_patients1, nquantiles(5)"
My question: How do I create this Quintiles, telling Stata not to count the empty variables (.), but without simply dropping the empty variables (because I would lose my procedures (ICD))?
Thanks for your help!!
Code:
***Create newid=1 if there is a new hospital by ik: gen newid = 1 if _n==1 *** Create the value n_patients, which shows you how many patients are treated in the ik bysort ik: gen n_patients=_N *** Generate a new variable and drop reductant values gen n_patients1 = n_patients replace n_patients1 = . if newid !=1
ICD | ik | newid | n_patients | n_patients_1 |
24342345 | 260100023 | 1 | 1 | 1 |
23462346 | 260100034 | 1 | 3 | 3 |
23467645 | 260100034 | . | 3 | . |
45674575 | 260100034 | . | 3 | . |
56785687 | 260100125 | 1 | 1 | 1 |
56875687 | 260100147 | 1 | 3 | 3 |
56787655 | 260100147 | . | 3 | . |
78909809 | 260100147 | . | 3 | . |
78890988 | 260100432 | 1 | 1 | 1 |
Comment