Hello,

I have a question regarding running the xtabond2 command, with alternating years of data. I am using an unbalanced database of firms with three years of data (2011, 2013, 2015). I would like to estimate a system GMM model for labor productivity, and as GMM style instruments, I want to use the first and second lags of the variables (the first lag in this case is information from 2 years ago, and the second lag, whenever relevant, is from four years ago). xtabond2 gives the following error message, if I try to estimate the model with the years coded as above:

Code:
 xtset q1 Year
       panel variable:  q1 (unbalanced)
        time variable:  Year, 2011 to 2015, but with gaps
                delta:  1 unit
Code:
  xtabond2 lnlabprod_v2 lncaplab_v2 lnrawlab_v2 lnnplab_v2 pc_aq pc_fire pc_light q122 q124 q117a6 q101c q111b q115a q34a q36a q29a  q105 i.q17a i.Year if (q13a == 1 & q11a == 0), gmm (lnlabprod_v2 lncaplab_v2 lnrawlab_v2 lnnplab_v2 pc_aq pc_fire pc_light q122 q124 q117a6 q101c q111b q115a q34a q36a q29a q105 , lag(1 2)) iv(i.Year, eq(level))  iv(i.q17a, eq(both)) robust twostep
Favoring speed over space. To switch, type or click on mata: mata set matafavor space, perm.
Warning: Two-step estimated covariance matrix of moments is singular.
  Using a generalized inverse to calculate robust weighting matrix for Hansen test.
  Difference-in-Sargan/Hansen statistics may be negative.
estimates post: matrix has missing values
                 stata():  3598  Stata returned error
         xtabond2_mata():     -  function returned error
                 <istmt>:     -  function returned error
​​​​​​​

So, I created a new time variable,
Code:
gen time = 1 if Year == 2011
replace time= 2 if Year == 2013
replace time = 3 if Year == 2015
and then run the code for xtabond2 above. The results are as follows.

Code:
. xtabond2 lnlabprod_v2 lncaplab_v2 lnrawlab_v2 lnnplab_v2 pc_aq pc_fire q122 q124 q117a6 q101c q111b q115a q34a q36a q29a q105 i.q1
> 7a i.Year if (q13a == 1 & q11a == 0), gmm (lnlabprod_v2 lncaplab_v2 lnrawlab_v2 lnnplab_v2 pc_aq pc_fire  q122 q124 q117a6 q101c q
> 111b q115a q34a q36a q29a q105, lag(1 2)) iv(i.Year, eq(level))  iv(i.q17a, eq(both)) robust twostep
Favoring speed over space. To switch, type or click on mata: mata set matafavor space, perm.
Warning: Two-step estimated covariance matrix of moments is singular.
  Using a generalized inverse to calculate optimal weighting matrix for two-step estimation.
  Difference-in-Sargan/Hansen statistics may be negative.

Dynamic panel-data estimation, two-step system GMM
------------------------------------------------------------------------------
Group variable: q1                              Number of obs      =      5679
Time variable : time                            Number of groups   =      2983
Number of instruments = 102                     Obs per group: min =         1
Wald chi2(39) =  22624.99                                      avg =      1.90
Prob > chi2   =     0.000                                      max =         3
-----------------------------------------------------------------------------------------------------------------------------------
                                                                  |              Corrected
                                                     lnlabprod_v2 |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
------------------------------------------------------------------+----------------------------------------------------------------
                                                      lncaplab_v2 |   .0354353   .0430597     0.82   0.411    -.0489602    .1198307
                                                      lnrawlab_v2 |   .1227379   .0259091     4.74   0.000      .071957    .1735189
                                                       lnnplab_v2 |   .3460553   .0384345     9.00   0.000     .2707251    .4213856
                                                            pc_aq |   4.34e-06   1.92e-06     2.26   0.024     5.81e-07    8.09e-06
                                                          pc_fire |  -1.08e-06   7.95e-07    -1.35   0.176    -2.63e-06    4.83e-07
                                                             q122 |   .0329375   .0496159     0.66   0.507    -.0643078    .1301829
                                                             q124 |   .1886265   .0834946     2.26   0.024     .0249801    .3522729
                                                           q117a6 |   .0005963   .0004886     1.22   0.222    -.0003612    .0015539
                                                            q101c |   .0015383   .0011335     1.36   0.175    -.0006834    .0037599
                                                            q111b |   .0792683   .3197831     0.25   0.804     -.547495    .7060316
                                                            q115a |   .1115387   .1038907     1.07   0.283    -.0920833    .3151608
                                                             q34a |   .0210799   .0097299     2.17   0.030     .0020097    .0401501
                                                             q36a |   .1160642   .1216182     0.95   0.340     -.122303    .3544315
                                                             q29a |  -.0012474   .0009021    -1.38   0.167    -.0030154    .0005207
                                                             q105 |   -.002237   .1018361    -0.02   0.982    -.2018321    .1973581
                                                                  |
                                                             q17a |
                                                     Agriculture  |          0  (empty)
                                              Food and beverages  |   .3506242   .4971583     0.71   0.481    -.6237882    1.325037
                                                         Tobacco  |   .4395318   .5532646     0.79   0.427    -.6448469    1.523911
                                                        Textiles  |   .2753416   .4979738     0.55   0.580    -.7006691    1.251352
                                                         Apparel  |   .0278234   .4942391     0.06   0.955    -.9408675    .9965142
                                                         Leather  |   .2896563   .5070813     0.57   0.568    -.7042048    1.283517
                                                            Wood  |   .1764778   .5001476     0.35   0.724    -.8037935    1.156749
                                                           Paper  |   .4107523   .4950751     0.83   0.407     -.559577    1.381082
                                         Publishing and printing  |   .3756701   .4917285     0.76   0.445       -.5881     1.33944
                                          Refined petroleum etc.  |   .2307311   .5362108     0.43   0.667    -.8202228    1.281685
                                          Chemical products etc.  |   .3164512   .5179295     0.61   0.541     -.698672    1.331574
                                                          Rubber  |   .3203078   .4937529     0.65   0.517      -.64743    1.288046
                                   Non-metallic mineral products  |   .0294455   .5063753     0.06   0.954    -.9630319    1.021923
                                                    Basic metals  |   .6232988   .5141709     1.21   0.225    -.3844577    1.631055
                                       Fabricated metal products  |   .3364873   .4934035     0.68   0.495    -.6305657     1.30354
                Electronic machinery, computers, radio, tv, etc.  |   .5475978   .4950758     1.11   0.269     -.422733    1.517929
                                             Motor vehicles etc.  |  -.0088229   .5261101    -0.02   0.987     -1.03998    1.022334
                                       Other transport equipment  |   .4125957   .5896561     0.70   0.484    -.7431091      1.5683
