Handle two temporary control variables in nested loops

For questions regarding programming in the EViews programming language.

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

ohubert
Posts: 8
Joined: Thu Apr 21, 2022 2:21 am

Handle two temporary control variables in nested loops

Postby ohubert » Fri May 13, 2022 7:38 am

Hi all,

I am try to automate some computation with transformation of series names.
The problem that I have is that the temporary variable used as counter in the loop does not allow me to loop over lists of characters.

I come from MATLAB, so my way of doing things may not be the most appropriate for EVIEWS.

The code under does the following:
1) generate random series
2) generate names objects (one short name, one long)
3) Loop over the potential variable name and execute a simple expression




Code: Select all

wfcreate(wf=annual, page=myproject) a 1950 2005
genr series1=nrnd
genr series2= 0.9*series1(-1)+ 0.1*nrnd

alpha shortnames
shortnames(1) = "short1"
shortnames(2) = "short2"

alpha longnames
longnames(1) = "series1"
longnames(2) = "series2"

group grouptest

for !i=1 to 2 ' loop over the variables
      %stringtemp=shortnames(!i) 'create temporary variable for the short name
      %stringtemp2=longnames(!i) 'create temporary variable for the long name
for !j=1 to 2      
series test{%stringtemp}{!j}= {%stringtemp2} - !i + 10*!j
   grouptest.add test{%stringtemp}{!j}
next
next

grouptest.line(m)
‘The series testXXX should be testshort11 and not testseries11



The expected behavior should be the following:
a series testshort11 which would take the values of series1 - 1 +10
a series testshort12 which would take the values of series1 - 1 +20
a series testshort21 which would take the values of series2 - 2 +10
a series testshort22 which would take the values of series2 - 2 +20

Instead, the names of the series created remain testseriesXX. I suspect that Eviews does not handle two temporary variables at the same time (%stringtemp and %stringtemp2).


Thanks in advance for the help you can provide.

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

Re: Handle two temporary control variables in nested loops

Postby EViews Gareth » Fri May 13, 2022 9:01 am

Not sure I follow. If I run your code I get this:
2022-05-13_090044.png
2022-05-13_090044.png (113.51 KiB) Viewed 1148 times


Which seems to be what you think should happen?


As an aside, you should probably be using svectors rather than alphas.
Follow us on Twitter @IHSEViews

ohubert
Posts: 8
Joined: Thu Apr 21, 2022 2:21 am

Re: Handle two temporary control variables in nested loops

Postby ohubert » Mon May 16, 2022 11:39 pm

Thank you for having a look.

For some reason, it did not run correctly on my machine. It does now.

Thanks again.


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 11 guests