for loop problem - serious problem with EViews!

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt

charlesG
Posts: 3
Joined: Wed Sep 12, 2012 2:44 am

for loop problem - serious problem with EViews!

Postby charlesG » 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.

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
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???????????

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13604
Joined: Tue Sep 16, 2008 5:38 pm

Re: for loop problem - serious problem with EViews!

Postby EViews Gareth » Wed Sep 19, 2012 6:33 am

Welcome to the world of computer precision :)

Best thing to do is run your loop from 1 to 10 and divide by 10.


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests