I have a "census" data set. Each row is the number of patients living in the specific housing area of a facility for the each day. I generated a total number of patient per day for the facility.
sort FacilityCode2 CensusDate2
by FacilityCode2 CensusDate2: egen DailyFacilityPopulation=total(InmateCount)
What I need next is to create the monthly average of patients per month (per facility). My try was:
bysort FacilityCode2 month : egen MonthlyAverage_FP=mean(DailyFacilityPopulation)
but I am including all the rows of my DailyFacilityPopulation variable and not only one number (it should be one number per day). I tried to generate a flag to select only one distinct observation but I dont know if it is working. At the end, I would only need one number per month (which is the monthly average of each facility)
Thank you,
Marvin
sort FacilityCode2 CensusDate2
by FacilityCode2 CensusDate2: egen DailyFacilityPopulation=total(InmateCount)
What I need next is to create the monthly average of patients per month (per facility). My try was:
bysort FacilityCode2 month : egen MonthlyAverage_FP=mean(DailyFacilityPopulation)
but I am including all the rows of my DailyFacilityPopulation variable and not only one number (it should be one number per day). I tried to generate a flag to select only one distinct observation but I dont know if it is working. At the end, I would only need one number per month (which is the monthly average of each facility)
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str4 FacilityCode2 int CensusDate2 float month str8 HousingArea byte PatientCount float DailyFacilityPopulation byte flag float MonthlyAverage_FP "AMKC" 20454 1 "LOWER 8" 28 101 1 87.66666 "AMKC" 20454 1 "MOD 10 A" 23 101 0 . "AMKC" 20454 1 "MOD17L A" 50 101 0 . "AMKC" 20455 1 "RR" 15 51 1 87.66666 "AMKC" 20455 1 "3 TOP" 36 51 0 . "AMKC" 20455 1 "LOWER 2" 0 51 0 . "AMKC" 20456 1 "MOD 18UA" 49 111 1 87.66666 "AMKC" 20456 1 "MOD 7" 34 111 0 . "AMKC" 20456 1 "LOWER 11" 28 111 0 . "AMKC" 20485 2 "LOWER 4" 22 81 1 96.33334 "AMKC" 20485 2 "LOWER 5" 27 81 0 . "AMKC" 20485 2 "MOD 12A" 32 81 0 . "AMKC" 20486 2 "UPPER 17" 21 73 1 96.33334 "AMKC" 20486 2 "UPPER 14" 26 73 0 . "AMKC" 20486 2 "UPPER 15" 26 73 0 . "AMKC" 20487 2 "4 UPPER" 40 135 1 96.33334 "AMKC" 20487 2 "4 MAIN" 30 135 0 . "AMKC" 20487 2 "3 MAIN" 5 135 0 . "AMKC" 20487 2 "2 MAIN" 10 135 0 . "AMKC" 20487 2 "1 MAIN" 0 135 0 . "AMKC" 20487 2 "MOD 18UB" 50 135 0 . end format %tdnn/dd/CCYY CensusDate2
Marvin