Page 1 of 1

Handle two temporary control variables in nested loops

Posted: Fri May 13, 2022 7:38 am
by ohubert
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.

Re: Handle two temporary control variables in nested loops

Posted: Fri May 13, 2022 9:01 am
by EViews Gareth
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 3332 times
Which seems to be what you think should happen?


As an aside, you should probably be using svectors rather than alphas.

Re: Handle two temporary control variables in nested loops

Posted: Mon May 16, 2022 11:39 pm
by ohubert
Thank you for having a look.

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

Thanks again.