I am trying to replicate findings from a particular study. The study uses the xtabond
command in Stata to run an Arellano-Bond estimator with lags of the dependent variables. The goal of the study is to estimate the effects of being in year X of a 4 year cycle (with the cycle repeating over a 50 year period) for N units.
The call in Stata is:
xtabond rpcexp_annual election election_3 election_2 rpcinc_annual rpcgrants_annual unem popmillions_annual kidsaged rr dd y1974 y1975 y1976 y1977 y1978 y1979 y1980 y1981 y1982 y1983 y1984 y1985 y1986 if stcode!=2 & stcode!=4 & stcode!=29 & stcode!=39 & stcode!=45 & stcode!=42 & year>=1974, robust maxlag(4)
We have tried several packages in R including pgmm but have been unable to replicate the results (our understanding is pgmm may be bugged as described here). We have two questions.
First, which function in R will allow us to replicate this command?
Second, what does the lag notation refer to in the initial Stata command? It is unclear from the documentation what is being lagged as there is no division between exogenous and endogenous variables or instruments.
Data attached for a reproducible example:
* Example generated by -dataex-. To install: ssc install dataex
clear
input float rpcexp_annual byte(election election_3 election_2) float(rpcinc_annual rpcgrants_annual unem popmillions_annual kidsaged) byte(rr dd y1974 y1975 y1976 y1978 y1979 y1980 y1981 y1982 y1983 y1984 y1985 y1986)
1316.5624 0 0 1 9125.947 288.6954 . 3.267 35.42777 . . 0 0 0 0 0 0 0 0 0 0 0 0
1376.9705 0 0 0 9413.523 308.77295 . 3.316 35.628387 . . 0 0 0 0 0 0 0 0 0 0 0 0
1400.4978 1 0 0 9797.964 299.67462 . 3.323 35.90664 . . 0 0 0 0 0 0 0 0 0 0 0 0
1495.06 0 1 0 10348.486 336.344 . 3.358 35.97399 . . 0 0 0 0 0 0 0 0 0 0 0 0
1645.6897 0 0 1 10948.69 381.1924 . 3.395 36.14107 . . 0 0 0 0 0 0 0 0 0 0 0 0
1803.7977 0 0 0 11418.86 477.7399 . 3.443 35.740902 . . 0 0 0 0 0 0 0 0 0 0 0 0
1956.1627 1 0 0 11752.167 468.3919 . 3.464 35.687828 . . 0 0 0 0 0 0 0 0 0 0 0 0
2041.5275 0 1 0 12293.09 471.9064 . 3.458 36.63967 . . 0 0 0 0 0 0 0 0 0 0 0 0
2120.65 0 0 1 12711.763 490.5691 4.5 3.446 36.79629 0 1 0 0 0 0 0 0 0 0 0 0 0 0
2215.6824 0 0 0 13060.082 560.79626 3.9 3.44 36.51686 0 1 0 0 0 0 0 0 0 0 0 0 0 0
2350.494 1 0 0 13499.014 635.9165 5.9 3.444 36.453197 0 1 0 0 0 0 0 0 0 0 0 0 0 0
2441.2668 0 1 0 14287.498 689.6812 5.5 3.497 36.071228 0 1 0 0 0 0 0 0 0 0 0 0 0 0
2446.2986 0 0 1 15086.62 668.4541 4.5 3.539 35.72848 0 1 0 0 0 0 0 0 0 0 0 0 0 0
2451.418 0 0 0 15173.22 679.898 4.5 3.58 35.42019 0 1 0 0 0 0 0 0 0 0 0 0 0 0
2564.1316 1 0 0 15227.479 699.0737 5.5 3.626 35.07692 0 1 1 0 0 0 0 0 0 0 0 0 0 0
2718.576 0 1 0 15877.83 748.5618 7.7 3.679 34.79945 0 1 0 1 0 0 0 0 0 0 0 0 0 0
2813.7976 0 0 1 16376.425 800.3513 6.8 3.735 34.758896 0 1 0 0 1 0 0 0 0 0 0 0 0 0
2832.032 0 0 0 16924.018 800.6426 7.4 3.78 35.31165 0 1 0 0 0 0 0 0 0 0 0 0 0 0
2824.152 1 0 0 16975.473 802.2593 6.3 3.832 35.08583 0 1 0 0 0 1 0 0 0 0 0 0 0 0
2782.23 0 1 0 16537.809 793.6146 7.1 3.866 34.65111 0 1 0 0 0 0 1 0 0 0 0 0 0 0
2736.76 0 0 1 16428.512 740.1887 8.8 3.894 33.53878 0 1 0 0 0 0 0 1 0 0 0 0 0 0
2794.776 0 0 0 16380.41 656.3935 10.7 3.919 33.00229 0 1 0 0 0 0 0 0 1 0 0 0 0 0
2881.61 1 0 0 16777.41 625.9977 14.4 3.925 32.70743 0 1 0 0 0 0 0 0 0 1 0 0 0 0
2908.602 0 1 0 17656.92 640.411 13.7 3.934 32.4413 0 1 0 0 0 0 0 0 0 0 1 0 0 0
3107.953 0 0 1 18356.063 695.7643 11.1 3.952 32.33893 0 1 0 0 0 0 0 0 0 0 0 1 0 0
3309.771 0 0 0 18958.783 704.9506 8.9 3.973 32.34709 0 1 0 0 0 0 0 0 0 0 0 0 1 0
3230.8005 1 0 0 19360.621 664.225 9.8 3.992 32.44691 0 1 0 0 0 0 0 0 0 0 0 0 0 1
3279.5334 0 1 0 19815.21 736.0481 7.8 4.015 32.532257 0 0 0 0 0 0 0 0 0 0 0 0 0 0
3394.6855 0 0 1 20468.39 698.1594 7.2 4.024 32.38347 0 0 0 0 0 0 0 0 0 0 0 0 0 0
3514.046 0 0 0 20736.43 719.9347 7 4.03 32.39437 0 0 0 0 0 0 0 0 0 0 0 0 0 0
3669.283 1 0 0 20748.943 773.0032 6.9 4.04 33.16011 0 0 0 0 0 0 0 0 0 0 0 0 0 0
3877.976 0 1 0 21135.86 838.7319 7.2 4.099 31.8731 0 0 0 0 0 0 0 0 0 0 0 0 0 0
3900.5786 0 0 1 21194.834 902.0014 7.4 4.154 31.80135 0 0 0 0 0 0 0 0 0 0 0 0 0 0
3996.209 0 0 0 21507.75 904.3861 7.6 4.214 31.50653 0 1 0 0 0 0 0 0 0 0 0 0 0 0
4111.263 1 0 0 21879.33 914.1227 6 4.26 31.47955 0 1 0 0 0 0 0 0 0 0 0 0 0 0
4186.5776 0 1 0 22021.05 916.8386 6.3 4.297 31.27467 0 0 0 0 0 0 0 0 0 0 0 0 0 0
4228.099 0 0 1 22351.08 934.7521 5.1 4.331 31.18011 0 0 0 0 0 0 0 0 0 0 0 0 0 0
4401.7114 0 0 0 23063.37 1014.215 5.1 4.368 31.03124 0 0 0 0 0 0 0 0 0 0 0 0 0 0
4634.854 1 0 0 23431.49 1073.6261 4.2 4.405 31.23361 0 0 0 0 0 0 0 0 0 0 0 0 0 0
4894.457 0 1 0 23716.32 1129.3009 4.8 4.43 30.73455 0 1 0 0 0 0 0 0 0 0 0 0 0 0
. 0 0 1 . . 4.5 4.447 31.60606 0 1 0 0 0 0 0 0 0 0 0 0 0 0
2311.1653 0 0 1 16617.84 847.2505 . .226 . . . 0 0 0 0 0 0 0 0 0 0 0 0
2852.0886 0 0 0 16158.52 929.4943 . .238 . . . 0 0 0 0 0 0 0 0 0 0 0 0
3365.185 1 0 0 16487.813 1113.9612 . .246 . . . 0 0 0 0 0 0 0 0 0 0 0 0
3939.2825 0 1 0 17478.406 1547.7615 . .256 . . . 0 0 0 0 0 0 0 0 0 0 0 0
4497.172 0 0 1 18493.336 2104.962 . .263 . . . 0 0 0 0 0 0 0 0 0 0 0 0
4830.5137 0 0 0 19254.928 2135.0315 . .271 . . . 0 0 0 0 0 0 0 0 0 0 0 0
5464.552 1 0 0 20194.69 2389.3037 . .271 . . . 0 0 0 0 0 0 0 0 0 0 0 0
5894.966 0 1 0 20868.88 2505.1936 . .278 . . . 0 0 0 0 0 0 0 0 0 0 0 0
5609.474 0 0 1 21730.25 1989.375 . .285 . 1 0 0 0 0 0 0 0 0 0 0 0 0 0
5705.096 0 0 0 22923.81 1670.6044 . .296 . 0 0 0 0 0 0 0 0 0 0 0 0 0 0
6835.52 1 0 0 23653.85 1864.8027 . .303 . 0 0 0 0 0 0 0 0 0 0 0 0 0 0
8433.653 0 1 0 24286.54 2188.944 . .316 . 0 1 0 0 0 0 0 0 0 0 0 0 0 0
9179.755 0 0 1 25687.615 2311.7124 . .324 . 0 1 0 0 0 0 0 0 0 0 0 0 0 0
8912.5205 0 0 0 27708.854 2321.8918 . .331 . 0 0 0 0 0 0 0 0 0 0 0 0 0 0
8486.839 1 0 0 31254.2 2227.4233 . .341 . 0 0 1 0 0 0 0 0 0 0 0 0 0 0
8607.662 0 1 0 34856.113 2262.1702 . .376 . 0 0 0 1 0 0 0 0 0 0 0 0 0 0
9146.642 0 0 1 35365.742 2262.9238 8 .401 28.92051 0 0 0 0 1 0 0 0 0 0 0 0 0 0
9563.523 0 0 0 33771.79 2229.545 9.4 .403 29 0 0 0 0 0 0 0 0 0 0 0 0 0 0
10327.962 1 0 0 32091.33 2159.0454 11.2 .405 28.3 0 0 0 0 0 1 0 0 0 0 0 0 0 0
11982.192 0 1 0 31357.47 2150.9333 9.2 .403 27.9 0 0 0 0 0 0 1 0 0 0 0 0 0 0
13077.068 0 0 1 31373.104 2173.8315 9.7 .402 25.8 0 0 0 0 0 0 0 1 0 0 0 0 0 0
13513.48 0 0 0 32238.6 1904.3528 9.3 .418 25.1 0 0 0 0 0 0 0 0 1 0 0 0 0 0
14328.63 1 0 0 33115.49 1655.2924 9.9 .45 24.7 0 0 0 0 0 0 0 0 0 1 0 0 0 0
14726.245 0 1 0 32742.28 1599.464 10.3 .488 24.3 0 0 0 0 0 0 0 0 0 0 1 0 0 0
14798.727 0 0 1 32428.8 1584.992 10 .514 24.3 0 0 0 0 0 0 0 0 0 0 0 1 0 0
14743.357 0 0 0 31843.23 1483.284 9.7 .532 24.3 0 0 0 0 0 0 0 0 0 0 0 0 1 0
14645.305 1 0 0 30247.625 1473.2877 10.8 .544 24.2 0 0 0 0 0 0 0 0 0 0 0 0 0 1
14073.73 0 1 0 29168.084 1855.4728 10.8 .539 24.9 0 0 0 0 0 0 0 0 0 0 0 0 0 0
13384.085 0 0 1 29509.66 1938.952 9.3 .542 24.8 0 0 0 0 0 0 0 0 0 0 0 0 0 0
13105.982 0 0 0 30133.895 1718.062 6.7 .547 25 0 0 0 0 0 0 0 0 0 0 0 0 0 0
12707.703 1 0 0 29759.19 1746.5212 7 .55 25.8 0 0 0 0 0 0 0 0 0 0 0 0 0 0
12542.252 0 1 0 29238.13 1781.084 8.7 .57 25.8 0 0 0 0 0 0 0 0 0 0 0 0 0 0
12372.348 0 0 1 29222.5 1893.831 9.2 .589 26.1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
12137.702 0 0 0 29192.496 1971.333 7.7 .599 26.4 0 0 0 0 0 0 0 0 0 0 0 0 0 0
11982.547 1 0 0 28979.56 1981.7893 7.8 .603 27.04224 0 0 0 0 0 0 0 0 0 0 0 0 0 0
11708.7 0 1 0 28569.2 2025.486 7.3 .604 27.41656 0 0 0 0 0 0 0 0 0 0 0 0 0 0
11633.382 0 0 1 28504.266 2068.8638 7.8 .609 27.44053 0 0 0 0 0 0 0 0 0 0 0 0 0 0
11718.472 0 0 0 28909.61 2123.8718 7.9 .613 28.1243 0 0 0 0 0 0 0 0 0 0 0 0 0 0
11835.538 1 0 0 29073.613 2205.6846 5.8 .62 28.7899 0 0 0 0 0 0 0 0 0 0 0 0 0 0
12135.523 0 1 0 29462.7 2265.7112 6.4 .625 29.30968 0 0 0 0 0 0 0 0 0 0 0 0 0 0
. 0 0 1 . . 6.7 .627 28.52963 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1880.2672 1 . . 12130.445 289.0184 . 1.302 33.343147 . . 0 0 0 0 0 0 0 0 0 0 0 0
1994.296 0 . . 12234.726 303.12503 . 1.407 33.878998 . . 0 0 0 0 0 0 0 0 0 0 0 0
2069.7703 1 . . 12379.693 328.9912 . 1.471 34.31105 . . 0 0 0 0 0 0 0 0 0 0 0 0
2125.8398 0 . . 12616.122 340.135 . 1.521 34.67369 . . 0 0 0 0 0 0 0 0 0 0 0 0
2231.752 1 . . 13008.673 390.7931 . 1.556 35.24855 . . 0 0 0 0 0 0 0 0 0 0 0 0
2390.786 0 . . 13467.5 471.8137 . 1.584 35.30158 . . 0 0 0 0 0 0 0 0 0 0 0 0
2599.287 1 . . 13973.276 537.7237 . 1.614 35.93263 . . 0 0 0 0 0 0 0 0 0 0 0 0
2677.664 0 . . 14748.19 558.815 . 1.646 35.84447 . . 0 0 0 0 0 0 0 0 0 0 0 0
2640.892 1 . . 15805.41 524.65796 3.6 1.682 36.26635 1 0 0 0 0 0 0 0 0 0 0 0 0 0
2717.9175 0 . . 16762.72 522.0126 2.9 1.737 35.73829 1 0 0 0 0 0 0 0 0 0 0 0 0 0
2854.258 1 0 0 17413.816 531.3039 4.1 1.775 36.049107 1 0 0 0 0 0 0 0 0 0 0 0 0 0
3042.169 0 1 0 18050.035 531.0124 4.5 1.896 37.0985 1 0 0 0 0 0 0 0 0 0 0 0 0 0
3121.365 0 0 1 18783.205 571.12964 3.8 2.008 35.863472 1 0 0 0 0 0 0 0 0 0 0 0 0 0
3047.864 0 0 0 18822.143 584.3438 3.6 2.124 34.97347 1 0 0 0 0 0 0 0 0 0 0 0 0 0
3112.0754 1 0 0 18161.543 576.8924 5.6 2.223 34.81687 1 0 1 0 0 0 0 0 0 0 0 0 0 0
3286.8125 0 1 0 18074.033 610.4025 12.1 2.285 34.6745 0 0 0 1 0 0 0 0 0 0 0 0 0 0
3390.967 0 0 1 18615.066 624.2149 9.8 2.346 33.973885 0 0 0 0 1 0 0 0 0 0 0 0 0 0
3370.134 0 0 0 19383.855 654.8785 8.2 2.425 35.583622 0 0 0 0 0 0 0 0 0 0 0 0 0 0
end
The result of this gmm should be:
Please help reproduce this result in R.
This option says to use at most lag 4 to instrument for both predetermined and endogenous variables.
If you want to treat variables differently, you would use
pre(varlist [, lagstruct(prelags, premaxlags)])
andendogenous(varlist [, lagstruct(endlags, endmaxlags)])
.You can let each variable have its own lag structure by repeating options (or have groups of variables that are treated similarly):
In R, I would try theIt looks like you already ruled this out, and I am unsure if there is anything better. Let me offer my strategy for solving such problems instead.plm
package for this.First, try installing the dev version of plm. Sometimes that works if the version on CRAN is stale.
Second, ensure your summary stats match the authors to rule out data issues.
Third, I would also not consider anything buggy because some user on SO reported that while there are no issues on GitHub. These models can be finicky in any language. Try replicating the simplest model on a public dataset and then increase complexity in a direction similar to what you are trying to do until you get a divergence between R and Stata. If you cannot figure that out, submit a bug request on GitHub with a reproducible example. Cameron and Trivedi's MUS have many examples and accessible data in Stata. The first edition is cheap if you cannot get the second edition from the library. I think the Baltagi and Hsiao panel data books may also have some reproducible examples.
I would also try replicating the Stata code using the same version of the package the authors used and then the newest one. Sometimes there are bug fixes, so you are trying to replicate something that was itself buggy in the same language, which may be impossible. This relies on having access to Stata, maybe even an older version.