The package is registered in the
General registry and so can be installed at the REPL with
] add InteractiveFixedEffectModels.
This package implements a novel, fast and robust algorithm to estimate interactive fixed effect models.
The definition of interactive fixed effects follows Bai (2009).Formally, denote
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
using DataFrames, RDatasets, InteractiveFixedEffectModels df = dataset("plm", "Cigar") regife(df, @formula(Sales ~ Price + ife(State, Year, 2) + fe(State))) # Interactive Fixed Effect Model # ================================================================ # Number of obs: 1380 Degree of freedom: 47 # 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.0132871 -32.0139 0.000 -0.451438 -0.399306 # ================================================================
ife. For instance, to specify a factor model with id variable
State, time variable
Year, and rank 2, use
ife(State, Year, 2).
fe(State)but only for the variables specified in the factor model. See FixedEffectModels.jl for more information
regife(df, @formula(Sales ~ Price + ife(State, Year, 2))) regife(df, @formula(Sales ~ Price + ife(State, Year, 2) + fe(State)))
To construct formula programatically, use
regife(df, Term(:Sales) ~ Term(:Price) + ife(Term(:State), Term(:Year), 2) + fe(Term(:State)))
Standard errors are indicated as follows
Vcov.robust() Vcov.cluster(:State) Vcov.cluster(:State, :Year)
weights can add weights
weights = :Pop
method can be used 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
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.
To estimate a factor model without any demeaning
using DataFrames, RDatasets, InteractiveFixedEffectModels df = dataset("plm", "Cigar") regife(df, @formula(Sales ~ 0 + ife(State, Year, 2)), save = true)
To demean with respect to one dimension, use
using DataFrames, RDatasets, InteractiveFixedEffectModels df = dataset("plm", "Cigar") regife(df, @formula(Sales ~ ife(State, Year, 2) + fe(State)), save = true)
The algorithm used in this package allows one to estimate 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 (in which case there is no need for bias correction).
5 months ago