For loops with numerical variables - resulting object-order

For questions regarding programming in the EViews programming language.

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

Vron
Posts: 6
Joined: Wed Jan 01, 2014 1:27 pm

For loops with numerical variables - resulting object-order

Postby Vron » Sun Feb 02, 2014 1:05 pm

Hello,
I´m running For-loops with numerical variables, just as an example:

rndseed 123
For !i = 1 to 1000
!w1 = @runif(0.1,1)
!w2 = @runif(0.1,1)
!w3 = @runif(0.1,1)
!w1n = (!w1)/(!w1 + !w2 + !w3)
!w2n = (!w2)/(!w1 + !w2 + !w3)
!w3n = (!w3)/(!w1 + !w2 + !w3)
series hdi!i = edu^(!w1n) * lexp^(!w2n) * inc^(!w3n)
next

As a result I´m getting the following object-order in my workfile: hdi1, hdi10, hdi100, hdi 1000, hdi101, hdi102, […], hdi11, hdi110, hdi111, hdi112 and so on

How can I create a “normal” order like this: hdi1, hdi2, hdi3, hdi4, hdi5, etc. ?

Thank you very much!

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

Re: For loops with numerical variables - resulting object-or

Postby EViews Gareth » Sun Feb 02, 2014 4:02 pm

Code: Select all

For !i = 1 to 1000 !w1 = @runif(0.1,1) !w2 = @runif(0.1,1) !w3 = @runif(0.1,1) !w1n = (!w1)/(!w1 + !w2 + !w3) !w2n = (!w2)/(!w1 + !w2 + !w3) !w3n = (!w3)/(!w1 + !w2 + !w3) %str = @str(!i) if (!i<100) then %str = "0" + %str endif if (!i<10) then %str = "00" + %str endif series hdi{%str} = edu^(!w1n) * lexp^(!w2n) * inc^(!w3n) next
or something like that.

EViews Glenn
EViews Developer
Posts: 2682
Joined: Wed Oct 15, 2008 9:17 am

Re: For loops with numerical variables - resulting object-or

Postby EViews Glenn » Mon Feb 03, 2014 10:34 am

Same idea but simpler form of the string conversion. The "i04" format string tells EViews to produce a 4 digit string integer representation with leading zeros.

Code: Select all

For !i = 1 to 1000 !w1 = @runif(0.1,1) !w2 = @runif(0.1,1) !w3 = @runif(0.1,1) !w1n = (!w1)/(!w1 + !w2 + !w3) !w2n = (!w2)/(!w1 + !w2 + !w3) !w3n = (!w3)/(!w1 + !w2 + !w3) %str = @str(!i, "i04") series hdi{%str} = edu^(!w1n) * lexp^(!w2n) * inc^(!w3n) next

Vron
Posts: 6
Joined: Wed Jan 01, 2014 1:27 pm

Re: For loops with numerical variables - resulting object-or

Postby Vron » Tue Feb 04, 2014 9:50 am

Thank you very much! Both works! :D


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests