Discrete values and doloop

Use this forum to post questions about syntax problems or general programming issues. Questions on implementing a particular aspect of econometrics should go in "Econometrics Issues" below.
samson
Posts: 10
Joined: Fri Apr 20, 2012 3:53 am

Discrete values and doloop

Unread post by samson »

Hi

Is that possible to run a doloop with discrete values in RATS?

For example, I would like to show 1-5, 6, 7 and 11-21 instead of 1-21.

I cannot figure out how to do so by the "do" instructions~~~

*******
Maybe we can create a BIG matrix and let 1-5, 6, 7, 11-21 be the element in first row.

And then we use a(1,j) and doloop to run a doloop with discrete values.

But I think this approach is not so flexiable~~

(If we want to run doloop for "1-5, 7", "6-15, 11, 20", and "5-21",
then the matrix will have 6, 12, and 17 elements in first, second, and third row. )
*******
**************************************************************************************************************

Another question is that given the names of variables or series include numbers,

how to make the following codes recognizable for RATS?

Code: Select all

comp all1 = 9
comp all6 = 10
disp all1
disp all6

comp i = 1
disp alli
comp i = 6
disp alli
The error message is:

## SX11. Identifier ALLI is Not Recognizable. Incorrect Option Field or Parameter Order?
>>>>disp alli<<<<


best regards,
Samson
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Discrete values and doloop

Unread post by TomDoan »

That's exactly what the DOFOR loop does.
samson
Posts: 10
Joined: Fri Apr 20, 2012 3:53 am

Re: Discrete values and doloop

Unread post by samson »

Thanks



What I really want to do is:

First assign value for a variable (choice), and use if-else sentence to get corresponding variables.

Code: Select all

COMPUTE choice = (1 or 2 or 3)
IF choice == 1
{
JJ = 1-5, 11-15
}
ELSE IF choice == 2
{
JJ = 1-5, 31-35
}
ELSE IF choice == 3
{
JJ = 16-20
}
where JJ indicates the variables we use.

(If choice = 1, then we use first to fifth and thirty-first to thirty-fifth variables, and so forth.)

In DOFOR instruction, is that possible to write:

Code: Select all

com j =0
dofor i = JJ
 comj = j+1 


(JJ is list of variables.)

I don't know whether RATS can recognize JJ or not~~


Samson
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Discrete values and doloop

Unread post by TomDoan »

Based upon the sound of this, you probably want to use a VECT[VECT[INT]] to make the three lists:

dec vect[vect[int]] myjj(3)
compute myjj(1)=||1,2,3,4,5,11,12,13,14,15||
compute myjj(2)=||1,2,3,4,5,31,32,33,34,35||
compute myjj(3)=||16,17,18,19,20||

You would then use myjj(choice) and elements of it. For instance,

do i=1,%size(myjj(choice))
disp myjj(choice)(i)
end do i

would show the set of values in myjj(choice), one per line. If you are doing something more involved with each index, you could do

dofor i = myjj(choice)
...
end dofor i

In this case, i walks through the values in myjj(choice).
Post Reply