I need to run many similar regressions with small differences. As such, I want to create a class that creates different objects.
How can I setMethodso that a linear regression is run within the object? I'm now using "show" and cat to define the function, but it's not working.
The model I want to create as an object is:
model_ols <- plm(npl_lnratio ~ qe_ann + factor(year), index = "NAME", model = "within", data = mydata)
setClass("definition",
slots = list(dv = "character",
vars = "character",
method = "character",
data = "character",
model = "character")
)
setMethod("show", "definition",
function(object){
cat(object$dv ~ object$model(object$vars, factor(year), index = "NAME", model = object$method, data = object$data))
})
ols <- new("definition",
dv = "npl_lnratio",
vars = "qe_ann",
method = "within",
data = "mydata",
model = "plm")
show(ols)