Skip to contents

This function extracts the formula from a fixest estimation (obtained with femlm, feols or feglm). If the estimation was done with fixed-effects, they are added in the formula after a pipe (“|”). If the estimation was done with a non linear in parameters part, then this will be added in the formula in between I().

Usage

# S3 method for class 'fixest'
formula(x, type = "full", fml.update = NULL, fml.build = NULL, ...)

# S3 method for class 'fixest_multi'
formula(x, type = "full", fml.update = NULL, fml.build = NULL, ...)

Arguments

x

An object of class fixest. Typically the result of a femlm, feols or feglm estimation.

type

A character scalar. Default is type = "full" which gives back a formula containing the linear part of the model along with the fixed-effects (if any) and the IV part (if any). Here is a description of the other types:

  • full.noiv: the full formula without the IV part

  • full.nofixef.noiv: the full formula without the IV nor the fixed-effects part

  • lhs: a one-sided formula with the dependent variable

  • rhs: a one-sided formula of the right hand side without the IVs (if any)

  • rhs.nofixef or indep: a one-sided formula of the right hand side without the fixed-effects nor IVs (if any), it is equivalent to the independent variables

  • NL: a one-sided formula with the non-linear part (if any)

  • fixef: a one-sided formula containing the fixed-effects

  • iv: a two-sided formula containing the endogenous variables (left) and the instruments (right)

  • iv.endo: a one-sided formula of the endogenous variables

  • iv.inst: a one-sided formula of the instruments

  • iv.reduced: a two-sided formula representing the reduced form, that is y ~ exo + inst

fml.update

A formula representing the changes to be made to the original formula. By default it is NULL. Use a dot to refer to the previous variables in the current part. For example: . ~ . + xnew will add the variable xnew as an explanatory variable. Note that the previous fixed-effects (FEs) and IVs are implicitly forwarded. To rerun without the FEs or the IVs, you need to set them to 0 in their respective slot. Ex, assume the original formula is: y ~ x | fe | endo ~ inst, passing . ~ . + xnew to fml.update leads to y ~ x + xnew | fe | endo ~ inst (FEs and IVs are forwarded). To add xnew and remove the IV part: use . ~ . + xnew | . | 0 which leads to y ~ x + xnew | fe.

fml.build

A formula or NULL (default). You can create a new formula based on the parts of the formula of the object in x. In this argument you have access to these specific variables:

  • .: to refer to the part of the original formula

  • .lhs: to refer to the dependent variable

  • .indep: to refer to the independent variables (excluding the fixed-effects)

  • .fixef: to refer to the fixed-effects

  • .endo: to refer to endogenous variables in an IV estimation

  • .inst: to refer to instruments in an IV estimation

Example, the original estimation was y ~ x1 | z ~ inst. Then fml.build = . ~ .endo + . leads to y ~ z + x1.

...

Not currently used.

Value

It returns either a one-sided formula, either a two-sided formula.

Details

The arguments type, fml.update and fml.build are exclusive: they cannot be used at the same time.

See also

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

Author

Laurent Berge

Examples


# example estimation with IVS and FEs
base = setNames(iris, c("y", "x1", "endo", "instr", "species"))
est = feols(y ~ x1 | species | endo ~ instr, base)

# the full formula
formula(est)
#> y ~ x1 | species | endo ~ instr

# idem without the IVs nor the FEs
formula(est, "full.nofixef.noiv")
#> y ~ x1
#> <environment: 0x000001a386c490b0>

# the reduced form
formula(est, "iv.reduced")
#> y ~ x1 + instr | species

# the IV relation only
formula(est, "iv")
#> endo ~ instr
#> <environment: 0x000001a386c49e08>

# the dependent variable => onse-sided formula
formula(est, "lhs")
#> ~y
#> <environment: 0x000001a386c490b0>

# using update, we add x1^2 as an independent variable:
formula(est, fml.update = . ~ . + x1^2)
#> y ~ x1 + x1^2 | species | endo ~ instr
#> <environment: 0x000001a386498e08>

# using build, see the difference => the FEs and the IVs are not inherited
formula(est, fml.build = . ~ . + x1^2)
#> y ~ x1 + x1^2
#> <environment: 0x000001a38632a5f0>

# we can use some special variables
formula(est, fml.build = . ~ .endo + .indep)
#> y ~ endo + x1
#> <environment: 0x000001a3861a8430>