I have a wide dataset of stock returns and their lagged values. I want to use systemfit
package for a SUR estimation but couldn't put in multiple formulas
A sample of my dataset looks like:
df = data.frame('stock.1' = c(0, - 0.2, 0.3, 0.5, 0.2), 'lag.stock.1'
= c(0.2,0,- 0.2, 0.3, 0.5), 'stock.2' = c(0, - 0.1, 0.4, 0.7, -0.1), 'lag.stock.2' = c(0.1,0, - 0.1, 0.4, 0.7))
If I use the following code, it works
fitsur = systemfit(list(stock.1 ~ lag.stock.1, stock.2 ~ lag.stock.2), data = df)
But I have many stocks, so I create a list of formula first
stock.list = c("stock.1", "stock.2")
fm.list = list()
for (i in 1:length(stock.list)) {
stock = stock.list[i]
formula = paste0(stock,"~","lag.",stock)
fm.list[i] = formula
}
Using the this list does not work
fitsur = systemfit(fm.list, data = df)
Error in systemfit(fm.list, data = return.joindf) :
the list of argument 'formula' must contain only objects of class 'formula'
Is there a way to use the formula list correctly?
Use the
as.formula
function: