Loop with 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

Loop with decimals

Postby lpando08 » Thu Apr 26, 2018 10:41 am

Hello, I'm trying to run this, I mean I want to generate hdebt_10, hdebt_10.5, hdebt_11 up to hdebt_12, the same for ldebt. But Eviews can´t generate hdebt_10.5, I do not why. It shows a message like this "5 is not a member or procedure of hdebt_10 in "series hdebt_!x"=1" How I can compute the series with decimals?

for !x=10 to 12 step 0.5
smpl if debt>!x
series hdebt_!x=1
smpl @all

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

call regressions
next

Thanks for your help!

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

Re: Loop with decimals

Postby EViews Gareth » Thu Apr 26, 2018 11:00 am

Object names cannot contain periods/points.
Follow us on Twitter @IHSEViews

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

Re: Loop with decimals

Postby lpando08 » Thu Apr 26, 2018 2:40 pm

I'm trying to run this to generate hdebt_105=1 when debt>10.5... because I can't generate hdebt_10.5 because of the point bu it doesn't work. How I could do this?

for !x=10 to 12 step 0.5
smpl if debt>!x
for !i=100 to 120 step 5
series hdebt_!i=1
smpl @all


for !x=10 to 12 step 0.5
smpl if debt<!x
for !i=100 to 120 step 5
series ldebt_!i=1
smpl @all

string grps = "hdebt_!i ldebt_!i"
call regressions
next
next
next
next

EViews Matt
EViews Developer
Posts: 239
Joined: Thu Apr 25, 2013 7:48 pm

Re: Loop with decimals

Postby EViews Matt » Thu Apr 26, 2018 3:24 pm

Hello,

You can create a string version of the number and then use @replace to remove the ".", e.g., @replace(@str(!x), ".", "").

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

Re: Loop with decimals

Postby EViews Gareth » Thu Apr 26, 2018 3:33 pm

Or, use @makevalidname
Follow us on Twitter @IHSEViews

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

Re: Loop with decimals

Postby lpando08 » Thu Apr 26, 2018 3:37 pm

I have tried to run it like this, it could work?

for !x=10 to 12 step 0.5
!i=!x*10
smpl if debt>!x
series hdebt_!i=1
smpl @all

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

EViews Matt
EViews Developer
Posts: 239
Joined: Thu Apr 25, 2013 7:48 pm

Re: Loop with decimals

Postby EViews Matt » Thu Apr 26, 2018 3:40 pm

Sure, go ahead and run it to find out.

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

Re: Loop with decimals

Postby lpando08 » Thu Apr 26, 2018 3:46 pm

Ok, it doesn't, it generates hdebt_100 but then a message window error shows that it hadn't find " hdebt_1001". I don't know why from hdebt_100 it goes to hdebt_1001.

EViews Matt
EViews Developer
Posts: 239
Joined: Thu Apr 25, 2013 7:48 pm

Re: Loop with decimals

Postby EViews Matt » Thu Apr 26, 2018 4:21 pm

Did you accidentally type "hdebt_!i1" somewhere in your code?

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

Re: Loop with decimals

Postby lpando08 » Thu Apr 26, 2018 11:13 pm

No, there is no a 1. It is weird, however if I want to use what you said, the code @replace to have hdebt_105 instead of hdebt_10.5 that is not possible, where I have to put this code @replace(@str(!x), ".", "") ? Thank you very much for your help.

for !x=10 to 12 step 0.5
smpl if debt>!x
series hdebt_!x=1
smpl @all

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

EViews Matt
EViews Developer
Posts: 239
Joined: Thu Apr 25, 2013 7:48 pm

Re: Loop with decimals

Postby EViews Matt » Fri Apr 27, 2018 8:59 am

Creating a string to hold the result of that expression will work, e.g.,

Code: Select all

string tmp = @replace(@str(!x), ".", "")
series hdebt_{tmp}=1


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 1 guest