dear statalisters:
i have attempted to use margins with contrast operators to compare all levels of a 3+ level categorical variable to the base level after anova or xtreg. this works fine with r.factor (assuming first level is base), but does not work with r2.factor, which, according to documentation, should set the second level as the base category for comparison.
i may just be misinterpretting margins, contrast documentation.
see code below
Code:
. sysuse bplong
(fictional blood-pressure data)

. xtset patient when
       panel variable:  patient (strongly balanced)
        time variable:  when, 1 to 2
                delta:  1 unit

. xtdes

 patient:  1, 2, ..., 120                                    n =        120
    when:  1, 2, ..., 2                                      T =          2
           Delta(when) = 1 unit
           Span(when)  = 2 periods
           (patient*when uniquely identifies each observation)

Distribution of T_i:   min      5%     25%       50%       75%     95%     max
                         2       2       2         2         2       2       2

     Freq.  Percent    Cum. |  Pattern
 ---------------------------+---------
      120    100.00  100.00 |  11
 ---------------------------+---------
      120    100.00         |  XX

. xtreg bp i.sex#i.agegrp

Random-effects GLS regression                   Number of obs     =        240
Group variable: patient                         Number of groups  =        120

R-sq:                                           Obs per group:
     within  =      .                                         min =          2
     between = 0.4393                                         avg =        2.0
     overall = 0.2442                                         max =          2

                                                Wald chi2(5)      =      75.59
corr(u_i, X)   = 0 (assumed)                    Prob > chi2       =     0.0000

-------------------------------------------------------------------------------
           bp |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
--------------+----------------------------------------------------------------
   sex#agegrp |
  Male#46-59  |        8.2   2.570528     3.19   0.001     3.161858    13.23814
    Male#60+  |     14.125   2.570528     5.49   0.000     9.086858    19.16314
Female#30-45  |       -3.9   2.570528    -1.52   0.129    -8.938142    1.138142
Female#46-59  |     -2.225   2.570528    -0.87   0.387    -7.263142    2.813142
  Female#60+  |      7.525   2.570528     2.93   0.003     2.486858    12.56314
              |
        _cons |     149.95   1.817638    82.50   0.000     146.3875    153.5125
--------------+----------------------------------------------------------------
      sigma_u |          0
      sigma_e |  12.307349
          rho |          0   (fraction of variance due to u_i)
-------------------------------------------------------------------------------

. margins i.agegrp

Predictive margins                              Number of obs     =        240
Model VCE    : Conventional

Expression   : Linear prediction, predict()

------------------------------------------------------------------------------
             |            Delta-method
             |     Margin   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
      agegrp |
      30-45  |        148   1.285264   115.15   0.000     145.4809    150.5191
      46-59  |   152.9375   1.285264   118.99   0.000     150.4184    155.4566
        60+  |    160.775   1.285264   125.09   0.000     158.2559    163.2941
------------------------------------------------------------------------------

. margins r.agegrp

Contrasts of predictive margins
Model VCE    : Conventional

Expression   : Linear prediction, predict()

-----------------------------------------------------
                  |         df        chi2     P>chi2
------------------+----------------------------------
           agegrp |
(46-59 vs 30-45)  |          1        7.38     0.0066
  (60+ vs 30-45)  |          1       49.40     0.0000
           Joint  |          2       50.25     0.0000
-----------------------------------------------------

-------------------------------------------------------------------
                  |            Delta-method
                  |   Contrast   Std. Err.     [95% Conf. Interval]
------------------+------------------------------------------------
           agegrp |
(46-59 vs 30-45)  |     4.9375   1.817638      1.374996    8.500004
  (60+ vs 30-45)  |     12.775   1.817638      9.212496     16.3375
-------------------------------------------------------------------

. margins r2.agegrp
invalid contrast;
factor with only one level not allowed
r(322);

.
could you please confirm my error in understanding or an error in Stata?