I want to create three series that are dependent on each others past, as for simulating VAR-model or cointegrated data.
I have the following code:
Code: Select all
workfile u 1000
smpl @all
series common_root=0
series var1=0 'Just three variables var1, 2 and 3
series var2=0
series var3=0
smpl 2 @last
common_root=common_root(-1)+@nrnd
var1=var1(-1)-0.5*(var1(-1)-var2(-1)-var3(-1)) + common_root
var2=var2(-1) +0.25*(var1(-1)-var2(-1)-var3(-1))
var3=var3(-1) +0.25*(var1(-1)-var2(-1)-var3(-1))
Series 2 and 3 should be exactly the same. They should be computed at the same time, depending on each others past but not the contemporaneous values.
The Problem is, they (a) are quite different from each other (var2 sticks close to var1 while var3 sticks around the zero line) and (b) if I change the order of the code (switching the ordering of var2 and 3):
Code: Select all
var1=var1(-1)-0.5*(var1(-1)-var2(-1)-var3(-1)) + common_root
var3=var3(-1) +0.25*(var1(-1)-var2(-1)-var3(-1))
var3=var3(-1) +0.25*(var1(-1)-var2(-1)-var3(-1))
...the result changes (i.e. var3 now sticks around var1 and var2 sticks to the zero). Both things should not happen.
If I instead use a for loop such as below, it works as it should:
Code: Select all
smpl @all
series v1=0
series v2=0
series v3=0
for !t=2 to 1000
v1(!t)= v1(!t-1) - 0.5*( v1(!t-1) - v2(!t-1) - v3(!t-1) ) + common_root(!t)
v2(!t)= v2(!t-1) +0.25*( v1(!t-1) - v2(!t-1) - v3(!t-1) )
v3(!t)= v3(!t-1) +0.25*( v1(!t-1) - v2(!t-1) - v3(!t-1) )
next
I don't quite understand why that is but there has to be a problem with the way EViews computes the vectors / series (Does the program overlook the interdependency and computes the series one after the other?)
I have Version 8.1 Build Nov 11 2014.