I believe I am doing this correctly but I would love confirmation from others more experienced with this type of analysis. I am attempting to calculate a practice-level observed over expected rate for mortality with data from two levels (patient and physician practice).


Code:
melogit mortality covariates  || practiceid:
predict yhat
by practiceid: egen yhatsum = sum(yhat)
gen expected = yhatsum/totalnumberpatients
gen observed = totaldeaths/totalnumberpatients
gen SRR = observed/expected
Is there anything I am missing or something else I should be aware of when calculating these rates?