Dear all,

I am working with the xtabond2 command in Stata to solve the endogeneity problem of my estimation. I read the construction of doing xtabond2 from David Roodman. However, I am still confused that my coding is right or wrong. I appreciate receiving your advice :

Code:
*************:
xtabond2 ltotalfertility l.ltotalfertility l(0/2).(pand_res_pt) i.year, ///
iv(i.year, eq(both)) ///
iv(l(0/2).(pand_res_pt), eq(both)) ///
gmm(ltotalfertility, lag(2 .) collapse eq(both))  ///
h(1) ar(3) two cluster(ifscode)
here, by choosing
Code:
. xtabond2 ltotalfertility l.ltotalfertility l(0/2).(pand_res_pt) i.year, ///
> iv(i.year, eq(both)) ///
> iv(l(0/2).(pand_res_pt), eq(both)) ///
> gmm(ltotalfertility, lag(2 .) collapse eq(both))  ///
> h(1) ar(3) two cluster(ifscode)
Favoring speed over space. To switch, type or click on mata: mata set matafavor space, perm.
1996b.year dropped due to collinearity
1997.year dropped due to collinearity
2009.year dropped due to collinearity
2018.year dropped due to collinearity
2019.year dropped due to collinearity
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: ifscode                         Number of obs      =      3622
Time variable : year                            Number of groups   =       183
Number of instruments = 44                      Obs per group: min =         1
Wald chi2(23) =  69569.39                                      avg =     19.79
Prob > chi2   =     0.000                                      max =        20
                                   (Std. err. adjusted for clustering on ifscode)
---------------------------------------------------------------------------------
                |              Corrected
ltotalfertility | Coefficient  std. err.      z    P>|z|     [95% conf. interval]
----------------+----------------------------------------------------------------
ltotalfertility |
            L1. |   .8861639   .0218916    40.48   0.000     .8432571    .9290708
                |
    pand_res_pt |
            --. |  -.0253932   .0059697    -4.25   0.000    -.0370936   -.0136929
            L1. |  -.0309516    .008387    -3.69   0.000    -.0473897   -.0145134
            L2. |  -.0282224   .0065436    -4.31   0.000    -.0410476   -.0153972
                |
           year |
          1998  |  -.0060163   .0048398    -1.24   0.214    -.0155022    .0034696
          1999  |  -.0054971    .004538    -1.21   0.226    -.0143914    .0033972
          2000  |  -.0053192   .0040945    -1.30   0.194    -.0133442    .0027059
          2001  |  -.0116792    .004663    -2.50   0.012    -.0208184   -.0025399
          2002  |  -.0085614   .0040365    -2.12   0.034    -.0164728     -.00065
          2003  |  -.0082516   .0035831    -2.30   0.021    -.0152744   -.0012288
          2004  |  -.0066783   .0034789    -1.92   0.055    -.0134968    .0001401
          2005  |  -.0094819   .0034326    -2.76   0.006    -.0162097   -.0027541
          2006  |   -.006441   .0031204    -2.06   0.039    -.0125569   -.0003251
          2007  |  -.0062036   .0032063    -1.93   0.053    -.0124879    .0000806
          2008  |   -.006044   .0029945    -2.02   0.044    -.0119131   -.0001749
          2010  |   .0023753   .0019727     1.20   0.229    -.0014911    .0062418
          2011  |  -.0024552   .0013919    -1.76   0.078    -.0051833    .0002729
          2012  |  -.0121593   .0034885    -3.49   0.000    -.0189966    -.005322
          2013  |  -.0177037   .0037538    -4.72   0.000    -.0250609   -.0103465
          2014  |  -.0139368   .0039577    -3.52   0.000    -.0216938   -.0061797
          2015  |  -.0176519   .0041448    -4.26   0.000    -.0257756   -.0095281
          2016  |   -.018251   .0041753    -4.37   0.000    -.0264344   -.0100676
          2017  |  -.0233959   .0044382    -5.27   0.000    -.0320946   -.0146973
                |
          _cons |   .1172786   .0240108     4.88   0.000     .0702183    .1643389
