### Install or Update xtabond2 Source: https://context7.com/droodman/xtabond2/llms.txt Install or update xtabond2 from SSC using the 'ssc install' command. The 'all' option installs companion .do files to the current directory, and 'replace' ensures you get the latest version. ```stata ssc install xtabond2, all replace ``` -------------------------------- ### Check xtabond2 Version Source: https://context7.com/droodman/xtabond2/llms.txt To check the currently installed version of xtabond2, simply run the command with the 'version' option. This is useful for ensuring you are using the latest features or for reporting purposes. ```stata xtabond2, version ``` -------------------------------- ### Replicate Greene (2002) p. 554 Source: https://context7.com/droodman/xtabond2/llms.txt Reproduces Greene's Econometric Analysis 5th ed., p. 554 example using `xi:` for year dummies (approximate) and then with exact cumulative year-dummy variables. ```stata * Reproduce Greene, Econometric Analysis 5th ed., p. 554 (Dahlberg & Johansson 2000) * Requires T7987.asc from http://qed.econ.queensu.ca/jae/2000-v15.4/dahlberg-johansson/ clear all set matsize 800 infile id year expend revenue grants using T7987.asc, clear tsset id year * Using xi: for year dummies (approximate) xi: xtabond2 expend l(1/3).(expend revenue grants) i.year, \ gmm(l.expend) iv(i.year) noleveleq twostep h(1) * Exact match: cumulative year-dummy variables forvalues y = 1980/1987 { gen yr`y'c = year >= `y' } xtabond2 expend l(1/3).(expend revenue grants) yr*c, \ gmm(l.expend) iv(yr*c) noleveleq twostep h(1) ``` -------------------------------- ### xtabond2: Default GMM-Style Instruments Source: https://context7.com/droodman/xtabond2/llms.txt This example shows the default behavior of gmmstyle() which uses all available lags in levels as instruments for the differenced equation. This is suitable for instrumenting predetermined and endogenous regressors. ```stata use "http://www.stata-press.com/data/r7/abdata.dta", clear * Default: use all available lags of L.n, w, k (instruments grow quadratically with T) xtabond2 n L.n L(0/1).(w k) yr1980-yr1984, \ gmm(L.(n w k)) \ iv(yr1980-yr1984) \ robust twostep small ``` -------------------------------- ### xtabond2: Limiting GMM Instrument Lags Source: https://context7.com/droodman/xtabond2/llms.txt Use the 'lag()' suboption within gmm() to limit the number of lags used as instruments, which helps reduce the instrument count. This example uses only lag 1 for the difference equation. ```stata * Limit lags to reduce instrument count: use only lag 1 for difference equation xtabond2 n L.n L(0/1).(w k) yr1978-yr1984, \ gmm(L.(n w k), lag(1 1)) \ iv(yr1978-yr1984, eq(level)) \ h(2) robust twostep ``` -------------------------------- ### Adjust Stata Memory Setting Source: https://context7.com/droodman/xtabond2/llms.txt If Mata encounters memory allocation errors ('unable to allocate real') during xtabond2 estimation, you can reduce Stata's overall memory allocation. Set a lower memory limit, for example, 'set memory 100m', and then retry the estimation. ```stata set memory 100m ``` -------------------------------- ### Configure Mata Memory/Speed Tradeoff Source: https://context7.com/droodman/xtabond2/llms.txt Control the memory and speed tradeoff for Mata, Stata's matrix programming language, used by xtabond2. Use 'mata set matafavor speed' for faster execution at the cost of more memory, or 'mata set matafavor space' for slower execution that uses less memory. These settings are persistent. ```stata mata: mata set matafavor speed, perm // faster, uses more memory ``` ```stata mata: mata set matafavor space, perm // slower, uses less memory ``` -------------------------------- ### Standard IV-Style Instruments with xtabond2 Source: https://context7.com/droodman/xtabond2/llms.txt Use `ivstyle()` to enter variables as conventional instrumental variables, suitable for strictly exogenous regressors. Options like `eq(level)` or `eq(diff)` specify the equation where the instrument is valid, and `passthru` prevents differencing of IV instruments. ```stata use "http://www.stata-press.com/data/r7/abdata.dta", clear * Year dummies as IV instruments in both equations (default eq = both) xtabond2 n L.n L(0/1).(w k) yr1980-yr1984, /// gmm(l.n w k) \ iv(yr1980-yr1984) \ noleveleq robust small ``` ```stata * eq(level): instrument valid only in levels equation (e.g., predetermined x) * eq(diff): instrument valid only in differenced equation xtabond2 n L.n L(0/1).(w k) yr1978-yr1984, /// gmm(L.(n w k)) \ iv(yr1978-yr1984, eq(level)) \ robust twostep ``` ```stata * passthru: prevent differencing of IV instruments for transformed equation xtabond2 n L.n L(0/1).(w k) yr1980-yr1984, /// gmm(l.n w k) \ iv(yr1980-yr1984, passthru) \ noleveleq robust small ``` ```stata * mz: replace missing instrument values with zeros so observations are not dropped xtabond2 n l.n l(0/1).(w k) yr1980-yr1984, /// gmm(l.n w k) \ iv(yr1980-yr1984, mz) \ robust twostep small h(2) ``` -------------------------------- ### Replicate Blundell-Bond (1998) bbest1.out Source: https://context7.com/droodman/xtabond2/llms.txt Reproduces `bbest1.out` from DPD for Ox (Blundell-Bond 1998) using difference GMM and system GMM. System GMM includes a split instrument group for levels equation testing. ```stata * Reproduce bbest1.out from DPD for Ox (Blundell-Bond 1998) clear all set matsize 800 use "http://www.stata-press.com/data/r7/abdata.dta" forvalues y = 1979/1984 { gen yr`y'c = year >= `y' } gen cons = year * Difference GMM (two-step robust) xtabond2 n L.n L(0/1).(w k) yr*c cons, \ gmm(L.(w k n)) iv(yr*c cons) \ noleveleq robust twostep * System GMM (two-step robust) with split instrument group for levels equation testing xtabond2 n L.n L(0/1).(w k) yr1978-yr1984, \ gmm(L.n, split) gmm(L.(w k)) \ iv(yr1978-yr1984, eq(level)) \ h(2) robust twostep ``` -------------------------------- ### Replicate Arellano-Bond (1991) Table 4 Source: https://context7.com/droodman/xtabond2/llms.txt Reproduces Table 4 from Arellano & Bond (1991) using one-step and two-step difference GMM. Requires cumulative year dummies for exact matching. ```stata * Reproduce Table 4 of Arellano & Bond (1991) clear all set matsize 800 use "http://www.stata-press.com/data/r7/abdata.dta" * Create cumulative year dummies (needed to exactly match DPD for Ox) forvalues y = 1979/1984 { gen yr`y'c = year >= `y' } gen cons = year * Column (a1): one-step robust difference GMM xtabond2 n L(0/1).(l.n w) l(0/2).(k ys) yr198?c cons, \ gmm(L.n) iv(L(0/1).w l(0/2).(k ys) yr198?c cons) \ noleveleq noconstant robust * Column (a2): two-step difference GMM xtabond2 n L(0/1).(l.n w) l(0/2).(k ys) yr198?c cons, \ gmm(L.n) iv(L(0/1).w l(0/2).(k ys) yr198?c cons) \ noleveleq noconstant twostep * Column (c): separate GMM groups for w and k with restricted lags xtabond2 n L(0/1).(l.n ys w) k yr198?c cons, \ gmm(L.n) gmm(w k, lag(2 3)) iv(L(0/1).ys yr198?c cons) \ noleveleq noconstant twostep ``` -------------------------------- ### Difference GMM (one-step, robust) in xtabond2 Source: https://context7.com/droodman/xtabond2/llms.txt Use this for one-step difference GMM estimation with robust standard errors. Ensure the dataset is tsset and specify regressors and instruments using gmmstyle() and ivstyle() options. ```stata * Load the classic Arellano-Bond employment dataset use "http://www.stata-press.com/data/r7/abdata.dta", clear * --- Difference GMM (one-step, robust) --- * Dependent variable: n (log employment) * Regressors: L.n (lag), current and lagged w and k, year dummies * GMM instruments: lags of L.n, w, k in levels (collapsed to limit instrument count) * IV instruments: year dummies (entered passthru, i.e., undifferenced) xtabond2 n L.n L(0/1).(w k) yr1980-yr1984, \ gmm(L.(n w k), collapse) \ iv(yr1980-yr1984, passthru) \ noleveleq robust small * Expected output: one-step difference GMM coefficients with robust SE, * F statistic, AR(1)/AR(2) tests, Sargan/Hansen tests ``` -------------------------------- ### Inspect Stored Results After xtabond2 Estimation Source: https://context7.com/droodman/xtabond2/llms.txt After running an xtabond2 model, use 'ereturn list' to see all stored results. Key scalars like 'e(N)' (number of observations) and 'e(hansen)' (Hansen J statistic) and macros like 'e(esttype)' (estimation type) are available for inspection. Coefficient and variance matrices are stored in 'e(b)' and 'e(V)'. ```stata xtabond2 n L.n L(0/1).(w k) yr1978-yr1984, /// gmm(L.(n w k), collapse) iv(yr1978-yr1984, eq(level)) /// h(2) robust twostep small ereturn list // shows all stored results // Key scalars display e(N) // number of observations display e(N_g) // number of groups (individuals) display e(j) // number of instruments used display e(hansen) // Hansen J statistic display e(hansenp) // p-value (H0: instruments exogenous; want p > 0.1) display e(ar2) // Arellano-Bond AR(2) test statistic display e(ar2p) // p-value (H0: no AR(2); want p > 0.05) display e(F) // F statistic (with small option) // Key macros display e(esttype) // "system" or "difference" display e(transform) // "first differences" or "orthogonal deviations" display e(vcetype) // "Robust" or "Corrected" (Windmeijer) display e(version) // xtabond2 version number // Coefficient matrix matrix list e(b) matrix list e(V) ``` -------------------------------- ### Post-Estimation Predictions with `predict` Source: https://context7.com/droodman/xtabond2/llms.txt After fitting `xtabond2`, use the `predict` command to compute fitted values or residuals. The `residuals` option computes the difference between actual and fitted values (u_it = n - bx_it), and the `difference` suboption requests predictions for the differenced equation. ```stata use "http://www.stata-press.com/data/r7/abdata.dta", clear xtabond2 n L.n L(0/1).(w k) yr1980-yr1984, /// gmm(L.(n w k), collapse) iv(yr1980-yr1984, passthru) \ noleveleq robust small * Fitted values (default: levels, xb = b*X_it) predict n_hat * n_hat contains bx_it for observations in the estimation sample * Residuals (u_it = n - bx_it) predict resid, residuals * Fitted values for the differenced equation predict n_hat_diff, xb difference * Inspect fit list id year n n_hat resid in 1/10 ``` -------------------------------- ### System GMM (two-step, Windmeijer-corrected) in xtabond2 Source: https://context7.com/droodman/xtabond2/llms.txt This snippet demonstrates two-step system GMM estimation with Windmeijer-corrected robust standard errors. It includes both differenced and levels equations and uses more instruments than difference GMM. ```stata * --- System GMM (two-step, Windmeijer-corrected robust SE) --- * Includes both the differenced and levels equations xtabond2 n L.n L(0/1).(w k) yr1978-yr1984, \ gmm(L.(n w k), collapse) \ iv(yr1978-yr1984, eq(level)) \ h(2) robust twostep small * Expected output: two-step system GMM with "Corrected" SE label, * more instruments than difference GMM, difference-in-Hansen tests ``` -------------------------------- ### xtabond2: Collapsing GMM Instruments Source: https://context7.com/droodman/xtabond2/llms.txt The 'collapse' suboption in gmm() creates one instrument per lag distance, rather than one per (lag, time) pair, significantly reducing the instrument count. This is useful for managing large numbers of instruments. ```stata * collapse: one instrument per lag distance instead of per (lag, time) pair xtabond2 n L.n L(0/1).(w k) yr1978-yr1984, \ gmm(L.(n w k), collapse) \ iv(yr1978-yr1984, eq(level)) \ h(2) robust twostep ``` -------------------------------- ### xtabond2: Splitting GMM Instruments for Tests Source: https://context7.com/droodman/xtabond2/llms.txt Use the 'split' suboption in gmm() to obtain separate difference-in-Hansen tests for instruments derived from the transformed (differenced) equation versus those from the levels equation. This aids in diagnosing instrument validity. ```stata * split: separate difference-in-Hansen tests for transformed vs. levels equation instruments xtabond2 n L.n L(0/1).(w k) yr1978-yr1984, \ gmm(L.n, split) gmm(L.(w k)) \ iv(yr1978-yr1984, eq(level)) \ h(2) robust twostep ``` -------------------------------- ### Two-Step Estimation with Windmeijer Correction Source: https://context7.com/droodman/xtabond2/llms.txt Use `twostep robust` for asymptotically more efficient two-step GMM estimation. This option triggers Windmeijer's (2005) finite-sample correction for standard errors, which are otherwise downward-biased. It is often more efficient than one-step robust estimation. ```stata use "http://www.stata-press.com/data/r7/abdata.dta", clear * One-step robust (baseline) xtabond2 n L.n L(0/1).(w k) yr1978-yr1984, /// gmm(L.(n w k), collapse) \ iv(yr1978-yr1984, eq(level)) \ robust small * VCE label: "Robust" ``` ```stata * Two-step with Windmeijer correction (preferred for efficiency) xtabond2 n L.n L(0/1).(w k) yr1978-yr1984, /// gmm(L.(n w k), collapse) \ iv(yr1978-yr1984, eq(level)) \ robust twostep small * VCE label: "Corrected" * Typically produces tighter, more reliable SE than one-step robust ``` -------------------------------- ### Save Internal Matrices with svmat and svvar Source: https://context7.com/droodman/xtabond2/llms.txt Use `svmat` to save internal matrices as `e()` macros for inspection. Use `svvar` to save the same data as Stata variables, enabling manual cross-checks with `ivreg` or `ivreg2`. ```stata use "http://www.stata-press.com/data/r7/abdata.dta", clear * Run system GMM saving internal matrices (requires Mata, matafavor speed) mata: mata set matafavor speed xtabond2 n L.n L(0/1).(w k) yr1978-yr1984, \ gmm(L.(n w k), collapse) \ iv(yr1978-yr1984, eq(level)) \ h(2) robust twostep svmat * Access saved matrices matrix list e(Z) // instrument matrix matrix list e(X) // regressors matrix list e(Y) // dependent variable column matrix list e(ideqt) // panel ID, equation (0=diff,1=level), time period * With svvar: save as Stata variables for manual ivreg cross-check xtabond2 n L.n L(0/1).(w k) yr1978-yr1984, \ gmm(L.(n w k), collapse) \ iv(yr1978-yr1984, eq(level)) \ h(1) robust svvar * Approximate the differenced equation manually: ivreg ydiff1 (xdiff* = zdiff*) if samplediff, nocons ``` -------------------------------- ### Single-Level Clustering by Panel ID Source: https://context7.com/droodman/xtabond2/llms.txt Use `cluster(id)` for single-level clustering by panel ID, which is equivalent to `robust` in one-step estimation. This option is useful when errors are correlated within panels. ```stata use "http://www.stata-press.com/data/r7/abdata.dta", clear * Single-level clustering by panel id (equivalent to robust in one-step) xtabond2 n L.n L(0/1).(w k) yr1980-yr1984, \ gmm(L.(n w k), collapse) iv(yr1980-yr1984, passthru) \ noleveleq cluster(id) small ``` -------------------------------- ### Instrument-Count Reduction with PCA Source: https://context7.com/droodman/xtabond2/llms.txt Use `pca` to replace GMM-style instruments with their principal components, reducing overfitting and weak Hansen test results. The `components(#)` option allows manual specification of the number of components. The `pca` option keeps components with an eigenvalue >= 1 by default. ```stata use "http://www.stata-press.com/data/r7/abdata.dta", clear * Unreduced instrument set (many instruments, potentially weak Hansen test) xtabond2 n L.n L(0/1).(w k) yr1978-yr1984, /// gmm(L.(n w k)) \ iv(yr1978-yr1984, eq(level)) \ h(2) robust twostep ``` ```stata * Reduce via PCA (keeps components with eigenvalue >= 1 by default) xtabond2 n L.n L(0/1).(w k) yr1978-yr1984, /// gmm(L.(n w k)) \ iv(yr1978-yr1984, eq(level)) \ h(2) robust twostep pca ``` ```stata * Manually specify 5 principal components xtabond2 n L.n L(0/1).(w k) yr1978-yr1984, /// gmm(L.(n w k)) \ iv(yr1978-yr1984, eq(level)) \ h(2) robust twostep pca components(5) * e(components) stores number selected; e(kmo) stores Kaiser-Meyer-Olkin measure ``` -------------------------------- ### Orthogonal Deviations Transform with xtabond2 Source: https://context7.com/droodman/xtabond2/llms.txt The `orthogonal` option uses the Arellano-Bover (1995) forward orthogonal deviations transform instead of first-differencing to remove fixed effects. This preserves sample size in unbalanced panels and can reduce finite-sample bias when T >= 10. Use the `orthog` suboption on `gmmstyle` along with the main `orthogonal` option. ```stata use "http://www.stata-press.com/data/r7/abdata.dta", clear * Standard difference GMM (first differencing) xtabond2 n L.n L(0/1).(w k) yr1979-yr1984, /// gmm(L.(n w k), lag(1 1) collapse) \ iv(yr1979-yr1984) \ noleveleq robust twostep ``` ```stata * Same model using orthogonal deviations (Hayakawa 2009 approach) * Use orthog suboption on gmmstyle AND the orthogonal main option together xtabond2 n L.n L(0/1).(w k) yr1979-yr1984, /// gmm(L.(n w k), lag(1 1) orthog) \ iv(yr1979-yr1984) \ h(2) robust twostep orthog noleveleq * Benefits: preserves observations with gaps; can reduce finite-sample bias (T >= 10) ``` -------------------------------- ### Multiway Clustering by ID and Year Source: https://context7.com/droodman/xtabond2/llms.txt Employ `cluster(id year)` for multiway clustering, accounting for correlation within both individuals and time periods. The correction multiplier uses the Cameron, Gelbach & Miller (2006) formula when combined with the `small` option. ```stata xtabond2 n w cap [pw=_n], \ iv(cap k ys, eq(level)) iv(rec, eq(level)) \ cluster(id year) h(1) * SE account for correlation both within individuals and within time periods * Correction multiplier uses Cameron, Gelbach & Miller (2006) formula when combined with small ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.