## Loop with decimals

For questions regarding programming in the EViews programming language.

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

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

### Loop with decimals

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: 12111
Joined: Tue Sep 16, 2008 5:38 pm

### Re: Loop with decimals

Object names cannot contain periods/points.

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

### Re: Loop with decimals

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: 356
Joined: Thu Apr 25, 2013 7:48 pm

### Re: Loop with decimals

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: 12111
Joined: Tue Sep 16, 2008 5:38 pm

### Re: Loop with decimals

Or, use @makevalidname

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

### Re: Loop with decimals

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: 356
Joined: Thu Apr 25, 2013 7:48 pm

### Re: Loop with decimals

Sure, go ahead and run it to find out.

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

### Re: Loop with decimals

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: 356
Joined: Thu Apr 25, 2013 7:48 pm

### Re: Loop with decimals

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

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

### Re: Loop with decimals

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: 356
Joined: Thu Apr 25, 2013 7:48 pm

### Re: Loop with decimals

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`

### Who is online

Users browsing this forum: No registered users and 18 guests