Furniture, jewellery, music equipment, watches, toys and medic..  |   .1689693   .4968482     0.34   0.734    -.8048353    1.142774
                                                  Recycling etc.  |  -.1834269      .5786    -0.32   0.751    -1.317462    .9506083
                                                        Services  |          0  (omitted)
                                                                  |
                                                             Year |
                                                            2011  |          0  (empty)
                                                            2013  |  -4.525192   .0364661  -124.09   0.000    -4.596664   -4.453719
                                                            2015  |  -4.416423   .0372227  -118.65   0.000    -4.489378   -4.343468
                                                                  |
                                                            _cons |   15.94037    .906944    17.58   0.000      14.1628    17.71795
-----------------------------------------------------------------------------------------------------------------------------------
Instruments for first differences equation
  Standard
    D.(0b.q17a 1.q17a 2.q17a 3.q17a 4.q17a 5.q17a 6.q17a 7.q17a 8.q17a 9.q17a
    10.q17a 11.q17a 12.q17a 13.q17a 14.q17a 15.q17a 16.q17a 17.q17a 18.q17a
    19.q17a 20.q17a)
  GMM-type (missing=0, separate instruments for each period unless collapsed)
    L(1/2).(lnlabprod_v2 lncaplab_v2 lnrawlab_v2 lnnplab_v2 pc_aq pc_fire q122
    q124 q117a6 q101c q111b q115a q34a q36a q29a q105)
Instruments for levels equation
  Standard
    0b.q17a 1.q17a 2.q17a 3.q17a 4.q17a 5.q17a 6.q17a 7.q17a 8.q17a 9.q17a
    10.q17a 11.q17a 12.q17a 13.q17a 14.q17a 15.q17a 16.q17a 17.q17a 18.q17a
    19.q17a 20.q17a
    2011b.Year 2013.Year 2015.Year
    _cons
  GMM-type (missing=0, separate instruments for each period unless collapsed)
    D.(lnlabprod_v2 lncaplab_v2 lnrawlab_v2 lnnplab_v2 pc_aq pc_fire q122 q124
    q117a6 q101c q111b q115a q34a q36a q29a q105)
------------------------------------------------------------------------------
Arellano-Bond test for AR(1) in first differences: z =  -5.68  Pr > z =  0.000
Arellano-Bond test for AR(2) in first differences: z =      .  Pr > z =      .
------------------------------------------------------------------------------
Sargan test of overid. restrictions: chi2(62)   =1162.57  Prob > chi2 =  0.000
  (Not robust, but not weakened by many instruments.)
Hansen test of overid. restrictions: chi2(62)   = 183.34  Prob > chi2 =  0.000
  (Robust, but weakened by many instruments.)

Difference-in-Hansen tests of exogeneity of instrument subsets:
  GMM instruments for levels
    Hansen test excluding group:     chi2(30)   =  79.08  Prob > chi2 =  0.000
    Difference (null H = exogenous): chi2(32)   = 104.26  Prob > chi2 =  0.000
  iv(2011b.Year 2013.Year 2015.Year, eq(level))
    Hansen test excluding group:     chi2(60)   = 169.46  Prob > chi2 =  0.000
    Difference (null H = exogenous): chi2(2)    =  13.89  Prob > chi2 =  0.001
  iv(0b.q17a 1.q17a 2.q17a 3.q17a 4.q17a 5.q17a 6.q17a 7.q17a 8.q17a 9.q17a 10.q17a 11.q17a 12.q17a 13.q17a 14.q17a 15.q17a 16.q17a
> 17.q17a 18.q17a 19.q17a 20.q17a)
    Hansen test excluding group:     chi2(43)   = 160.39  Prob > chi2 =  0.000
    Difference (null H = exogenous): chi2(19)   =  22.96  Prob > chi2 =  0.239
My question is regarding the estimation of the Hansen test of overidentification restrictions. The chi-squared statistic is computed assuming I have three consecutive period of data, however this is not the case (this is also why I am using the first and second lags as instruments, because in reality, they represent lags of 2 years and 4 years respectively)). Is there some way to estimate the model using non-consecutive years of data, or to recompute this Hansen statistic assuming that the lags are actually for the second and fourth periods, instead of the first and second (I might be wrong, but my hunch is that the null hypothesis is being rejected so strongly, because of the presence of the gmm style instruments in the first lag form)?