Problem with recognition of decimals

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Jason, EViews Moderator

lpando08
Posts: 22
Joined: Tue Apr 03, 2018 1:13 pm

Problem with recognition of decimals

Postby lpando08 » Fri May 11, 2018 1:37 pm

Hello,

I have run this loop:

for !x=70 to 74 step 0.1
!h= !x*10
smpl if debt>!x
series hdebt_!h =1
smpl @all

smpl if debt<!x
series ldebt_!h=1
smpl @all
next

One of the series generated would be hdebt_709 when debt>70.9 but when I run the program it doesn't work, it shows this message "9999999 is not a member or procedure of hdebt_709 in series hdebt_!h=1". Which could be the problem?

Thank you!

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

Re: Problem with recognition of decimals

Postby EViews Gareth » Fri May 11, 2018 2:03 pm

Since computers cannot handle decimals precisely, you should not perform loop operations with a decimal step size (this is true of most programming languages, not just EViews).

Although you think that !x will follow the pattern 70 70.1 70.2 70.3 70.4 etc..., it will not.
For example, if you run this code:

Code: Select all

create u 10
table a
!r=1
for !x=70 to 74 step 0.1
   a(!r) = !x
   !r=!r+1
next
show a


Then select individual elements of the table, you can see the numbers are not exact.
Follow us on Twitter @IHSEViews

EViews Steve
EViews Developer
Posts: 504
Joined: Tue Sep 16, 2008 3:00 pm
Location: Irvine, CA

Re: Problem with recognition of decimals

Postby EViews Steve » Sun May 13, 2018 6:11 am

I think using integers in the for loop instead would work better:

Code: Select all

logmode l
for !h=700 to 740 step 1
   !x= !h/10
   logmsg !x
   smpl if debt>!x
   series hdebt_!h =1
   smpl @all

   smpl if debt<!x
   series ldebt_!h=1
   smpl @all
next

lpando08
Posts: 22
Joined: Tue Apr 03, 2018 1:13 pm

Re: Problem with recognition of decimals

Postby lpando08 » Mon May 14, 2018 10:54 am

Thank you very much! It works!


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests