Learn R Programming

fixest (version 0.5.1)

i: Interact variables with factors

Description

Interacts a variable with another treated as a factor, and sets a reference

Usage

i(var, fe, ref)

interact

Arguments

var

A vector.

fe

A vector (of any type). Must be of the same length as var.

ref

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

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 fe 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, fe, ref), you can instead use the following writing var::fe(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]

cbind(x, y, i(x, y, 1))

#
# In fixest estimations
#

# NOTA: in fixest estimations, i(var, fe, ref) is equivalent to var::fe(ref)

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)

# You could have used the following formula instead:
# y ~ x1 + treat::period(5) | id+period

# }

Run the code above in your browser using DataLab