[.fixest_panel | R Documentation |
fixest_panel
Subselection from a fixest_panel
which has been created with the function panel
.
Also allows to create lag/lead variables with functions l
/f
if
the fixest_panel
is also a data.table::data.table
.
## S3 method for class 'fixest_panel'
x[i, j, ...]
x |
A |
i |
Row subselection. Allows |
j |
Variable selection. Allows |
... |
Other arguments to be passed to |
If the original data was also a data.table, some calls to [.fixest_panel
may dissolve
the fixest_panel
object and return a regular data.table. This is the case for
subselections with additional arguments. If so, a note is displayed on the console.
It returns a fixest_panel
data base, with the attributes allowing to create
lags/leads properly bookkeeped.
Laurent Berge
Alternatively, the function panel
changes a data.frame
into a panel from which the
functions l
and f
(creating leads and lags) can be called. Otherwise you can set the
panel 'live' during the estimation using the argument panel.id
(see for example in
the function feols
).
data(base_did)
# Creating a fixest_panel object
pdat = panel(base_did, ~id+period)
# Subselections of fixest_panel objects bookkeeps the leads/lags engine
pdat_small = pdat[!pdat$period %in% c(2, 4), ]
a = feols(y~l(x1, 0:1), pdat_small)
# we obtain the same results, had we created the lags "on the fly"
base_small = base_did[!base_did$period %in% c(2, 4), ]
b = feols(y~l(x1, 0:1), base_small, panel.id = ~id+period)
etable(a, b)
# Using data.table to create new lead/lag variables
if(require("data.table")){
pdat_dt = panel(as.data.table(base_did), ~id+period)
# Variable creation
pdat_dt[, x_l1 := l(x1)]
pdat_dt[, c("x_l1", "x_f1_2") := .(l(x1), f(x1)**2)]
# Estimation on a subset of the data
# (the lead/lags work appropriately)
feols(y~l(x1, 0:1), pdat_dt[!period %in% c(2, 4)])
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.