Page 1 of 1

For loops with numerical variables - resulting object-order

Posted: Sun Feb 02, 2014 1:05 pm
by Vron
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!

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

Posted: Sun Feb 02, 2014 4:02 pm
by EViews Gareth

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.

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

Posted: Mon Feb 03, 2014 10:34 am
by EViews Glenn
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

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

Posted: Tue Feb 04, 2014 9:50 am
by Vron
Thank you very much! Both works! :D