The variable "denominator" was computed from other variables. "Monthly_notification_date" is essentially months (731 being Dec 2020 or so....below those many rows of 731 are 732, 733 etc for subsequent months in the data). I am trying to find the sum of "denominator" in each month and I want to call it facility_total. The first column is "facility." The problem is that every facility will have the same value for "denominator" and there are multiple rows with the same ID for "facility". I only need the "denominator" to be added once for every "facility" during each month.
I have tried both bysort monthly_notification_date : egen facility_total = total(denominator) AND bysort monthly_notification_date : egen facility_total = sum(denominator), none of which worked. They both gave impossibly high values because the repeated rows of "denominator" is being added multiple times for each facility, instead of once. Please kindly help with a code that resolves this.
I have tried both bysort monthly_notification_date : egen facility_total = total(denominator) AND bysort monthly_notification_date : egen facility_total = sum(denominator), none of which worked. They both gave impossibly high values because the repeated rows of "denominator" is being added multiple times for each facility, instead of once. Please kindly help with a code that resolves this.
Code:
* Example generated by -dataex-. For more info, type help dataex clear input float(facility monthly_notification_date denominator) 10 731 9 37 731 10 32 731 7 34 731 10 34 731 10 5 731 11 35 731 9 30 731 8 31 731 11 36 731 9 17 731 11 5 731 11 22 731 8 5 731 11 29 731 9 22 731 8 22 731 8 5 731 11 11 731 8 73 731 11 17 731 11 19 731 10 35 731 9 35 731 9 73 731 11 12 731 9 22 731 8 21 731 10 33 731 9 14 731 8 17 731 11 15 731 10 6 731 8 20 731 10 21 731 10 15 731 10 12 731 9 4 731 8 33 731 9 34 731 10 19 731 10 5 731 11 19 731 10 35 731 9 12 731 9 10 731 9 11 731 8 27 731 10 11 731 8 2 731 10 27 731 10 28 731 13 24 731 5 20 731 10 22 731 8 8 731 11 37 731 10 35 731 9 17 731 11 7 731 8 12 731 9 5 731 11 22 731 8 34 731 10 4 731 8 22 731 8 8 731 11 19 731 10 25 731 10 32 731 7 21 731 10 25 731 10 20 731 10 37 731 10 15 731 10 35 731 9 14 731 8 4 731 8 74 731 6 11 731 8 27 731 10 36 731 9 8 731 11 27 731 10 27 731 10 4 731 8 5 731 11 21 731 10 28 731 13 19 731 10 12 731 9 25 731 10 15 731 10 25 731 10 37 731 10 8 731 11 30 731 8 10 731 9 30 731 8 24 731 5 end format %tm monthly_notification_date
Comment