---------------------------------------------------------------------------------
Instruments for first differences equation
  Standard
    D.(pand_res_pt L.pand_res_pt L2.pand_res_pt)
    D.(1996b.year 1997.year 1998.year 1999.year 2000.year 2001.year 2002.year
    2003.year 2004.year 2005.year 2006.year 2007.year 2008.year 2009.year
    2010.year 2011.year 2012.year 2013.year 2014.year 2015.year 2016.year
    2017.year 2018.year 2019.year)
  GMM-type (missing=0, separate instruments for each period unless collapsed)
    L(2/23).ltotalfertility collapsed
Instruments for levels equation
  Standard
    pand_res_pt L.pand_res_pt L2.pand_res_pt
    1996b.year 1997.year 1998.year 1999.year 2000.year 2001.year 2002.year
    2003.year 2004.year 2005.year 2006.year 2007.year 2008.year 2009.year
    2010.year 2011.year 2012.year 2013.year 2014.year 2015.year 2016.year
    2017.year 2018.year 2019.year
    _cons
  GMM-type (missing=0, separate instruments for each period unless collapsed)
    DL.ltotalfertility collapsed
------------------------------------------------------------------------------
Arellano-Bond test for AR(1) in first differences: z =  -4.49  Pr > z =  0.000
Arellano-Bond test for AR(2) in first differences: z =   0.67  Pr > z =  0.501
Arellano-Bond test for AR(3) in first differences: z =  -1.82  Pr > z =  0.069
------------------------------------------------------------------------------
Sargan test of overid. restrictions: chi2(20)   =  17.39  Prob > chi2 =  0.628
  (Not robust, but not weakened by many instruments.)
Hansen test of overid. restrictions: chi2(20)   =  96.22  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(19)   =  70.91  Prob > chi2 =  0.000
    Difference (null H = exogenous): chi2(1)    =  25.31  Prob > chi2 =  0.000
  iv(1996b.year 1997.year 1998.year 1999.year 2000.year 2001.year 2002.year 2003.year 2004.year 2005.year 2006.year 2007.year 2008.year 2009
> .year 2010.year 2011.year 2012.year 2013.year 2014.year 2015.year 2016.year 2017.year 2018.year 2019.year)
    Hansen test excluding group:     chi2(1)    =   0.10  Prob > chi2 =  0.757
    Difference (null H = exogenous): chi2(19)   =  96.12  Prob > chi2 =  0.000
  iv(pand_res_pt L.pand_res_pt L2.pand_res_pt)
    Hansen test excluding group:     chi2(17)   =  90.00  Prob > chi2 =  0.000
    Difference (null H = exogenous): chi2(3)    =   6.21  Prob > chi2 =  0.102


.
end of do-file
the lag(2 .) , but when I use the collapse the Hansen test is not significant.


***also I used the "xtdpdgmm" to get te better results, I did this :
Code:
xtdpdgmm L(0/1).ltotalfertility l(0/2).(pand_res_pt) i.year, noserial gmmiv(L.ltotalfertility, collapse model(difference)) iv(l(0/2).(pand_res_pt) i.year, difference model(difference)) twostep vce(robust)
and the results :
Code:
. xtdpdgmm L(0/1).ltotalfertility l(0/2).(pand_res_pt) i.year, noserial gmmiv(L.ltotalfertility, collapse model(difference)) iv(l(0/2).(pand
> _res_pt) i.year, difference model(difference)) twostep vce(robust)
note: 1996.year identifies no observations in the sample.
note: 1997.year identifies no observations in the sample.
note: 2017.year omitted because of collinearity.
note: 2018.year identifies no observations in the sample.
note: 2019.year identifies no observations in the sample.

Generalized method of moments estimation

Fitting full model:

Step 1:
initial:       f(b) =  19.115759
alternative:   f(b) =  4.6514905
rescale:       f(b) =  .08442007
Iteration 0:   f(b) =  .08442007  
Iteration 1:   f(b) =  .00083005  
Iteration 2:   f(b) =  .00082701  
Iteration 3:   f(b) =  .00082701  

Step 2:
Iteration 0:   f(b) =  .97149141  
Iteration 1:   f(b) =  .57064682  
Iteration 2:   f(b) =  .56335002  
Iteration 3:   f(b) =   .5633197  
Iteration 4:   f(b) =  .56331884  
Iteration 5:   f(b) =  .56331881  

