efactory: Create estimable function

View source: R/efactory.R

efactoryR Documentation

Create estimable function

Description

Creates an estimable function for a factor-structure.

Usage

efactory(obj, opt = "ref", ...)

Arguments

obj

object of class "felm", usually, a result of a call to felm().

opt

character. Which type of estimable function.

...

various.

Details

There are several possibilities for the input parameter opt.

  • "ref" yields an estimable function which is similar to the default one in lm(), one reference is forced to 0 in each connected component.

  • "zm" Similar to "ref", but the factor which does not contain a reference is made to have zero mean, and an intercept is added.

  • "zm2" Similar to "zm", but both factors are made to have zero mean.

  • "ln" Least norm function. This will yield the raw coefficients from the Kaczmarz-method, i.e. the solution with smallest norm. This function is not estimable.

Note that in the case with more than two factors, it is not known how to analyze the factors to find the structure of the rank-deficiencies, i.e. the estimable functions. In this case, the factors beyond the first two are assumed not to contribute to the rank-deficiency beyond a single dimension in each. Both "ref" and "zm" keep one such reference at zero in each of these factors. This is the common method when using dummies.

In the case that interactions are specified in the model, i.e. with x:f in the second part of the formula, these terms are not analyzed to create an estimable function. Only the pure f terms are used for this purpose. It is assumed that the x:f terms are all identified. Note that in this case, all the levels of f are included.

Value

A function of two parameters ⁠function(v,addnames)⁠. An estimable function (i.e. the result is the vector of some length N) of the input vector v. When addnames==TRUE the returned vector should have names, and optionally an attribute "extra" which is a list of vectors of length N which may be used to code additional information.

Note

The author is open to suggestions for other estimable functions, i.e. other useful normalizations of the solutions.

It is not strictly necessary that the obj argument is of class "felm", any list with entries "fe" and "cfactor" of the appropriate form will do. That is, list(fe=fl,cfactor=compfactor(fl)) where fl is the list of factors defining the component structure. I.e. if the model is y ~ ... |id + firm, we have fl=list(id=id,firm=firm).

Examples


oldopts <- options("lfe.threads")
options(lfe.threads = 2)
id <- factor(sample(5000, 50000, replace = TRUE))
firm <- factor(sample(3000, 50000, replace = TRUE))
fl <- list(id = id, firm = firm)
obj <- list(fe = fl, cfactor = compfactor(fl))
## the trivial least-norm  transformtion, which by the way is non-estimable
print(ef <- efactory(obj, "ln"))
is.estimable(ef, fl)
## then the default
print(ef <- efactory(obj, "ref"))
is.estimable(ef, fl)
# get the names of the coefficients, i.e. the nm-variable in the function
head(evalq(nm, environment(ef)))
options(oldopts)


lfe documentation built on May 29, 2024, 7:39 a.m.