for loop problem - serious problem with EViews!
Posted: Wed Sep 19, 2012 4:15 am
I've been trying to run a simple for loop from 0.1 to 1 with step size 0.1. Eventually I figured out that the loop wasn't working as it is supposed to. My code is below.
The problem turns out to be that the loop produces the following numbers for !j:
0.1
0.2
0.3000000000000001
0.4
0.5
0.6
0.7999999999999999
0
0.9999999999999999
0
My question is... how on Earth does this happen???????????
Code: Select all
vector(10) counter=0
for !j = 0.1 to 1 step 0.1
scalar phi = !j
smpl 1 1
genr y=1+2*nrnd
smpl 2 500
for !i = 1 to 5000
y=phi*y(-1)+2*nrnd
equation temp.ls y c y(-1)
scalar phihat=temp.@coef(2)
scalar phise=temp.@stderr(2)
scalar tstat = (phihat-phi)/phise
scalar tprob=@dtdist(tstat,498)
if tprob<0.05 then counter(10*!j)=counter(10*!j)+1
else counter(10*!j)=counter(10*!j)+1
endif
next
counter(10*!j)=counter(10*!j)/5000
next
0.1
0.2
0.3000000000000001
0.4
0.5
0.6
0.7999999999999999
0
0.9999999999999999
0
My question is... how on Earth does this happen???????????