I have a two level data (hospital level and region level), each hospital has an unique o:e:
hospid zipid o:e
1 1 0.8
2 1 0.5
3 1 0.4
4 2 0.9
5 2 1.2
6 2 1.5
I want to generate the 25% quantiles and 75% quantiles of o:e by zipid, so that the output would be like this:
hospid zipid o:e q1 q3
1 1 0.8 0.9 1.05
2 1 0.5 0.9 1.05
3 1 0.4 0.9 1.05
4 2 0.9 1.0 1.10
5 2 1.2 1.0 1.10
6 2 1.5 1.0 1.10
I found a R code that can show the exact quantiles, but not sure how to extract those values and generating new variables based on those values.
do.call("rbind", tapply(data$oe, data$zipid, quantile))
0% 25% 50% 75% 100%
region1 0.93 0.99 1.02 1.04 1.11
region2 0.54 0.92 1.02 1.07 1.16
Any suggestions? Thanks!!