[R] VAR simulation help
londonphd
r.otojanov at qmul.ac.uk
Sat Feb 2 18:06:44 CET 2013
<http://r.789695.n4.nabble.com/file/n4657370/untitled.jpg>
Hi Everyone,
I am a new comer to R circle. I am trying to simulate a VAR estimation. The
problem is given above in the image. Assume that the errors are iid and
normally distributed. Here the number of observations x1=x2=64.
I've written the code below. Not sure if it is correct.
pi=matrix(c(0.9,0.1,-0.1,0.7),nrow=2,ncol=2)
# errors
error1=rnorm(64,mean=0,sd=1)
error2=rnorm(64,mean=0,sd=1)
#variables x1 and x2
x1=sample(64)
x2=sample(64)
#VAR simulation#
obs = 64
set.seed(123)
E=matrix(c(error1,error2),nrow=2,ncol=64)
pi=matrix(c(0.9,0.1,-0.1,0.7),nrow=2,ncol=2)
X=matrix(c(x1,x2),nrow=2,ncol=64)
for (i in 2:obs) {
X[,i] = pi%*%X[,i-1]+E[,i]
}
I would appreciate if you could comment whether I've correctly simulated it
or not.
Thank you,
lphd
--
View this message in context: http://r.789695.n4.nabble.com/VAR-simulation-help-tp4657370.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list