Hello All, and Thanks in Advance.

I have a very large dataset for which I need to create a variable- no doubt using egen- but the process is not completely clear to me.

Cases are distributed across about 125 spatial groups and these spatial groupings in continuous variable (1-125).

I am interested in generating a variable that quantifies the mean difference in another binary subgroup variable *within spatial groups*

Example: What is the mean difference in height between subgroup A and subgroup B ----within spatial groups (1-125)

Variables: Height, Subgroup, Spatial Group

Thanks in advance for any advice, and I'm happy to provide further information and/or clarification.