For loops

For questions regarding programming in the EViews programming language.

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

cap
Posts: 55
Joined: Fri Oct 17, 2008 11:47 am

For loops

Postby cap » Fri Feb 05, 2010 12:55 pm

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

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

Re: For loops

Postby EViews Gareth » Wed Feb 10, 2010 8:58 am

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)


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests