I have already read similar questions regarding the assign command. But it doesnt work for me.
Here is my code:
masums <- function(var) {
lags <- var$p # number of lags in VAR
eqn <- length(var$varresult) # number of equations in VAR
dep <- names(var$varresult) # names of dependent variables
for(i in 1:eqn) # compute coefficient matrices
d <- dep[i]
x <- paste("var$varresult$",d,"$coefficients",sep="")
y <- as.matrix(GET THE VALUE OF "x" e.g. var$varresult$d$coefficients) # d="gap" for i=1
}
return(y)
}
Example: For i=1 d would have the value "gap", therefore I want the value of var$varresult$gap$coefficients.
var$varresult consists of elements of class "lm". Maybe the solution is easy and I am just to stressed to see it. Hope someone can help.
Edit: For a small example dataset:
library(vars)
y <- c(100*rnorm(100))
x <- seq(1,100,1)
vardata <- cbind(x,y)
var1 <- VAR(vardata,p=4,type="const")
var1$varresult$x$coefficients
Martin
x? (2) you're only returningyfrom the last iteration of your loop - but you haven't explained what you're actually trying to do and what aspects of your current efforts aren't working.assign. There is probably a more R-like way of doing things. What is your real problem?