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()
.
Arguments
- x
An object of class
fixest
. Typically the result of afemlm
,feols
orfeglm
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 partfull.nofixef.noiv
: the full formula without the IV nor the fixed-effects partlhs
: a one-sided formula with the dependent variablerhs
: a one-sided formula of the right hand side without the IVs (if any)rhs.nofixef
orindep
: a one-sided formula of the right hand side without the fixed-effects nor IVs (if any), it is equivalent to the independent variablesNL
: a one-sided formula with the non-linear part (if any)fixef
: a one-sided formula containing the fixed-effectsiv
: a two-sided formula containing the endogenous variables (left) and the instruments (right)iv.endo
: a one-sided formula of the endogenous variablesiv.inst
: a one-sided formula of the instrumentsiv.reduced
: a two-sided formula representing the reduced form, that isy ~ 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 variablexnew
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 toy ~ x + xnew | fe | endo ~ inst
(FEs and IVs are forwarded). To add xnew and remove the IV part: use. ~ . + xnew | . | 0
which leads toy ~ 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 inx
. 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
. Thenfml.build = . ~ .endo + .
leads toy ~ z + x1
.- ...
Not currently used.
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
.
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>