Search code examples
undefinedpanel

Undefined columns selected using panelvar package


Have anyone used panel var in R?

Currently I'm using the package panelvar of R. And I'm getting this error :

Error in `[.data.frame`(data, , c(colnames(data)[panel_identifier], required_vars)) :
undefined columns selected

And my syntax currently is:

model1<-pvargmm(
    dependent_vars = c("Change.."),
    lags = 2,
    exog_vars = c("Price"),
transformation = "fd",    
data = base1,    
panel_identifier = c("id", "t"),
steps = c("twostep"),    
system_instruments = FALSE,    
max_instr_dependent_vars = 99,    
min_instr_dependent_vars = 2L,
collapse = FALSE)

I don't know why my panel_identifier is not working, it's pretty similar to the example given by panelvar package, however, it doesn't work, I want to appoint that base1 is on data.frame format. any ideas? Also, my data is structured like this:

 head(base1)
  id    t country    DDMMYY month month_text day Date_txt year    Price     Open
1  1 1296   China  1-4-2020     4        Apr   1   Apr 01 2020 12588.24 12614.82
2  1 1295   China 31-3-2020     3        Mar  31   Mar 31 2020 12614.82 12597.61

      High      Low Vol. Change..
1 12775.83 12570.32   NA  -0.0021
2 12737.28 12583.05   NA   0.0014

thanks in advance !


Solution

  • Check the documentation of the package and the SSRN paper. For me it helped to ensure all entered formats are identical (you can check this with str(base1) command). For example they write:

    library(panelvar)
    data("Dahlberg")
    ex1_dahlberg_data <-
    pvargmm(dependent_vars = .......
    

    When I look at it I get

     >str(Dahlberg)
     'data.frame':  2385 obs. of  5 variables:
         $ id          : Factor w/ 265 levels "114","115","120",..: 1 1 1 1 1 1 1 1 1 2 ...
         $ year        : Factor w/ 9 levels "1979","1980",..: 1 2 3 4 5 6 7 8 9 1 ...
         $ expenditures: num  0.023 0.0266 0.0273 0.0289 0.0226 ...
         $ revenues    : num  0.0182 0.0209 0.0211 0.0234 0.018 ...
         $ grants      : num  0.00544 0.00573 0.00566 0.00589 0.00559 ...
    

    For example the input data must be a data.frame (in my case it had additional type specifications like tibble or data.table). I resolved it by casting as.data.frame() on it.