*! version 1.2 29nov2023
help xtnumfac

Title

xtnumfac Estimate the number of factors in time series and panel data

Syntax

xtnumfac
[varlist]
[if] [in]
[, options]

Main
kmax(#) Consider at most # factors; default is kmax(8).

detail Report detailed results.

standardize(#) Demean and/or rescale data. Default is stan(1) for neither demeaning nor rescaling.

Description

xtnumfac Estimates the number of factors in the variables varlist, observed in a large-dimensional panel dataset, by obtaining and reporting the estimators of Bai and Ng
(2002), Ahn and Horenstein (2013), Onatski (2010) and Gagliardini et al. (2019).
Data must be tsset or xtset.
In case of unbalanced panels, xtnumfac internally fills in the gaps using tsfill.
Missing values are imputed following Stock and Watson (1998) and Bai et al. (2015).
varlist may contain time-series operators, see tsvarlist.

Options

Main

kmax(#) specifies how many factors to consider at most when estimating its true number. The default is kmax(8). The choice of kmax
mostly affects the length of the reported table of results. Additionally, the
values of the PC_, PC_ and PC_ statistics may be slightly affected since
they are functions of an estimated error variance in the idiosyncratic component
which is obtained from the most general model (i.e. the one with kmax factors).

detail allows to report extended result that show the exact values assumed by each criterion function when
0,1,..., kmax factors are estimated. The estimator of Onatski (2010) is left out from this representation
in order to avoid confusion about how the estimated number of factors is obtained from a list of potential values.

standardize(#) implements variable transformations prior to factor estimation. The following options are available:

1: No transformations

2: Remove individual fixed effects

3: Remove individual fixed effects and standardize variance of each cross-section to 1

4: Remove individual and time fixed effects

5: Remove individual&time fixed effects and standardize variance of each cross-section to 1

Remarks

The methods of Bai and Ng (2002), Ahn and Horenstein (2013), Onatski (2010) and Gagliardini et al. (2019)
constitute four sets of estimators that rely on different mechanisms and that need to be
interpreted differently. The six ICs of Bai and Ng (2002) are based on an
adjustment to the sum of squared residuals which corrects for the optimism of the
training error. Accordingly, the estimated number of factors is determined by the
minimum IC value among all numbers of factors under consideration.
By contrast, the two estimators of Ahn and Horenstein rely on the ratio between
two subsequent eigenvalues (ER) or their growth rates (GR). Accordingly, the
estimated number of factors is determined by the maximum ER or GR criterion,
respectively.
Third, the ED (edge distribution) estimator of Onatski (2010) is based on the difference
of two successive eigenvalues. Determining the number of factors is not achieved by picking the extremum
in a list of options. Instead, a threshold is determined from the data and the eigenvalue differences
exceeding this differences are targeted. This procedure is iterated to convergence with an updated list of eigenvalues and an updated threshold.
Lastly, the diagnostic criterion of Gagliardini et al. (2019) considers the decreasing sequence of eigenvalues minus a correction term.
It chooses the number of factors as one less than the position of the earliest negative corrected eigenvalue in that series.
The criterion shows kmax+1 factors if no negative corrected eigenvalue is found.

Contact

Questions, Comments, Suggestions? Please let us know.

Simon Reese
Associate Senior Lecturer, Lund University
simon.reese@nek.lu.se

Jan Ditzen
Free University of Bozen-Bolzano
jan.ditzen@unibz.it

Examples

The following example uses the file KPR2021_hpdata which is downloaded together
with the package and which is taken from the first empirical example in Kapetanios et al. (2021)

. use KPR2021_hpdata

. xtnumfac d_lrhp, kmax(10)

. xtnumfac rd_lrhp, stan(5) detail

Stored results

xtnumfac stores the following in e():

Scalars

e(N) Number of cross-sections.

e(T) Number of time periods.

e(kmax) Maximum number of factors considered.

e(missnum) Number of missing values which are imputed.

Matrices

e(best_numfac) A (1 x 8) matrix containing the number of factors
estimated by any of the 8 criteria. The order is as in the reported function
output.

e(allICs) A (kmax x 8) matrix containing the value of all measures for all numbers of
factors under consideration. Corresponds to the values in the reported function
output (albeit without asterisks).

References

Ahn, S. C., & Horenstein, A. R. (2013). Eigenvalue ratio test for the number of factors. Econometrica, 81(3), 1203-1227.

Bai, J., & Ng, S. (2002). Determining the number of factors in approximate factor models. Econometrica, 70(1), 191-221.

Bai, J., Y. Liao, & Jisheng Yang. 2015. Unbalanced Panel Data Models with Interactive Effects. In The Oxford Handbook of Panel Data, 149–170

Gagliardini, P., Ossola, E., & Scaillet, O. (2019). A diagnostic criterion for approximate factor structure. Journal of Econometrics, 212(2), 503-521.

Kapetanios, G., Pesaran, M.H., & Reese, S. (2021). Detection of units with pervasive effects in large panel data models. Journal of Econometrics, 221(2), 510-541.

Onatski, A. 2010. Determining the Number of Factors from Empirical Distribution of Eigenvalues. The Review of Economics and Statistics, 92(4): 1004–1016.

Stock, J. H., and M. W. Watson. 1998. Diffusion Indexes. NBER Working Paper (w6702).