fixest (version 0.7.0)

i: Create, or interact variables with, factors

Description

Treat a variable as a factor, or interacts a variable with another treated as a factor. Values to be dropped/kept from the factor can be easily set.

Usage

i(var, f, ref, drop, keep)

interact

Arguments

var

A vector. If the other argument f is missing, then this vector will be treated as a factor.

f

A vector (of any type) that will be treated as a factor. Must be of the same length as var.

ref

A single value that belongs to the interacted variable (f). Can be missing.

drop

A vector of values that belongs to the factor variable (f). If provided, all values from f that match drop will be removed.

keep

A vector of values that belongs to the factor variable (f). If provided, only the values from f that match keep will be kept.

Value

It returns a matrix with number of rows the length of var. The number of columns is equal to the number of cases contained in f minus the reference.

Format

An object of class function of length 1.

Shorthand in <code>fixest</code> estimations

In fixest estimations, instead of using i(var, f, ref), you can instead use the following writing var::f(ref).

See Also

coefplot to plot interactions, feols for OLS estimation with multiple fixed-effects.

Examples

Run this code
# NOT RUN {
#
# Simple illustration
#

x = rnorm(10)
y = rep(1:4, 3)[1:10]

# interaction
cbind(x, y, i(x, y, 1))
# without interaction
cbind(x, y, i(y, ref = 1))

#
# In fixest estimations
#

data(base_did)
# We interact the variable 'period' with the variable 'treat'
est_did = feols(y ~ x1 + i(treat, period, 5) | id + period, base_did)

# => special treatment in coefplot
coefplot(est_did)

# Using i() for factors
est_bis = feols(y ~ x1 + i(period, keep = 3:6) + i(treat, period, 5) | id, base_did)

coefplot(est_bis, only.inter = FALSE)

# => special treatment in etable
etable(est_bis, dict = c("6" = "six"))


# }

Run the code above in your browser using DataLab