Package 'xtfifevd'

Title: Panel Fixed Effects Filtered and Variance Decomposition Estimation
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.
Authors: Muhammad Alkhalaf [aut, cre, cph] (ORCID: <https://orcid.org/0009-0002-2677-9246>)
Maintainer: Muhammad Alkhalaf <[email protected]>
License: GPL-3
Version: 1.0.1
Built: 2026-05-25 06:44:52 UTC
Source: https://github.com/muhammedalkhalaf/xtfifevd

Help Index


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")

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 y ~ x1 + x2 | z1 + z2 where variables before | are time-varying and variables after | are time-invariant.

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: "fevd" (default), "fef", or "fef_iv".

instruments

For method = "fef_iv", a one-sided formula specifying instrumental variables, e.g., ~ iv1 + iv2.

na.action

How to handle missing values. Default is na.omit.

Details

Model

The panel model is:

yit=αi+xitβ+ziγ+εity_{it} = \alpha_i + x_{it}'\beta + z_i'\gamma + \varepsilon_{it}

where xitx_{it} are time-varying regressors, ziz_i are time-invariant regressors, and αi\alpha_i are individual fixed effects.

Stage 1 (All Methods)

Fixed effects regression of yity_{it} on xitx_{it} yields consistent β^\hat{\beta} and combined residuals u^it=α^i+ε^it\hat{u}_{it} = \hat{\alpha}_i + \hat{\varepsilon}_{it}.

Stage 2

Time-averaged residuals uˉi\bar{u}_i are regressed on ziz_i:

  • FEF: OLS of uˉi\bar{u}_i on ziz_i with intercept

  • FEF-IV: 2SLS using instruments rir_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

fevd, fef, fef_iv, bw_ratio

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)