Error: Can't subset columns that don't exist

This is the code I'm trying to run:

varex1 <- pvargmm(dependent_vars = c("en_con_tot_toe", "gdp", "pop_urb_per"), lags = 1, transformation = "fod", data = VARtestdata, panel_identifier = c("country", "year"), steps = c("twostep"), system_instruments = FALSE)

I keep getting this error:

Error: Can't subset columns that don't exist.
x Locations 5, 2, 4, 3, 8, etc. don't exist.
i There are only 1 column.

Here is the last_error() and last_trace():

rlang::last_error()
<error/vctrs_error_subscript_oob>
Can't subset columns that don't exist.
x Locations 5, 2, 4, 3, 8, etc. don't exist.
i There are only 1 column.
Backtrace:

  1. panelvar::pvargmm(...)
  2. base::sort.default(unique(Set_Vars[, 1]))
  3. tibble:::[.tbl_df(x, order(x, na.last = na.last, decreasing = decreasing))
  4. tibble:::vectbl_as_col_location(...)
  5. vctrs::vec_as_location(j, n, names)
  6. vctrs:::stop_subscript_oob(...)
  7. vctrs:::stop_subscript(...)
    Run rlang::last_trace() to see the full context.

rlang::last_trace()
<error/vctrs_error_subscript_oob>
Can't subset columns that don't exist.
x Locations 5, 2, 4, 3, 8, etc. don't exist.
i There are only 1 column.
Backtrace:
x

  1. -panelvar::pvargmm(...)
  2. +-base::sort(unique(Set_Vars[, 1]))
  3. -base::sort.default(unique(Set_Vars[, 1]))
  4. +-x[order(x, na.last = na.last, decreasing = decreasing)]
    
  5. \-tibble:::`[.tbl_df`(x, order(x, na.last = na.last, decreasing = decreasing))
    
  6.   \-tibble:::vectbl_as_col_location(...)
    
  7.     +-tibble:::subclass_col_index_errors(...)
    
  8.     | \-base::withCallingHandlers(...)
    
  9.     \-vctrs::vec_as_location(j, n, names)
    
  10.       \-(function () ...
    
  11.         \-vctrs:::stop_subscript_oob(...)
    
  12.           \-vctrs:::stop_subscript(...)
    

PLEASE HELP. Also, if you want me to upload the dataset I'm using, how do I do that?

Yes, some representative data would be helpful. Using mtcars as an example:

dput <- head(mtcars)

then cut and paste the output.

Also, please provide the library from which pvargmm comes.

Is this what you mean?

A tibble: 6 x 16

country year elec_gen_kwh elec_con_kwh elec_cap_kw elec_loss_kwh en_con_tot_toe en_con_petr_toe petr_con_mt

1 AGO 1980 8.96 8.87 8.78 8.23 6.17 6.04 6.00
2 AGO 1981 8.96 8.87 8.78 8.23 6.16 6.04 6.00
3 AGO 1982 9.00 8.91 8.78 8.26 6.19 6.06 6.02
4 AGO 1983 9.01 8.92 8.78 8.29 6.22 6.08 6.04
5 AGO 1984 9.01 8.93 8.78 8.23 6.18 6.02 5.98
6 AGO 1985 9.01 8.92 8.78 8.31 6.27 6.13 6.10

pvargmm comes from panelvar

Here's what the reprex should look like. I can reproduce the error, can't see why it should not work based on the example, and have found no express error messages in the function code for pvargmm, so I will be running that looking for subset operations later tonight.

The reprex doesn't generate because two of the variables given as an argument, "gdp", "pop_urb_per" don't exist. However, removing them doesn't help, either

suppressPackageStartupMessages({
      library(panelvar)
    })
    
    
    VARtestdata <- structure(list(
        country = c(
          "AGO", "AGO", "AGO", "AGO", "AGO",
          "AGO"
        ), year = c(1980, 1981, 1982, 1983, 1984, 1985), elec_gen_kwh = c(
          8.96,
          8.96, 9, 9.01, 9.01, 9.01
        ), elec_con_kwh = c(
          8.87, 8.87, 8.91,
          8.92, 8.93, 8.92
        ), elec_cap_kw = c(
          8.78, 8.78, 8.78, 8.78, 8.78,
          8.78
        ), elec_loss_kwh = c(8.23, 8.23, 8.26, 8.29, 8.23, 8.31),
        en_con_tot_toe = c(6.17, 6.16, 6.19, 6.22, 6.18, 6.27), en_con_petr_toe = c(
          6.04,
          6.04, 6.06, 6.08, 6.02, 6.13
        ), petr_con_mt = c(
          6, 6, 6.02,
          6.04, 5.98, 6.1
        )
      ), class = c(
        "spec_tbl_df", "tbl_df", "tbl",
        "data.frame"
      ), row.names = c(NA, -6L), spec = structure(list(
        cols = list(country = structure(list(), class = c(
          "collector_character",
          "collector"
        )), year = structure(list(), class = c(
          "collector_double",
          "collector"
        )), elec_gen_kwh = structure(list(), class = c(
          "collector_double",
          "collector"
        )), elec_con_kwh = structure(list(), class = c(
          "collector_double",
          "collector"
        )), elec_cap_kw = structure(list(), class = c(
          "collector_double",
          "collector"
        )), elec_loss_kwh = structure(list(), class = c(
          "collector_double",
          "collector"
        )), en_con_tot_toe = structure(list(), class = c(
          "collector_double",
          "collector"
        )), en_con_petr_toe = structure(list(), class = c(
          "collector_double",
          "collector"
        )), petr_con_mt = structure(list(), class = c(
          "collector_double",
          "collector"
        ))), default = structure(list(), class = c(
          "collector_guess",
          "collector"
        )), skip = 1L
      ), class = "col_spec"pvargmm))e(list(), class = c(
        "collector_double",
        "collector"
      ))), default = structure(suppressPackageStartupMessages({
        library(panelvar)
      })
      
    # reproduce the error
    
    varex1 <- pvargmm(dependent_vars = c("en_con_tot_toe", "gdp", "pop_urb_per"), lags = 1, transformation = "fod", data = VARtestdata, panel_identifier = c("country", "year"), steps = c("twostep"), system_instruments = FALSE)