| Title: | Interactive Fixed Effects Estimator for Panel Data |
|---|---|
| Description: | Implements the interactive fixed effects ('IFE') panel estimator of Bai (2009) <doi:10.3982/ECTA6135> for balanced and unbalanced panels, with optional additive unit and/or time fixed effects. Provides analytical standard errors ('homoskedastic', 'HC1' heteroskedasticity-robust, cluster-robust by unit, and heteroskedasticity- and autocorrelation- consistent), together with asymptotic incidental-parameter bias correction for large panels, including a dynamic extension for predetermined (lagged-dependent) regressors following Moon and Weidner (2017) <doi:10.1017/S0266466615000328>. The number of factors is chosen by information criteria (Bai and Ng 2002 <doi:10.1111/1468-0262.00273>) or by singular value thresholding. Unbalanced panels are handled by an expectation-maximisation algorithm with nuclear-norm-regularised initialisation, with estimation, analytical inference, and bias correction following Su, Wang and Wang (2025) <doi:10.2139/ssrn.5177283> and building on the matrix-completion and missing-data factor analysis of Bai and Ng (2021) <doi:10.1080/01621459.2021.1967163>. All computations use base R only, with no external dependencies. |
| Authors: | Binzhi Chen [aut, cre] |
| Maintainer: | Binzhi Chen <[email protected]> |
| License: | GPL-2 | GPL-3 |
| Version: | 0.1.4 |
| Built: | 2026-07-22 22:49:03 UTC |
| Source: | https://github.com/cran/xtife |
Balanced panel of cigarette sales and prices across 46 US states for 30 years (1963–1992). Originally used in Baltagi (1995) and widely used as a benchmark dataset for panel estimators.
cigarcigar
A data frame with 1,380 rows and 9 variables:
US state identifier (integer, 1–46)
year (integer, 1963–1992)
cigarette price index
state population
population aged 16 and over
consumer price index
per-capita disposable income
per-capita cigarette sales (packs per person per year)
minimum cigarette price in adjoining states
Baltagi, B.H. (1995) Econometric Analysis of Panel Data. Wiley. Distributed with the plm R package (Croissant and Millo 2008).
Baltagi, B.H. (1995). Econometric Analysis of Panel Data. Wiley.
Croissant, Y. and Millo, G. (2008). Panel data econometrics in R: the plm package. Journal of Statistical Software, 27(2), 1–43. doi:10.18637/jss.v027.i02
Fits the panel model
for balanced panel data with analytical standard errors.
ife( formula, data, index, r = 1L, force = "two-way", se = "standard", bias_corr = FALSE, method = "static", M1 = 1L, tol = 1e-09, max_iter = 10000L )ife( formula, data, index, r = 1L, force = "two-way", se = "standard", bias_corr = FALSE, method = "static", M1 = 1L, tol = 1e-09, max_iter = 10000L )
formula |
R formula: |
data |
data.frame in long format (one row per unit-time observation) |
index |
character(2): |
r |
integer >= 0, number of interactive factors (default 1) |
force |
additive FE specification: |
se |
SE type: |
bias_corr |
logical; if |
method |
|
M1 |
integer; lag bandwidth for the B1 dynamic bias term
(default |
tol |
convergence tolerance (default |
max_iter |
maximum iterations (default |
An S3 object of class "ife" with the following components:
coef – named p-vector of estimated coefficients
vcov – p x p variance-covariance matrix
se – named p-vector of standard errors
tstat – named p-vector of t-statistics
pval – named p-vector of two-sided p-values
ci – p x 2 matrix of 95% confidence intervals (CI.lower, CI.upper)
table – data.frame coefficient table (Estimate, Std.Error, t.value, Pr.t, CI.lower, CI.upper)
F_hat – T x r estimated factor matrix
Lambda_hat – N x r estimated loading matrix
residuals – T x N residual matrix (full model)
sigma2 – estimated error variance
df – residual degrees of freedom
n_iter – iterations to convergence
converged – logical
N, T, r, force, se_type – model dimensions and options
call – matched call
Bai, J. (2009). Panel data models with interactive fixed effects. Econometrica, 77(4), 1229–1279. doi:10.3982/ECTA6135
Moon, H.R. and Weidner, M. (2017). Dynamic linear panel regression models with interactive fixed effects. Econometric Theory, 33, 158–195. doi:10.1017/S0266466615000328
Bai, J. and Ng, S. (2002). Determining the number of factors in approximate factor models. Econometrica, 70(1), 191–221. doi:10.1111/1468-0262.00273
data(cigar, package = "xtife") fit <- ife(sales ~ price, data = cigar, index = c("state", "year"), r = 2, force = "two-way", se = "standard") print(fit)data(cigar, package = "xtife") fit <- ife(sales ~ price, data = cigar, index = c("state", "year"), r = 2, force = "two-way", se = "standard") print(fit)
Fits the IFE model for r = 0, 1, ..., r_max and evaluates
five information criteria at each value of r. Returns IC1, IC2, and IC3
from Bai and Ng (2002) Proposition 1, applied to IFE residuals per Bai
(2009) Section 9.4, plus a BIC-style penalty (IC_bic) and a
small-sample-corrected prediction criterion (PC) from Bai (2009).
The criterion-minimising r for each IC is flagged with "*" in the
printed table, and a data-driven recommendation (favouring IC_bic when
the Bai-Ng criteria decrease monotonically) is displayed.
ife_select_r( formula, data, index, r_max = NULL, force = "two-way", verbose = TRUE, tol = 1e-09, max_iter = 10000L )ife_select_r( formula, data, index, r_max = NULL, force = "two-way", verbose = TRUE, tol = 1e-09, max_iter = 10000L )
formula |
R formula passed to |
data |
long-format data.frame |
index |
character(2): |
r_max |
maximum r to consider (default: |
force |
additive FE type (default |
verbose |
logical; if |
tol |
convergence tolerance (default |
max_iter |
maximum iterations (default |
(invisibly) a data.frame with columns r, V_r, IC1, IC2,
IC3, IC_bic, PC, converged, and attribute "suggested" (named
integer vector giving the IC-minimising r for each criterion).
Bai, J. (2009). Panel data models with interactive fixed effects. Econometrica, 77(4), 1229–1279. doi:10.3982/ECTA6135
Bai, J. and Ng, S. (2002). Determining the number of factors in approximate factor models. Econometrica, 70(1), 191–221. doi:10.1111/1468-0262.00273
data(cigar, package = "xtife") sel <- ife_select_r(sales ~ price, data = cigar, index = c("state", "year"), r_max = 4)data(cigar, package = "xtife") sel <- ife_select_r(sales ~ price, data = cigar, index = c("state", "year"), r_max = 4)
Estimates the number of interactive factors in an unbalanced panel by the singular value thresholding (SVT) rule of Su, Wang and Wang (2025), applied to the nuclear-norm-regularised (soft-imputed) matrix — a missing-data counterpart of the information-criterion rules of Bai and Ng (2002).
ife_select_r_unb(formula, data, index, c_f = 0.6, nu_NT = NULL, verbose = TRUE)ife_select_r_unb(formula, data, index, c_f = 0.6, nu_NT = NULL, verbose = TRUE)
formula |
R formula: |
data |
Data frame in long format. |
index |
Character vector of length 2: |
c_f |
SVT threshold constant (default 0.6). |
nu_NT |
Optional scalar or vector of NNR penalty values. If
|
verbose |
Logical; print result table. Default |
Invisibly returns a list with components r_hat, sv
(normalised singular values), threshold, c_f,
c_NT, and nu_used.
Su, L., Wang, F. and Wang, Y. (2025). Estimation and inference for interactive fixed effects panel data models with unbalanced panels. SSRN Working Paper No. 5177283. doi:10.2139/ssrn.5177283
Bai, J. and Ng, S. (2002). Determining the number of factors in approximate factor models. Econometrica, 70(1), 191–221. doi:10.1111/1468-0262.00273
Bai, J. and Ng, S. (2021). Matrix completion, counterfactuals, and factor analysis of missing data. Journal of the American Statistical Association, 116(536), 1746–1763. doi:10.1080/01621459.2021.1967163
data(cigar, package = "xtife") set.seed(42) cigar_unb <- cigar[sample(nrow(cigar), 1200L), ] ife_select_r_unb(sales ~ price, data = cigar_unb, index = c("state", "year"))data(cigar, package = "xtife") set.seed(42) cigar_unb <- cigar[sample(nrow(cigar), 1200L), ] ife_select_r_unb(sales ~ price, data = cigar_unb, index = c("state", "year"))
Fits the interactive fixed effects model
for unbalanced panels (units observed at different sets of time periods),
where the additive unit effects and time effects
are controlled by force. The estimation and inference theory follows
Su, Wang and Wang (2025). Estimation uses an alternating outer loop
that updates and the structure , with an expectation-maximisation (EM) inner loop —
in the spirit of Bai (2009, Appendix B) and the missing-data factor /
matrix-completion framework of Bai and Ng (2021) — that imputes the
unobserved cells from the current structure and re-estimates the additive
and interactive components on the completed panel. An optional
nuclear-norm-regularised (soft-impute) warm start (Mazumder, Hastie and
Tibshirani 2010) is available via init = "nnr".
ife_unbalanced( formula, data, index, r = 1L, force = "none", se = "standard", init = "ols", bias_corr = FALSE, exog = "strict", L_T = NULL, c_f = 0.6, nu_NT = NULL, tol = 1e-09, max_iter = 10000L, tol_em = 1e-07, max_iter_em = 500L )ife_unbalanced( formula, data, index, r = 1L, force = "none", se = "standard", init = "ols", bias_corr = FALSE, exog = "strict", L_T = NULL, c_f = 0.6, nu_NT = NULL, tol = 1e-09, max_iter = 10000L, tol_em = 1e-07, max_iter_em = 500L )
formula |
R formula: |
data |
Data frame in long format (one row per observed unit-time pair). |
index |
Character vector of length 2: |
r |
Positive integer. Number of interactive factors (default 1). |
force |
Additive fixed effects to remove jointly with the factors:
|
se |
SE type: |
init |
Initialisation method: |
bias_corr |
Logical. Apply the analytical incidental-parameter bias
correction. Supports both strictly and weakly exogenous regressors
(controlled by |
exog |
Exogeneity assumption: |
L_T |
Bartlett kernel bandwidth for HAC standard errors ( |
c_f |
Singular-value-thresholding constant (default 0.6) used for
factor-number selection. Used only when |
nu_NT |
NNR penalty grid. If |
tol |
Outer-loop convergence tolerance on
|
max_iter |
Maximum outer-loop iterations. Default |
tol_em |
Inner EM convergence tolerance. Default |
max_iter_em |
Maximum inner EM iterations per outer step.
Default |
Inference. Standard errors use a sandwich estimator on factor-projected regressors (the unbalanced analogue of the balanced formula of Bai 2009), following Su, Wang and Wang (2025), with heteroskedasticity-robust, cluster-robust (Arellano 1987; Cameron, Gelbach and Miller 2011) and HAC (Newey and West 1987) variants. The optional analytical bias correction of Su, Wang and Wang (2025) removes the leading incidental-parameter bias, extending the corrections of Bai (2009) and Moon and Weidner (2017) to the unbalanced and predetermined-regressor case.
Additive fixed effects. With force = "none" (default) the model
is intercept-free and all heterogeneity is carried by the interactive
factors. Setting force = "unit", "time" or "two-way"
estimates the additive effects jointly with the factors by demeaning the
imputed (completed) panel inside the EM loop, which is robust to
informative missingness; the degrees-of-freedom adjustment is propagated to
the standard errors.
An S3 object of class "ife_unb" with components:
Named p-vector of estimated coefficients
(bias-corrected when bias_corr = TRUE).
Named p-vector of uncorrected coefficients (only when
bias_corr = TRUE).
p x p variance-covariance matrix.
Named p-vector of standard errors.
Named p-vector of t-statistics.
Named p-vector of two-sided p-values.
p x 2 matrix of 95 percent confidence intervals.
Data frame coefficient table.
TT x r estimated factor matrix (normalised F'F/TT = I_r).
N x r estimated loading matrix.
n_obs numeric vector of full-model residuals at observed cells.
Estimated error variance ().
Residual degrees of freedom.
Number of observed unit-time cells.
Outer-loop iterations to convergence.
Logical.
Model dimensions and options.
Options used.
Bias components (only when
bias_corr = TRUE). b2 is a zero vector when
exog = "strict".
Variable names.
Unique unit and time identifiers.
Integer index vectors for residuals.
Matched call.
Su, L., Wang, F. and Wang, Y. (2025). Estimation and inference for interactive fixed effects panel data models with unbalanced panels. SSRN Working Paper No. 5177283. doi:10.2139/ssrn.5177283
Bai, J. (2009). Panel data models with interactive fixed effects. Econometrica, 77(4), 1229–1279. doi:10.3982/ECTA6135
Bai, J. and Ng, S. (2021). Matrix completion, counterfactuals, and factor analysis of missing data. Journal of the American Statistical Association, 116(536), 1746–1763. doi:10.1080/01621459.2021.1967163
Mazumder, R., Hastie, T. and Tibshirani, R. (2010). Spectral regularization algorithms for learning large incomplete matrices. Journal of Machine Learning Research, 11, 2287–2322.
Moon, H. R. and Weidner, M. (2017). Dynamic linear panel regression models with interactive fixed effects. Econometric Theory, 33, 158–195. doi:10.1017/S0266466615000328
data(cigar, package = "xtife") # Drop ~10 % of rows to create an unbalanced panel set.seed(1) cigar_unb <- cigar[sample(nrow(cigar), 1200L), ] fit <- ife_unbalanced(sales ~ price, data = cigar_unb, index = c("state", "year"), r = 2L) print(fit)data(cigar, package = "xtife") # Drop ~10 % of rows to create an unbalanced panel set.seed(1) cigar_unb <- cigar[sample(nrow(cigar), 1200L), ] fit <- ife_unbalanced(sales ~ price, data = cigar_unb, index = c("state", "year"), r = 2L) print(fit)
Prints a formatted summary of an object of class "ife",
including panel dimensions, number of factors, additive fixed effect
specification, SE type, and a coefficient table with standard errors,
t-statistics, p-values, and 95% confidence intervals. If bias correction
was applied, bias terms are also reported. Information criteria are printed
when the object contains them (i.e., when called from ife_select_r()).
## S3 method for class 'ife' print(x, digits = 4, ...)## S3 method for class 'ife' print(x, digits = 4, ...)
x |
an object of class |
digits |
number of significant digits (default 4) |
... |
unused |
x invisibly.
data(cigar, package = "xtife") fit <- ife(sales ~ price, data = cigar, index = c("state", "year"), r = 2, force = "two-way", se = "standard") print(fit)data(cigar, package = "xtife") fit <- ife(sales ~ price, data = cigar, index = c("state", "year"), r = 2, force = "two-way", se = "standard") print(fit)