Group variable: ifscode                      Number of obs         =      3622
Time variable: year                          Number of groups      =       183

Moment conditions:     linear =      43      Obs per group:    min =         1
                    nonlinear =      18                        avg =  19.79235
                        total =      61                        max =        20

                                 (Std. err. adjusted for 183 clusters in ifscode)
---------------------------------------------------------------------------------
                |              WC-Robust
ltotalfertility | Coefficient  std. err.      z    P>|z|     [95% conf. interval]
----------------+----------------------------------------------------------------
ltotalfertility |
            L1. |   1.025479   .0123817    82.82   0.000     1.001211    1.049746
                |
    pand_res_pt |
            --. |   .0027941   .0027985     1.00   0.318    -.0026909    .0082791
            L1. |   .0014515   .0040002     0.36   0.717    -.0063887    .0092917
            L2. |   .0011745   .0039944     0.29   0.769    -.0066543    .0090033
                |
           year |
          1996  |          0  (empty)
          1997  |          0  (empty)
          1998  |  -.0134633   .0039956    -3.37   0.001    -.0212946    -.005632
          1999  |  -.0099362   .0039732    -2.50   0.012    -.0177235   -.0021489
          2000  |  -.0072415   .0039882    -1.82   0.069    -.0150582    .0005752
          2001  |  -.0112745   .0031739    -3.55   0.000    -.0174952   -.0050537
          2002  |  -.0051081   .0031922    -1.60   0.110    -.0113647    .0011486
          2003  |  -.0028348   .0032195    -0.88   0.379    -.0091448    .0034752
          2004  |   .0006642   .0032341     0.21   0.837    -.0056745     .007003
          2005  |  -.0004954    .002737    -0.18   0.856    -.0058598    .0048691
          2006  |    .004047   .0031755     1.27   0.202    -.0021767    .0102708
          2007  |   .0055304   .0032534     1.70   0.089    -.0008462    .0119071
          2008  |   .0068074   .0032675     2.08   0.037     .0004032    .0132115
          2009  |   .0009863   .0024508     0.40   0.687    -.0038171    .0057897
          2010  |   .0030281   .0027427     1.10   0.270    -.0023475    .0084037
          2011  |   .0013373   .0022822     0.59   0.558    -.0031357    .0058103
          2012  |   .0048407   .0023568     2.05   0.040     .0002214    .0094599
          2013  |     .00075   .0015893     0.47   0.637    -.0023651     .003865
          2014  |   .0057334   .0019981     2.87   0.004     .0018172    .0096496
          2015  |   .0034253   .0013914     2.46   0.014     .0006982    .0061525
          2016  |    .003241   .0012295     2.64   0.008     .0008312    .0056508
          2017  |          0  (omitted)
          2018  |          0  (empty)
          2019  |          0  (empty)
                |
          _cons |   -.037772   .0117266    -3.22   0.001    -.0607558   -.0147882
---------------------------------------------------------------------------------
Instruments corresponding to the linear moment conditions:
 1, model(diff):
   L1.L.ltotalfertility L2.L.ltotalfertility L3.L.ltotalfertility
   L4.L.ltotalfertility L5.L.ltotalfertility L6.L.ltotalfertility
   L7.L.ltotalfertility L8.L.ltotalfertility L9.L.ltotalfertility
   L10.L.ltotalfertility L11.L.ltotalfertility L12.L.ltotalfertility
   L13.L.ltotalfertility L14.L.ltotalfertility L15.L.ltotalfertility
   L16.L.ltotalfertility L17.L.ltotalfertility L18.L.ltotalfertility
   L19.L.ltotalfertility L20.L.ltotalfertility
 2, model(diff):
   D.pand_res_pt D.L.pand_res_pt D.L2.pand_res_pt D.1999bn.year D.2000.year
   D.2001.year D.2002.year D.2003.year D.2004.year D.2005.year D.2006.year
   D.2007.year D.2008.year D.2009.year D.2010.year D.2011.year D.2012.year
   D.2013.year D.2014.year D.2015.year D.2016.year D.2017.year
 3, model(level):
   _cons

.
end of do-file

the results are not the same, Please guide me if is it the right command.

Many thanks in advance for your valuable time and advice.

Regards,