Lags a variable in a fixest estimation
Produce lags or leads in the formulas of fixest
estimations or when creating variables in a data.table
. The data must be set as a panel beforehand (either with the function panel
or with the argument panel.id
in the estimation).
f(x, lead = 1, fill = NA) d(x, lag = 1, fill = NA) l(x, lag = 1, fill = NA)
x |
The variable. |
lead |
A vector of integers giving the number of leads. Negative values lead to lags. This argument can be a vector when using it in fixest estimations. When creating variables in a |
fill |
A scalar, default is |
lag |
A vector of integers giving the number of lags. Negative values lead to leads. This argument can be a vector when using it in fixest estimations. When creating variables in a |
These functions can only be used i) in a formula of a fixest
estimation, or ii) when creating variables within a fixest_panel
object (obtained with function panel
) which is alaos a data.table
.
f
: Forwards a variable (inverse of lagging) in a fixest
estimation
d
: Creates differences (i.e. x - lag(x)) in a fixest
estimation
data(base_did) # Setting a data set as a panel... pdat = panel(base_did, ~ id + period) # ...then using the functions l and f est1 = feols(y ~ l(x1, 0:1), pdat) est2 = feols(f(y) ~ l(x1, -1:1), pdat) est3 = feols(l(y) ~ l(x1, 0:3), pdat) etable(est1, est2, est3, order = c("f", "^x"), drop = "Int") # or using the argument panel.id feols(f(y) ~ l(x1, -1:1), base_did, panel.id = ~id + period) feols(d(y) ~ d(x1), base_did, panel.id = ~id + period) # l() and f() can also be used within a data.table: if(require("data.table")){ pdat_dt = panel(as.data.table(base_did), ~id+period) # Now since pdat_dt is also a data.table # you can create lags/leads directly pdat_dt[, x1_l1 := l(x1)] pdat_dt[, x1_d1 := d(x1)] pdat_dt[, c("x1_l1_fill0", "y_f2") := .(l(x1, fill = 0), f(y, 2))] }
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.