ycroissant / plm

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

automatically handle missing values in pmg #6

Closed waynelapierre closed 3 years ago

waynelapierre commented 3 years ago

I noticed that I need to remove all missing values when using plm::pmg. Most other econometrics packages can automatically handle missing values. Would you add this feature in the future? Thanks.

tappek commented 3 years ago

pmg removes observations when NA is encountered. Could you provide an example to illustrate what you have in mind?

waynelapierre commented 3 years ago

After updating to the most recent plm, it seems plm can handle missing values in independent and dependent variables now. Does it also handle missing values in the time and id index?

tappek commented 3 years ago

Please make sure to use the latest CRAN version before you write in. However, if I remember correctly, dropping rows with NA in variables used in estimation is in pmg for quite a long time (maybe from its first version).

Please read the NEWS (from 2.4-1): NAs in the index variables are "handled" like this (at least currently; one could argue to drop affected rows (with a warning)):

- pdata.frame: warns if NA in index dimension is encountered (before, only a plain message was printed).
- Between/between/Sum/Within: Methods which rely on the index attribute (*.pseries and partly *.matrix)
   now error informatively if NA in any index dimension is encountered.

Example:

data("Produc", package = "plm")
Produc[2, "state"] <- NA
head(Produc)
mgmod <- pmg(log(gsp) ~ log(pcap) + log(pc) + log(emp) + unemp, data = Produc)
# Error in checkNA.index(index) : NA in the individual index variable
# In addition: Warning message:
# In pdata.frame(data, index) :
#  at least one NA in at least one index dimension in resulting pdata.frame
# to find out which, use, e.g., table(index(your_pdataframe), useNA = "ifany")