*! version 1.4.2 06feb2024

*! Sebastian Kripfganz, www.kripfganz.de

*! Vasilis Sarafidis, sites.google.com/view/vsarafidis

Title

xtivdfreg -- Defactored IV estimation of large panel data models

Syntax

xtivdfreg depvar [indepvars] [if] [in] [, options]

options

Model
* absorb(absvars) categorical variables that identify the fixed effects to be absorbed

iv(iv_spec) instruments; can be specified more than once

factmax(#) specify the maximum number of factors

[no]doubledefact implement a further defactorization stage of the entire model for the first-stage estimator

fstage use the first-stage instead of the second-stage estimator

mg compute the mean-group estimator

noconstant suppress constant term

Reporting
mg(#) display the group-specific estimates for group #

level(#) set confidence level; default is level(95)

noheader suppress output header

notable suppress coefficient table

display_options control

Optimization
noeigratio do not use the eigenvalue ratio test to determine the number of factors

std extract factors from standardized variables

# iterate(#) specifies maximum # of iterations

# ltolerance(#) tolerance for the objective function

# nodots do not display dots for the iteration steps

* This option requires the community-contributed packages reghdfe (version 6.12.3 or higher) and ftools (version 2.49.1 or higher) to be installed; see reghdfe and ftools.
absvars is a list of categorical variables to be absorbed.
Typical use is absorb(panelvar) or absorb(panelvar timevar) for one-way or two-way fixed effects, respectively.

# These options are only relevant for unbalanced panel data.

iv_spec is

varlist [, fvar(fvars) lags(#) factmax(#) [no]eigratio [no]std [no]doubledefact]

You must xtset your data before using xtivdfreg; see [XT] xtset.

All varlists may contain factor variables; see fvvarlist.

depvar and all varlists may contain time-series operators; see tsvarlist.

See xtivdfreg postestimation for features available after estimation.

xtivdfreg is a community-contributed program. The current version requires Stata version 13 or higher; see version history and updates.

Description

xtivdfreg implements the instrumental variables (IV) estimator for large panel data models, as developed by Norkute, Sarafidis, Yamagata, and Cui (2021) and Cui, Norkute, Sarafidis, and Yamagata (2022).
The instruments are defactored to control for a multifactor error structure. Heterogeneous slope coefficients can be allowed using a mean-group (MG) estimator.
The command accommodates unbalanced panel data and permits highly flexible instrumentation strategies. Examples in Kripfganz and Sarafidis (2021) illustrate several features of xtivdfreg.

An extension of the estimator to models with spatially lagged variables is implemented in spxtivdfreg.

Options

Model

absorb(absvars) specifies categorical variables that identify the fixed effects to be absorbed; see reghdfe (if installed).

iv(varlist [, fvar(fvars) lags(#) factmax(#) [no]eigratio [no]std [no]doubledefact]) specifies instrumental variables.
One can specify as many sets of instruments as required. Variables in the same set are defactored jointly. External variables that are not part of the regression model can also be used as instruments in varlist.

fvar(fvars) specifies that factors are extracted from the variables in fvars. The default is to extract factors from all variables in varlist.

lags(#) specifies the # of lags of varlist to be added to the set of instruments.
The variables at each lag order are defactored separately with factors extracted from the corresponding lag of fvars. The default is lags(0).

factmax(#) specifies the maximum number of factors to be extracted from fvars. The default is set by the global option factmax(#).

noeigratio and eigratio request to either use a fixed number of factors as specified with suboption factmax(#) or to use the Ahn and Horenstein (2013) eigenvalue ratio test to compute the number of factors.
eigratio is the default unless otherwise specified with the global option noeigratio.

std and nostd request to compute factors from either standardized or nonstandardized variables. nostd is the default unless otherwise specified with the global option std.

doubledefact requests to include fvars in a further defactorization stage of the entire model for the first-stage estimator. All sets of instruments that are included in this defactorization stage are jointly defactored,
excluding lags of fvars specified with suboption lags(#). nodoubledefact requests to avoid implementing a further defactorization stage of the entire model for the first-stage estimator.
The default is set by the global option [no]doubledefact.

factmax(#) specifies the maximum number of factors for each estimation stage and each set of instruments. The default is factmax(4).

doubledefact requests to implement a further defactorization stage of the entire model for the first-stage estimator. nodoubledefact requests to avoid implementing this further defactorization stage.
doubledefact is the default when option mg is specified, and nodoubledefact is the default when option mg is omitted.

fstage requests the first-stage IV estimator to be computed instead of the second-stage estimator.

mg requests the mean-group estimator to be computed that allows for heterogeneous slopes. Group-specific coefficients and standard errors are stored in matrices e(b_mg) and e(se_mg), respectively.
This option requires either option absorb(panelvar) or noconstant to be specified as well.

noconstant; see [R] estimation options.

Reporting

mg(#) requests to display the group-specific estimates for group # instead of the mean-group estimates. #.panelvar must identify a group in the estimation sample. This option implies option mg.

level(#); see [R] estimation options.

coeflegend; see [R] estimation options.

noheader suppresses display of the header above the coefficient table that displays the number of observations and moment conditions.

notable suppresses display of the coefficient table.

display_options: noci, nopvalues, noomitted, vsquish, noemptycells, baselevels, allbaselevels, nofvlabel, fvwrap(#), fvwrapon(style), cformat(%fmt),
pformat(%fmt), sformat(%fmt), and nolstretch; see [R] estimation options.

Optimization

noeigratio requests to use a fixed number of factors as specified with option factmax(#).
By default, the eigenvalue ratio test of Ahn and Horenstein (2013) is used to compute the number of factors for each estimation stage and each set of instruments.

std requests to compute factors from standardized variables (requires Stata version 16.1 or higher).

iterate(#) specifies the maximum number of iterations for the extraction of factors. If convergence is declared before this threshold is reached, it will stop when convergence is declared.
The default is the number set using set maxiter. This option has no effect with strongly balanced panel data, in which case any iterations are redundant.

ltolerance(#) specifies the convergence tolerance for the objective function; see [R] maximize. The default is ltolerance(1e-4). This option has no effect with strongly balanced panel data.

nodots requests not to display dots for the iteration steps. By default, one dot character is displayed for each iteration step. This option has no effect with strongly balanced panel data.

Remarks

For the model with homogeneous slopes, the first-stage IV estimator is asymptotically biased and therefore not recommended.
For the model with heterogeneous slopes, only the first-stage MG estimator is available because estimating factors based on residuals may be very inefficient; see the discussion below Theorem 4 in Norkute, Sarafidis, Yamagata, and Cui (2021)
and footnote 10 in Kripfganz and Sarafidis (2021).

Factors are extracted jointly from the matrix of all variables in fvars for any iv(varlist, fvar(fvars)) option. By default, fvars equals varlist.
To extract factors separately for different subsets of variables, multiple options should be specified, e.g. iv(varlist1) iv(varlist2).

For the model with heterogeneous slopes, the MG estimator applies a second defactorization stage for which factors are extracted jointly from the matrix of all fvars previously used in the first defactorization stage,
excluding lags specified with the lags(#) suboption. Variable sets can be excluded from this second defactorization stage with suboption nodoubledefact.

For the model with homogeneous slopes, by default only one defactorization stage is applied in the first estimation stage because the additional defactorization stage is asymptotically redundant when the second-stage IV estimator is used;
see footnote 20 in Norkute, Sarafidis, Yamagata, and Cui (2021) and footnote 7 in Kripfganz and Sarafidis (2021).
The additional defactorization stage can still be applied by specifying suboption doubledefact for at least one set of instruments.

Factors for the first defactorization stage are extracted separately for each lag number of a specified set of instruments if specified with the lags(#) suboption.
For example, iv(varlist, fvar(fvars) lags(2)) specifies that for each lag order # from 0 to 2,
L#.(varlist) is defactored with factors extracted from L#.(fvars).
However, the number of factors is restricted to be the same and, if different based on the Ahn and Horenstein (2013) algorithm, is chosen as the maximum of the numbers that are obtained separately for each lag.
The number of factors can differ across different sets of instruments if multiple iv() options are specified.

Principal-components analysis can be sensitive to the scale of the data. For this reason, the command allows to compute factors from standardized variables. The standardization is computed separately for each time period.
The global option option std switches on the standardization for all variables in both defactorization stages for the first-stage IV estimator.
For the first defactorization stage, this can be switched on or off separately for each set of instruments.

When the estimation sample is not strongly balanced, an iterative EM algorithm is applied to extract the factors, following Stock and Watson (1998) and Bai, Liao, and Yang (2015).
Separate iteration loops are performed for each factor extraction, highlighted by an iteration log with a dot character for each iteration step unless the option nodots is specified.
For example, the option iv(varlist, lags(2)) results in 3 separate iteration loops for varlist, L.(varlist), and L2.(varlist) (with an iteration log in that order).
If another option iv(varlist2, lags(2)) is specified, the same iteration procedure is repeated for varlist2.

When the additional defactorization stage is applied for the model with heterogeneous slopes, or this defactorization stage is requested with suboption doubledefact for the model with homogeneous slopes,
an additional iteration loop is performed jointly for varlist and varlist2, excluding lags specified with the lags(#) suboption.
Similarly, an additional iteration loop is performed for the factor extraction from the first-stage residuals when the second-stage IV estimator for the model with homogeneous slopes is computed.

The constant term is estimated as the mean of the residuals in a separate stage after computing the slope coefficients. For the model with heterogeneous slopes, the intercept is also treated as heterogeneous.
For this reason, either of the options absorb(panelvar) or noconstant must be specified together with option mg.
Whether a constant term is estimated or not has no effect on the computation of the slope coefficients because the latter are computed for the demeaned model, with or without the absorption of fixed effects.
The standard error of the constant term is computed using the influence-function approach of Kripfganz and Schwarz (2019).

Example

Setup for balanced panel data set, dynamic model

(The data set is available as an ancillary file for the xtivdfreg package.)

. use http://www.kripfganz.de/stata/xtivdfreg_example

Defactored IV estimation with two-way fixed effects, homogeneous slopes

. xtivdfreg L(0/1).CAR size ROA liquidity, absorb(id t) iv(size ROA liquidity, lags(2)) factmax(3)

Defactored IV estimation with two-way fixed effects, heterogeneous slopes

. xtivdfreg L(0/1).CAR size ROA liquidity, absorb(id t) iv(size ROA liquidity, lags(2)) factmax(3) mg

Replication of a 2SLS estimation without common shocks

. ivregress 2sls CAR size ROA liquidity (L.CAR = L(0/2).(size ROA liquidity)) i.id i.t, vce(cluster id)

. xtivdfreg L(0/1).CAR size ROA liquidity, absorb(id t) iv(size ROA liquidity, lags(2)) factmax(0) fstage

Setup for unbalanced panel data set, static model

. use http://www.stata-journal.com/software/sj12-1/st0246/manu_prod

Defactored IV estimation with two-way fixed effects, homogeneous slopes

. xtivdfreg ly lk, absorb(list year) iv(lk, lags(2)) factmax(3)

Defactored IV estimation with two-way fixed effects, heterogeneous slopes

. xtivdfreg ly lk, absorb(list year) iv(lk, lags(2)) factmax(3) mg

See Kripfganz and Sarafidis (2021) for a detailed discussion of these examples.

Saved results

xtivdfreg saves the following in e():

Scalars

e(N) number of observations

e(df_m) model degrees of freedom

e(N_g) number of groups

e(g_min) smallest group size

e(g_avg) average group size

e(g_max) largest group size

e(sigma2u) variance of error term u_it = f_it + e_it

e(sigma2f) variance of factor error component f_it

e(rho) fraction of variance due to factor component

e(chi2_J) Hansen's J-statistic

e(df_J) degrees of freedom of Hansen's J-test

e(p_J) p-value of Hansen's J-test

e(rank) rank of e(V)

e(zrank) number of instruments

e(fact1) number of factors in the first stage

e(fact2) number of factors in the second stage

e(mg_id) group ID for displayed group-specific estimates; not always saved

Macros

e(cmd) xtivdfreg

e(cmdline) command as typed

e(ivar) variable denoting groups

e(tvar) variable denoting time

e(estat_cmd) xtivdfreg_estat

e(predict) xtivdfreg_p

e(marginsok) predictions allowed by margins

e(vcetype) title used to label Std. Err.

e(estimator) fstage, sstage, or mg

e(properties) b V

e(depvar) name of dependent variable

Matrices

e(b) coefficient vector

e(V) variance-covariance matrix of the estimators

e(factnum) variable-specific number of factors in the first stage

e(b_mg) matrix of group-specific coefficients; not always saved

e(se_mg) matrix of group-specific standard errors; not always saved

Functions

e(sample) marks estimation sample

Version history and updates

xtivdfreg is a community-contributed program. To determine the currently installed version, type

. which xtivdfreg, all

To update the xtivdfreg package to the latest version, type

. //www.kripfganz.de/stata/") replace"'

If the connection to the previous website fails, alternatively type

. ssc install xtivdfreg, replace

The SSC version is less frequently updated and may not be the latest available version. The current version of the xtivdfreg package requires Stata version 13 or higher. Some options require a more recent version.

Authors

Sebastian Kripfganz, University of Exeter, http://www.kripfganz.de

Vasilis Sarafidis, Brunel University London, https://sites.google.com/view/vsarafidis

Acknowledgements

xtivdfreg is not an official Stata command. It is a free contribution to the research community. Please cite Kripfganz and Sarafidis (2021), as provided in the references list just below.

References

Ahn, S. C., and A. R. Horenstein. 2013.
Eigenvalue ratio test for the number of factors.
Econometrica 81: 1203-1227.

Bai, J., Y. Liao, and J. Yang. 2015.
Unbalanced panel data models with interactive effects.
In: The Oxford Handbook of Panel Data, ed. B. H. Baltagi. Oxford University Press: 149-170.

Cui, G., M. Norkute, V. Sarafidis, and T. Yamagata. 2022.
Two-stage instrumental variable estimation of linear panel data models with interactive effects.
Econometrics Journal 25: 340-361.

Kripfganz, S., and V. Sarafidis. 2021.
Instrumental-variable estimation of large-T panel-data models with common factors.
Stata Journal 21: 659-686.

Kripfganz, S., and C. Schwarz. 2019.
Estimation of linear dynamic panel data models with time-invariant regressors.
Journal of Applied Econometrics 34: 526-546.

Norkute, M., V. Sarafidis, T. Yamagata, and G. Cui. 2021.
Instrumental variable estimation of dynamic linear panel data models with defactored regressors and a multifactor error structure.
Journal of Econometrics 220: 416-446.

Stock, J. H., and M. W. Watson. 1998.
Diffusion indexes.
NBER Working Paper 6702.