'the two series are "P" and "Q"
'setting the sample
smpl 1 3000
series _temp=1
!length=@obs(_temp)
delete _temp
'setting fixed sample size
!ssize=750
'setting the rolling sub-sample
for !i=1 to !length-!ssize+1
smpl @first+!i-1 @first+!i+!ssize-2
'introducing VEC
var v.ec(b,1) 1 2 P Q
'saving the adjustment coefficients of VEC
series alpha=v.a(1,1)
'putting restriction on adjustment coefficient of first equation to check ( the log likelihood values generated from this VEC estimation will be used for weak exogeneity)
v.append(coint) a(1,1)=0
v.coint(b,2,restrict,c=1e-5,m=100,save=mat1) P Q
'saving log-likelihood
series log_likelihood1=mat1(1,4)
'estimating unrestricted VEC ( the log likelihood values generated from this VEC estimation will be used for weak exogeneity)
v.cleartext(coint)
v.coint(b,2,save=mat2) P Q
'saving trace statistics
series trace=mat2(1,3)/54.07904
'saving log-likelihood
series log_likelihood2=mat2(2,4)
'calculating rolling LR statistic for weak exogenity test
series lr=2*(log_likelihood2-log_likelihood1)


next
