| Type: | Package |
| Title: | Panel Fixed Effects Filtered and Variance Decomposition Estimation |
| Version: | 1.0.2 |
| Description: | Implements fixed effects estimators for time-invariant variables in panel data models. Provides three estimation methods: FEVD (Fixed Effects Vector Decomposition) from Plumper and Troeger (2007) <doi:10.1093/pan/mpm002>, and FEF (Fixed Effects Filtered) and FEF-IV (instrumental variables variant) from Pesaran and Zhou (2018) <doi:10.1080/07474938.2016.1222225>. All methods use the correct Pesaran-Zhou variance estimators that account for generated regressor uncertainty, avoiding the size distortions documented in the literature. |
| License: | GPL-3 |
| URL: | https://github.com/muhammedalkhalaf/xtfifevd |
| BugReports: | https://github.com/muhammedalkhalaf/xtfifevd/issues |
| Encoding: | UTF-8 |
| RoxygenNote: | 7.3.3 |
| Depends: | R (≥ 4.1.0) |
| Imports: | stats, MASS |
| Suggests: | plm, lmtest, sandwich, testthat (≥ 3.0.0), knitr, rmarkdown |
| Config/testthat/edition: | 3 |
| NeedsCompilation: | no |
| Packaged: | 2026-04-27 19:31:03 UTC; acad_ |
| Author: | Muhammad Alkhalaf |
| Maintainer: | Muhammad Alkhalaf <muhammedalkhalaf@gmail.com> |
| Repository: | CRAN |
| Date/Publication: | 2026-04-28 20:30:02 UTC |
xtfifevd: Panel Fixed Effects Filtered and Variance Decomposition Estimation
Description
Implements fixed effects estimators for time-invariant variables in panel data models. Standard fixed effects (FE) estimation cannot identify coefficients on time-invariant regressors because they are collinear with the individual fixed effects. This package provides three methods to estimate these coefficients:
Methods
- FEVD
Fixed Effects Vector Decomposition (Plümper & Troeger, 2007). A three-stage estimator that decomposes the unit effects into explained (by time-invariant variables) and unexplained components.
- FEF
Fixed Effects Filtered (Pesaran & Zhou, 2016). A two-stage estimator that regresses time-averaged FE residuals on time-invariant variables.
- FEF-IV
Fixed Effects Filtered with Instrumental Variables (Pesaran & Zhou, 2016). Uses external instruments when time-invariant variables are endogenous.
Variance Estimation
All methods use the Pesaran-Zhou (2016) variance estimator (Equation 17 for FEF/FEVD, Equation 51 for FEF-IV). These correct variance estimators account for the generated regressor problem and avoid the severe size distortions documented for naive pooled OLS standard errors.
Author(s)
Maintainer:
References
Plumper, T., & Troeger, V. E. (2007). Efficient Estimation of Time-Invariant and Rarely Changing Variables in Finite Sample Panel Analyses with Unit Fixed Effects. Political Analysis, 15(2), 124-139. doi:10.1093/pan/mpm002
Pesaran, M. H., & Zhou, Q. (2018). Estimation of time-invariant effects in static panel data models. Econometric Reviews, 37(10), 1137-1171. doi:10.1080/07474938.2016.1222225
Greene, W. H. (2011). Fixed Effects Vector Decomposition: A Magical Solution to the Problem of Time-Invariant Variables in Fixed Effects Models? Political Analysis, 19(2), 135-146. doi:10.1093/pan/mpq034
Between/Within Variance Ratio for Time-Invariant Variables
Description
Computes the between-panel and within-panel standard deviations for specified variables, along with their ratio. This diagnostic helps assess whether FEVD/FEF methods may improve upon standard FE estimation.
Usage
bw_ratio(data, variables, id)
Arguments
data |
A data frame containing the panel data. |
variables |
A character vector of variable names to analyze. |
id |
Character string naming the panel identifier variable. |
Details
For truly time-invariant variables, the within-panel SD should be zero (or near-zero due to numerical precision), giving an infinite ratio.
According to Plümper and Troeger (2007), FEVD/FEF methods tend to improve upon standard FE when:
The between/within ratio exceeds approximately 1.7
The correlation between z and the unobserved unit effect is not too high
Value
A data frame with columns:
- variable
Variable name
- sd_between
Between-panel standard deviation
- sd_within
Within-panel standard deviation
- bw_ratio
Ratio of between to within SD
References
Plumper, T., & Troeger, V. E. (2007). Efficient Estimation of Time-Invariant and Rarely Changing Variables in Finite Sample Panel Analyses with Unit Fixed Effects. Political Analysis, 15(2), 124-139. doi:10.1093/pan/mpm002
Examples
# Create example data
set.seed(42)
N <- 50
T <- 5
id <- rep(1:N, each = T)
z_invariant <- rep(rnorm(N), each = T) # Truly time-invariant
z_slow <- rep(rnorm(N), each = T) + rnorm(N * T, sd = 0.1) # Slowly varying
x_varying <- rnorm(N * T) # Time-varying
data <- data.frame(id = id, z_inv = z_invariant,
z_slow = z_slow, x = x_varying)
bw_ratio(data, c("z_inv", "z_slow", "x"), id = "id")
Internal estimation functions
Description
Internal estimation functions
Panel Fixed Effects Estimation for Time-Invariant Variables
Description
Estimates panel models with time-invariant regressors using FEVD, FEF, or FEF-IV methods. Standard fixed effects estimation cannot identify coefficients on time-invariant variables; these methods decompose or filter the unit effects to recover these coefficients.
Usage
xtfifevd(
formula,
data,
id,
time,
method = c("fevd", "fef", "fef_iv"),
instruments = NULL,
na.action = na.omit
)
fevd(formula, data, id, time, na.action = na.omit)
fef(formula, data, id, time, na.action = na.omit)
fef_iv(formula, data, id, time, instruments, na.action = na.omit)
Arguments
formula |
A formula of the form |
data |
A data frame containing the variables. |
id |
Character string naming the panel (individual) identifier variable. |
time |
Character string naming the time identifier variable. |
method |
Estimation method: |
instruments |
For |
na.action |
How to handle missing values. Default is |
Details
Model
The panel model is:
y_{it} = \alpha_i + x_{it}'\beta + z_i'\gamma + \varepsilon_{it}
where x_{it} are time-varying regressors, z_i are time-invariant
regressors, and \alpha_i are individual fixed effects.
Stage 1 (All Methods)
Fixed effects regression of y_{it} on x_{it} yields consistent
\hat{\beta} and combined residuals \hat{u}_{it} = \hat{\alpha}_i + \hat{\varepsilon}_{it}.
Stage 2
Time-averaged residuals \bar{u}_i are regressed on z_i:
-
FEF: OLS of
\bar{u}_ionz_iwith intercept -
FEF-IV: 2SLS using instruments
r_i -
FEVD: Same as FEF, then Stage 3 pooled OLS (point estimates identical)
Variance Estimation
Uses Pesaran-Zhou (2016) Equation 17/51 which properly accounts for estimation uncertainty from Stage 1. The naive pooled OLS standard errors from FEVD Stage 3 are inconsistent and can understate true SEs by factors of 2-5x or more.
Value
An object of class "xtfifevd" containing:
- coefficients
Named vector of all coefficients (beta, gamma, intercept)
- vcov
Variance-covariance matrix using Pesaran-Zhou estimator
- beta
Coefficients on time-varying variables (from FE stage)
- gamma
Coefficients on time-invariant variables
- intercept
Overall intercept
- residuals
Idiosyncratic residuals from FE stage
- fitted.values
Fitted values
- sigma2_e
Variance of idiosyncratic error
- sigma2_u
Variance of unit effects
- N
Total number of observations
- N_g
Number of groups (panels)
- T_bar
Average time periods per panel
- method
Estimation method used
- call
The matched call
Functions
-
fevd: FEVD estimation (3-stage, Plümper-Troeger) -
fef: FEF estimation (2-stage, Pesaran-Zhou) -
fef_iv: FEF-IV estimation with instruments
References
Plumper, T., & Troeger, V. E. (2007). Efficient Estimation of Time-Invariant and Rarely Changing Variables in Finite Sample Panel Analyses with Unit Fixed Effects. Political Analysis, 15(2), 124-139. doi:10.1093/pan/mpm002
Pesaran, M. H., & Zhou, Q. (2018). Estimation of time-invariant effects in static panel data models. Econometric Reviews, 37(10), 1137-1171. doi:10.1080/07474938.2016.1222225
See Also
Examples
# Simulate panel data
set.seed(123)
N <- 100 # panels
T <- 10 # time periods
n <- N * T
# Generate data
id <- rep(1:N, each = T)
time <- rep(1:T, N)
alpha_i <- rep(rnorm(N), each = T) # Fixed effects
z <- rep(rnorm(N), each = T) # Time-invariant
x <- rnorm(n) # Time-varying
y <- 1 + 2 * x + 0.5 * z + alpha_i + rnorm(n, sd = 0.5)
data <- data.frame(id = id, time = time, y = y, x = x, z = z)
# Estimate with different methods
fit_fevd <- xtfifevd(y ~ x | z, data = data, id = "id", time = "time")
summary(fit_fevd)
fit_fef <- xtfifevd(y ~ x | z, data = data, id = "id", time = "time",
method = "fef")
summary(fit_fef)
Methods for xtfifevd objects
Description
Methods for xtfifevd objects