I'm trying to use the pglm
function from pglm
package to obtain a random effects panel estimation of an ordered logistic model.
When testing the standalone function pglm
it gives me the desired result. Here's my specifications:
pglm::pglm(as.numeric(y)~x1+x2+x3, df,family = pglm::ordinal('logit'),
model = "random", method = "bfgs", print.level = 3, R = 5, index = 'Year')
where: 1. all explanatory variable {x1,x2,x3} are numerical doubles 2. y is an ordered categorical variable ranging from 1 to 22
The table also includes a "Year" variable ranging from 1996 to 2014, that will be used to build the panel data.
When trying to use the pglm
function in another function:
pglm_fun <- function(df){
df <- data.frame(df)
pglm::pglm(as.numeric(y)~x1+x2+x3, data = df,family = pglm::ordinal('logit'),
model = "random", method = "bfgs", print.level = 3, R = 5, index = 'Year')
}
I get an error message occurring when calculating
pdata.frame(data, index)
Error in x[, !na.check] : object of type 'closure' is not subsettable.
When trying to run the code in the console, I do not have such an error and the pdata.frame()
function works.
Example of data frame:
df = data.frame(y = sort(rep(1:4,20)),
x1 = rnorm(80),
x2 = rnorm(80),
x3 = rnorm(80),
Year = rep(sample(1995:1998, replace = FALSE),20))