This package implements a novel, fast and robust algorithm to estimate interactive fixed effect models (Bai 2009).
I(i)) the two categorical dimensions associated with observation
i (typically time and id). This package estimates the set of coefficients
β, of factors
(f1, .., fr) and of loadings
(λ1, ..., λr) in the model
To estimate an interactive fixed effect model, one needs to specify a formula, a factor model with
ife, and, eventually, a set of fixed effects with
fe, a way to compute standard errors with
vcov, and a weight variable with
using DataFrames, RDatasets, InteractiveFixedEffectModels df = dataset("plm", "Cigar") df[:pState] = pool(df[:State]) df[:pYear] = pool(df[:Year]) regife(df, @model(Sales ~ Price, ife = (pState + pYear, 2), fe = pState, save = true)) # Linear Factor Model #================================================================ #Number of obs: 1380 Degree of freedom: 199 #R2: 0.976 R2 within: 0.435 #Iterations: 436 Converged: true #================================================================ # Estimate Std.Error t value Pr(>|t|) Lower 95% Upper 95% #---------------------------------------------------------------- #Price -0.425372 0.0141163 -30.1334 0.000 -0.453068 -0.397677 #================================================================
A typical formula is composed of one dependent variable and a set of regressors
using RDatasets, DataFrames, InteractiveFixedEffectModels df = dataset("plm", "Cigar")
When the only regressor is
fit fits a factor model
Sales ~ 0
fit fits a linear model with interactive fixed effects (Bai (2009))
Sales ~ Price + Year
Interactive fixed effects are indicated with the keyword argument
ife. Variables must be of type
PooledDataVector. For instance, for a factor model with id variable
State, time variable
Year, and rank
r equal to 2:
df[:pState] = pool(df[:State]) df[:pYear] = pool(df[:Year]) ife = (pState + pYear, 2)
Fixed effects are indicated with the keyword argument
fe. Use only the variables specified in the factor model. See FixedEffectModels.jl for more information
fe = pState fe = pYear fe = pState + pYear
Standard errors are indicated with the keyword argument
vcov = robust() vcov = cluster(StatePooled) vcov = cluster(StatePooled, YearPooled)
weights are indicated with the keyword argument
weights = Pop
method allows to choose between two algorithms:
save = true saves a new dataframe storing residuals, factors, loadings and the eventual fixed effects. Importantly, the returned dataframe is aligned with the initial dataframe (rows not used in the estimation are simply filled with NA).
The algorithm can estimate models with missing observations per id x time, multiple observations per id x time, and weights.
However, in these cases, the optimization problem may have local minima. The algorithm tries to catch these cases, and, if need be, restart the optimization until the global minimum is reached. However I am not sure that all the cases are caught.
Yes. Factor models are a particular case of interactive fixed effect models. Simply specify
0 as the lhs of the formula.
using DataFrames, RDatasets, InteractiveFixedEffectModels df = dataset("plm", "Cigar") df[:pState] = pool(df[:State]) df[:pYear] = pool(df[:Year]) regife(df, @model(Sales ~ 0, ife = (pState + pYear, 2), fe = pState, save = true))
Compared to the usual SVD method, the package estimates models with multiple (or missing) observations per id x time.
Some litterature using this estimation procedure::
Errors are obtained by regressing y on x and covariates of the form
i.year#c.id. This way of computing standard errors is hinted in section 6 of of Bai (2009).
In presence of cross or time correlation beyond the factor structure, the estimate for beta is consistent but biased (see Theorem 3 in Bai 2009, which derives the correction term in special cases). However, this package does not implement any correction. You may want to check that your residuals are approximately i.i.d.
11 days ago