Hello and thanks for taking your time to read an answer my question,

I am working with Stata and I have math grades for two different groups: A and B. I want to see the gap that exists between both groups in each decile. In addition I want to do a box plot of this gap for each decile (I want to have 10 box plots, one for each decile which shows the gap between group grades).

What I first did was to compute the deciles using xtile for both groups:

xtile decileA= mat if group==1, nq(10)

xtile decileB= mat if group==0, nq(10)


However, my observations of group A and B do not have the same number of observations nor distribution. I thought of computing quantiles for each decile and group and subtracting them to get the difference in each decile at each quartile to create the boxplot. However I do not know how to proceed afterwards to create the graph and given that I hace a different number of observations in each group decile I do not know if it is correct to proceed this way.

Now, if I try to use the pctile option and compute the difference at each decile I loose all the variance in the data inside each decile. I only get median differences and not all the quantiles I want.

Ex:

pctile decileA= mat if group==1, nq(10)

pctile decileB= mat if group==0, nq(10)

gen qdiff= decileA- decileB if _n<10

gen qtau=_n/10 if _n<10

graph box qdiff, over(qtau)

I want to know if there is a way to do the graph I am intending to and if there is I would really appreciate your help.

Thanks, Karla