This might not be the answer that you are looking for, but it seems that the author did not add any functionality to the lfe
package in order to make predictions on external data by using the fitted felm
model. The primary focus seems to be on the analysis of the group fixed effects. However, it's interesting to note that in the documentation of the package the following is mentioned:
The object has some resemblance to an 'lm' object, and some
postprocessing methods designed for lm may happen to work. It may
however be necessary to coerce the object to succeed with this.
Hence, it might be possible to coerce the felm
object to an lm
object in order to obtain some additional lm
functionality (if all the required info is present in the object to perform the necessary computations).
The lfe package is intended to be run on very large datasets and effort was made to conserve memory: As a direct result of this, the felm
object does not use/contain a qr decomposition, as opposed to the lm
object. Unfortunately, the lm
predict
procedure relies on this information in order to compute the predictions. Hence, coercing the felm
object and executing the predict method will fail:
> model2 <- felm(data = iris, Sepal.Length ~ Sepal.Width | Species)
> class(model2) <- c("lm","felm") # coerce to lm object
> predict(model2, newdata = data.frame(Sepal.Width = 3, Species = "virginica"))
Error in qr.lm(object) : lm object does not have a proper 'qr' component.
Rank zero or should not have used lm(.., qr=FALSE).
If you really must use this package to perform the predictions then you could maybe write your own simplified version of this functionality by using the information that you have available in the felm
object. For example, the OLS regression coëfficients are available via model2$coefficients
.
data(iris)
, iris data is lazyloaded already. – Ursasfelm()
function (and the functions it calls) would be necessary as the current implementation does not store the fixed effect coefficients, or even apparently the intercept -- see this answer on a question that is at least a near duplicate of this one. – Unknowable