ycroissant / plm

Panel Data Econometrics with R
GNU General Public License v2.0
49 stars 13 forks source link

Support `na.action` argument #44

Open tappek opened 1 year ago

tappek commented 1 year ago

Currently, the na.action argument is (silently) ignored. (Of course, NA dropping works).

Adding support for it would have many benefits in presence of NAs, e.g., making it easier to add residuals back to the original data and it seems sandwich::vcovBS on plm objects estimated from a data frame with dropped NAs requires it via use of expand.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 ####################

tappek commented 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

kmfrick commented 3 months ago

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.

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.