I was using a panel dataset and I wanted to use the panelvar function. However, whenever I tried doing so with the original dataset, I received the following error

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

x Locations 13, 7, 8, 3, 6, etc. don't exist.

i There are only 1 column.//

The code that led to this

```
library(stats)
library(readr)
library(forecast)
library(panelvar)
kaya_identity_co2II_Copy <- read_csv(".....................csv")
#running the exact same code as used in the panelvar pdf
pvar1 <-pvargmm(
dependent_vars = c("RealGdpPerCapita","EnergyConsumptionPerGDp","AnnualCO2emissions"),
lags = 1,
transformation = "fod",
data = kaya_identity_co2II_Copy,
panel_identifier = c("Code", "Year"),
steps = c("twostep"),
system_instruments = FALSE,
max_instr_dependent_vars = 99,
max_instr_predet_vars = 99,
min_instr_dependent_vars = 2L,
min_instr_predet_vars = 1L,
collapse = FALSE
)
summary(pvar1)
```

After seeing the error I tried to look at the dataset used in the panelvar function pdf and found that the panel identifiers were factors in that dataset. So, I turned my panel identifiers into factors and tried to run the code. then I got the following error:

Error in if (xi > xj) 1L else -1L : missing value where TRUE/FALSE needed

In addition: Warning message:

In Ops.factor(xi, xj) : ‘>’ not meaningful for factors

Code after making changes

```
kaya_identity_co2II_Copy$Code = as.factor(kaya_identity_co2II_Copy$Code)
kaya_identity_co2II_Copy$Year = as.factor(kaya_identity_co2II_Copy$Year)
pvar1 <-pvargmm(
dependent_vars = c("RealGdpPerCapita","EnergyConsumptionPerGDp","AnnualCO2emissions"),
lags = 1,
transformation = "fod",
data = kaya_identity_co2II_Copy,
panel_identifier = c("Code", "Year"),
steps = c("twostep"),
system_instruments = FALSE,
max_instr_dependent_vars = 99,
max_instr_predet_vars = 99,
min_instr_dependent_vars = 2L,
min_instr_predet_vars = 1L,
collapse = FALSE
)
```

In an attempt to figure out why this error was occurring, we decided to check for missing values within the dataset. Turned out, there was a good amount of missing values within the dataset. So, we got rid of the missing values and made another data frame and tried to run the code with that. But, we got the same error.

Code at this point:

```
#Turning the panel identifiers into factors
kaya_identity_co2II_Copy$Code = as.factor(kaya_identity_co2II_Copy$Code)
kaya_identity_co2II_Copy$Year = as.factor(kaya_identity_co2II_Copy$Year)
#getting rid of missing values and making a subset of the original data
Data2 = subset(kaya_identity_co2II_Copy,is.na(kaya_identity_co2II_Copy$Code) == FALSE & is.na(kaya_identity_co2II_Copy$RealGdpPerCapita) == FALSE & is.na(kaya_identity_co2II_Copy$EnergyConsumptionPerGDp) == FALSE & is.na(kaya_identity_co2II_Copy$AnnualCO2emissions) == FALSE)
#Running the function
pvar2 <-pvargmm(
dependent_vars = c("RealGdpPerCapita","EnergyConsumptionPerGDp","AnnualCO2emissions"),
lags = 1,
transformation = "fod",
data = Data2,
panel_identifier = c("Code", "Year"),
steps = c("twostep"),
system_instruments = FALSE,
max_instr_dependent_vars = 99,
max_instr_predet_vars = 99,
min_instr_dependent_vars = 2L,
min_instr_predet_vars = 1L,
collapse = FALSE
)
summary(pvar2)
```

We are not really sure what this error means and at this point we have run out of ideas to solve it. So, hopefully someone can help.

I can't seem to attach files to the post. So, I am attaching a link to the dataset and the panelvar pdf.

https://drive.google.com/drive/folders/1O5xMkWODvEC_tu1eqClO1em_SfXRw3KI?usp=sharing

Thank you for your help!