Looping

Hi i'm trying to make a loop, concatenating the columns of the data_0 file

one at a time

do while i<4
q = data_0[.,1]~data_0[.,i]
i=1+1
endo;

it's not working and i don't know why !

can you help me ?

1 Answer



0



I see a couple of problems:

  • All GAUSS statements need to end with a semi-colon. You are missing semi-colons on several of the lines
  • Your loop keeps running until i is greater than 4, but i is assigned to be equal to 2 (1 + 1) each time in the loop, so the loop will keep running forever.

I would also change it to use a for loop instead. Like this:

//counter(start, stop, step_size)
for i(1, 4, 1);
   q = data_0[.,1] ~ data_0[.,i];
endfor;

If q will always be a matrix with 2 columns in this loop, then I would change it to something like this:

//Make 'q' a matrix with 2 columns
q = data_0[.,1 2]; 
for i(1, 4, 1);
   //Swap out the 2nd column
   q[.,2] = data_0[.,i];
endfor;

which should be faster.

aptech

1,773

Your Answer

1 Answer

0

I see a couple of problems:

  • All GAUSS statements need to end with a semi-colon. You are missing semi-colons on several of the lines
  • Your loop keeps running until i is greater than 4, but i is assigned to be equal to 2 (1 + 1) each time in the loop, so the loop will keep running forever.

I would also change it to use a for loop instead. Like this:

//counter(start, stop, step_size)
for i(1, 4, 1);
   q = data_0[.,1] ~ data_0[.,i];
endfor;

If q will always be a matrix with 2 columns in this loop, then I would change it to something like this:

//Make 'q' a matrix with 2 columns
q = data_0[.,1 2]; 
for i(1, 4, 1);
   //Swap out the 2nd column
   q[.,2] = data_0[.,i];
endfor;

which should be faster.


You must login to post answers.

Have a Specific Question?

Get a real answer from a real person

Need Support?

Get help from our friendly experts.