I'm analyzing a randomized controlled trial with four treatment groups. I want to test whether there are significant differences by treatment group assignment within subgroups.

To test whether there are statistically significant differences by treatment group assignment in the overall sample, I do the following:

Code:
quietly logistic y i.x i.sex
margins, dydx(*)  
margins x, pwcompare
Then I use the confidence intervals generated by the third line of the above code to test whether the differences are statistically significant.

I assume this is correct, but I'd be grateful if somebody could confirm.


Now, I also want to test whether there are significant difference in treatment effects within certain subpopulations (e.g. within males and females).

First, I include an interaction term to my regression model (see code below), but I don't know how to proceed.

Code:
quietly logistic y i.x i.sex i.x#i.sex
Basically, I need to generate for males and females separately what I generated for the overall sample using the -pwcompare command.

Any help would be greatly appreciated.