Open tappek opened 1 year ago
Test code for the part relating to the mentioned sandwich::vcovBS
issue in case of NA
dropping is here: https://gist.github.com/tappek/4cb65ab25d64f019ec629df5d11bd2bc
One other detail to think about is how NA dropping affects differencing and lagging of variables, which can be VERY subtle and has inconsistencies across packages. Bear with me for a second as I mention other packages before getting back to plm
.
xtdpd
allows for specifying an if
argument which is something like plm
's subset
(although subset
is also ignored in plm
and pgmm
currently). What this does is, after differencing and lagging, it drops observations that don't match the condition. This produces different results than dropping the observations before processing, because it deletes less data.fixest
's feols
, I can imitate this by adding a variable that is 1 everywhere and NA on the observations that I want to be dropped. The function will compute differences and lag first first, then drop the observations where that variable is NA, then realize that it's collinear with the intercept or one of the fixed effects and drop one of the two.plm
because it currently isn't able to drop NAs this way nor to drop the intercept or one of the fixed effects in case of collinearity.Therefore, implementing handling of NAs that is similar to what fixest
does would catch two birds with one stone: once it can drop NAs, implementing subset
is as simple as adding a variable that is 1 everywhere and NA on the observation that don't match the subset
condition and letting NA dropping work its magic.
Currently, the
na.action
argument is (silently) ignored. (Of course,NA
dropping works).Adding support for it would have many benefits in presence of
NA
s, e.g., making it easier to add residuals back to the original data and it seemssandwich::vcovBS
on plm objects estimated from a data frame with droppedNA
s requires it via use ofexpand.model.frame
.An old branch was once started on R-Forge and has the below information: https://r-forge.r-project.org/scm/viewvc.php/branches/exp_na.action/?root=plm
################# First take on na.action for plm objects ####################
plm, residuals.plm: element "na.action" is now in plm objects. This enables extraction of residuals padded to match the original data in presence of NAs when model is estimated with the na.action argument set to, e.g. na.exclude. Example: plm_object <- plm(..., data = data, na.action = na.exclude) residuals(plm_object) # will have the length to match number of rows of data
many more files changes to accomodate the change (but likely not all)