InteractiveFixedEffectModels.jl estimates interactive fixed effect models of the Bai (2009) form:
The package is designed for panel settings with latent factors, optional high-dimensional fixed effects on the same panel dimensions, weights, clustering, and incomplete panels.
It integrates with the Julia StatsModels / FixedEffectModels ecosystem:
- formulas use
@formula(...) - high-dimensional fixed effects use
fe(...) - covariance estimators come from
Vcov.jl
The package is registered in the General registry:
] add InteractiveFixedEffectModelsCurrent package compatibility requires Julia 1.9+.
using DataFrames, RDatasets, InteractiveFixedEffectModels
df = dataset("plm", "Cigar")
result = regife(
df,
@formula(Sales ~ Price + ife(State, Year, 2) + fe(State))
)
display(result)Typical output:
Interactive Fixed Effect Model
Number of obs: ...
R²: ...
R² within: ...
Every regife formula must contain exactly one interactive fixed effect term:
ife(id, time, rank)where:
idis the unit dimensiontimeis the time dimensionrankis the number of latent factors
Example:
@formula(Sales ~ Price + ife(State, Year, 2))High-dimensional fixed effects can also be added with fe(...), but only on the same panel dimensions used in ife(...):
@formula(Sales ~ Price + ife(State, Year, 2) + fe(State))
@formula(Sales ~ Price + ife(State, Year, 2) + fe(Year))
@formula(Sales ~ Price + ife(State, Year, 2) + fe(State) + fe(Year))This is invalid:
@formula(Sales ~ Price + ife(State, Year, 2) + fe(Region))unless Region is the same dimension as one of the ife(...) variables.
Pass a Vcov.jl covariance estimator as the third positional argument:
regife(df, @formula(y ~ x + ife(id, time, 2)), Vcov.simple())
regife(df, @formula(y ~ x + ife(id, time, 2)), Vcov.robust())
regife(df, @formula(y ~ x + ife(id, time, 2)), Vcov.cluster(:id))
regife(df, @formula(y ~ x + ife(id, time, 2)), Vcov.cluster(:id, :time))Use a positive weight column:
regife(df, @formula(y ~ x + ife(id, time, 2)); weights = :w)Restrict estimation to a subset while keeping saved outputs aligned with the original data:
regife(df, @formula(y ~ x + ife(id, time, 2)); subset = df.year .>= 1980)Available methods are:
:dogleg:levenberg_marquardt:gauss_seidel
Example:
regife(df, @formula(y ~ x + ife(id, time, 2)); method = :dogleg)With save = true, the returned object contains an augmentdf aligned with the original data. Depending on the specification, it can include:
residualsfactors1,factors2, ...loadings1,loadings2, ...- absorbed fixed effects such as
fe_State
Rows excluded from estimation are filled with missing.
using DataFrames, RDatasets, InteractiveFixedEffectModels
df = dataset("plm", "Cigar")
result = regife(
df,
@formula(Sales ~ Price + ife(State, Year, 2) + fe(State)),
Vcov.cluster(:State);
save = true
)
coef(result)
result.augmentdfFactor models are a special case with no observed regressors.
using DataFrames, RDatasets, InteractiveFixedEffectModels
df = dataset("plm", "Cigar")
result = regife(
df,
@formula(Sales ~ 0 + ife(State, Year, 2));
save = true
)To demean with respect to one panel dimension:
regife(df, @formula(Sales ~ ife(State, Year, 2) + fe(State)); save = true)using StatsModels
regife(
df,
Term(:Sales) ~ Term(:Price) + ife(Term(:State), Term(:Year), 2) + fe(Term(:State))
)If the model includes regressors, regife returns an InteractiveFixedEffectModel, which behaves like a regression result and supports methods such as:
coefcoefnamesvcovconfintcoeftablenobsr2adjr2
If the model contains no regressors, it returns a lighter FactorResult with estimation metadata and the optional saved dataframe.
The package supports:
- missing observations within the
id × timepanel - multiple observations per
id × time - weights
In those cases, the optimization problem can have local minima. The package includes a restart heuristic to reduce that risk, but it is still a numerical optimization problem rather than a closed-form estimator.
The reported standard errors are based on regressing on covariates of the form:
i.id # c.timei.time # c.id
This follows the discussion in Section 6 of Bai (2009).
The package does not implement the Bai (2009) bias correction for settings with residual cross-sectional or serial dependence beyond the factor structure. In such cases, coefficient estimates can remain consistent but biased in finite samples.
Some literature using this estimation procedure:
- Eberhardt, Helmers, Strauss (2013), Do spillovers matter when estimating private returns to R&D?
- Hagedorn, Karahan, Manovskii (2015), Unemployment Benefits and Unemployment in the Great Recession: The Role of Macro Effects
- Hagedorn, Karahan, Manovskii (2015), The impact of unemployment benefit extensions on employment: the 2014 employment miracle?
- Totty (2015), The Effect of Minimum Wages on Employment: A Factor Model Approach
- FixedEffectModels.jl: linear models with high-dimensional fixed effects
- FactorModels.jl: factor models on matrices
- LowRankModels.jl: general low-rank approximation models
- Bai, Jushan (2009), "Panel Data Models With Interactive Fixed Effects," Econometrica.
