sparse_model_matrix: Design matrix of a 'fixest' object returned in sparse format

View source: R/utils.R

sparse_model_matrixR Documentation

Design matrix of a fixest object returned in sparse format

Description

This function creates the left-hand-side or the right-hand-side(s) of a femlm, feols or feglm estimation. Note that this function currently does not accept a formula

Usage

sparse_model_matrix(
  object,
  data,
  type = "rhs",
  na.rm = TRUE,
  collin.rm = TRUE,
  combine = TRUE,
  ...
)

Arguments

object

A fixest estimation object

data

If missing (default) then the original data is obtained by evaluating the call. Otherwise, it should be a data.frame.

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).

na.rm

Default is TRUE. Should observations with NAs be removed from the matrix?

collin.rm

Logical scalar, default is TRUE. Whether to remove variables that were found to be collinear during the estimation. Beware: it does not perform a collinearity check.

combine

Logical scalar, default is TRUE. Whether to combine each resulting sparse matrix

...

Not currently used.

Value

It returns either a single sparse matrix a list of matrices, depending whether combine is TRUE or FALSE. The sparse matrix is of class dgCMatrix from the Matrix package.

Author(s)

Laurent Berge, Kyle Butts

See Also

See also the main estimation functions femlm, feols or feglm. formula.fixest, update.fixest, summary.fixest, vcov.fixest.

Examples


est = feols(wt ~ i(vs) + hp | cyl, mtcars)
sparse_model_matrix(est)



kylebutts/did2s documentation built on April 17, 2025, 5:20 p.m.