| model.matrix.fixest | R Documentation |
fixest objectThis function creates the left-hand-side or the right-hand-side(s) of a femlm,
feols or feglm estimation.
## S3 method for class 'fixest'
model.matrix(
object,
data = NULL,
type = "rhs",
sample = "estimation",
na.rm = FALSE,
subset = FALSE,
as.matrix = FALSE,
as.df = FALSE,
collin.rm = TRUE,
...
)
object |
A |
data |
A data.frame or |
type |
Character vector or one sided formula, default is "rhs". Contains the type of matrix/data.frame to be returned. Possible values are: "lhs", "rhs", "fixef", "iv.rhs1" (1st stage RHS), "iv.rhs2" (2nd stage RHS), "iv.endo" (endogenous vars.), "iv.exo" (exogenous vars), "iv.inst" (instruments). |
sample |
Character scalar equal to "estimation" (default) or "original". Only
used when If |
na.rm |
Logical scalar, default is |
subset |
Logical scalar or character vector. Default is |
as.matrix |
Logical scalar, default is |
as.df |
Logical scalar, default is |
collin.rm |
Logical scalar, default is |
... |
Not currently used. |
It returns either a vector, a matrix or a data.frame. It returns a vector for the dependent variable ("lhs"), a data.frame for the fixed-effects ("fixef") and a matrix for any other type.
Laurent Berge
See also the main estimation functions femlm, feols or feglm. formula.fixest, update.fixest, summary.fixest, vcov.fixest.
# we use a data set with NAs and fixed-effect singletons
base = setNames(iris, c("y", "x1", "x2", "x3", "fe"))
# adding NAs
base$x1[1:4] = NA
# adding singletons
base$fe = as.character(base$fe)
base$fe[10 + 1:5] = letters[1:5]
# OLS estimation where we remove singletons
est = feols(y ~ x1 + poly(x2, 2) | fe, base, fixef.rm = "singleton")
# by default, we have the data set used in the estimation
head(model.matrix(est))
nrow(model.matrix(est))
# to have the original data set: we need to use sample="original"
head(model.matrix(est, sample = "original"))
nrow(model.matrix(est, sample = "original"))
# we can drop only the NA values (and not the singletons) with na.rm=TRUE
head(model.matrix(est, sample = "original", na.rm = TRUE))
nrow(model.matrix(est, sample = "original", na.rm = TRUE))
#
# Illustration of subset
#
# subset => character vector
head(model.matrix(est, subset = "x1"))
# subset => TRUE, only works with data argument!!
head(model.matrix(est, data = base[, "x1", drop = FALSE], subset = TRUE))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.