Page 1 of 1

For loops

Posted: Fri Feb 05, 2010 12:55 pm
by cap
Greetings,

I am having trouble with the following for loop. I would like to make every 12th observation equal to a certain number:

create u 500

series myvar = 0

for !i = 1 to 30 step 12

series myvar(!i) = 5

next



but when I run this code, every single observation, for the whole length of the series, gets assigned the number 5.



Any help would be appreciated.

Thanks in advance,
- cap

Re: For loops

Posted: Wed Feb 10, 2010 8:58 am
by EViews Gareth
setting myvar(!i) = 5 doesn't actually set the !ith value of myvar equal to 5, it sets the entire series (with a lead of !i) equal to 5.

Perhaps the easiest way to do what you want is with a simple @recode, using the @trend function:

series myvar = @recode(@mod(@trend,12)=0,5,0)