Let's imagine I fit the following model, using a stock Stata dataset.

Code:
use http://www.stata-press.com/data/r15/margex
logistic outcome agegroup##group

------------------------------------------------------------------------------
     outcome | Odds Ratio   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
         sex |
     female  |   .9197162   .1476234    -0.52   0.602     .6714717    1.259737
             |
       group |
          2  |   .1091104   .0248865    -9.71   0.000     .0697781    .1706132
          3  |   .0470885    .014446    -9.96   0.000     .0258096    .0859111
             |
   sex#group |
   female#2  |   4.412609   1.182369     5.54   0.000      2.60984    7.460655
   female#3  |   1.463475   1.147196     0.49   0.627     .3148774    6.801886
             |
       _cons |   .4930556   .0714998    -4.88   0.000     .3710736    .6551363
------------------------------------------------------------------------------
Imagine that for some reason, I want to treat females in group 1 as the reference category. For all other combinations of sex by group, I want to obtain the difference in the predicted probability of the outcome relative to that reference category. That is, I want to know the difference for male + group 1, for female + group 2, for male + group 2, etc, relative to the reference group.

What is the most concise margins command that I can type? I know that this works, but it produces a lot of extra comparisons:

Code:
 margins sex#group, pwcompare

Pairwise comparisons of adjusted predictions
Model VCE    : OIM

Expression   : Pr(outcome), predict()

---------------------------------------------------------------------------
                          |            Delta-method         Unadjusted
                          |   Contrast   Std. Err.     [95% Conf. Interval]
--------------------------+------------------------------------------------
                sex#group |
    (male#2) vs (male#1)  |  -.2791815   .0331885     -.3442299   -.2141332
    (male#3) vs (male#1)  |  -.3075421   .0326294     -.3714947   -.2435896
  (female#1) vs (male#1)  |  -.0182407   .0353112     -.0874494     .050968
  (female#2) vs (male#1)  |   -.151029   .0367989     -.2231535   -.0789045
  (female#3) vs (male#1)  |  -.2999295   .0383922     -.3751769   -.2246821
    (male#3) vs (male#2)  |  -.0283606    .010425     -.0487933    -.007928
  (female#1) vs (male#2)  |   .2609408   .0170553       .227513    .2943686
  (female#2) vs (male#2)  |   .1281525   .0199539      .0890435    .1672615
  (female#3) vs (male#2)  |   -.020748   .0227588     -.0653545    .0238584
  (female#1) vs (male#3)  |   .2893014     .01594      .2580596    .3205433
  (female#2) vs (male#3)  |   .1565131   .0190095      .1192552     .193771
  (female#3) vs (male#3)  |   .0076126   .0219355     -.0353801    .0506053
(female#2) vs (female#1)  |  -.1327883   .0233144     -.1784838   -.0870929
(female#3) vs (female#1)  |  -.2816888   .0257559     -.3321695   -.2312082
(female#3) vs (female#2)  |  -.1489005   .0277605       -.20331    -.094491
---------------------------------------------------------------------------
I think that I should be using -margins, contrast-. But I can't quite figure out how to do this. The closest I can get is:

Code:
margins r.sex#r.group

Contrasts of adjusted predictions
Model VCE    : OIM

Expression   : Pr(outcome), predict()

--------------------------------------------------------------
                           |         df        chi2     P>chi2
---------------------------+----------------------------------
                 sex#group |
(female vs male) (2 vs 1)  |          1       13.03     0.0003
(female vs male) (3 vs 1)  |          1        0.39     0.5340
                    Joint  |          2       22.28     0.0000
--------------------------------------------------------------

----------------------------------------------------------------------------
                           |            Delta-method
                           |   Contrast   Std. Err.     [95% Conf. Interval]
---------------------------+------------------------------------------------
                 sex#group |
(female vs male) (2 vs 1)  |   .1463932   .0405591      .0668988    .2258876
(female vs male) (3 vs 1)  |   .0258533   .0415698      -.055622    .1073286
----------------------------------------------------------------------------
And that's not quite it. Any thoughts?