%if statements in dofor loops?

For questions and discussion related to reading in and working with data.
e1983
Posts: 20
Joined: Sun Aug 28, 2011 2:32 am

%if statements in dofor loops?

Unread post by e1983 »

Hi. I trying to figure out a bug in my code. I have 100 or so series and I am trying to clean up any missing values.I am trying to use the following code. If I use the dofor loop, I only get a column of 1s. If I use the code outside of the loop, the Na observation is fixed according to the %if statement. Can %if statements not be used inside of a dofor loop? Any help would be greatly appreciated.


dofor i = RPI
set %s(%l(i)) = %if(%valid(i), i, (i{1} + i{-1})/2)
end
set rpi = %if(%valid(rpi), rpi, (rpi{1} + rpi{-1})/2)
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: %if statements in dofor loops?

Unread post by TomDoan »

You need i{0} to get the current value of the series for the DOFOR index.
e1983
Posts: 20
Joined: Sun Aug 28, 2011 2:32 am

Re: %if statements in dofor loops?

Unread post by e1983 »

Thanks. Works perfectly now. Much appreciated.
Post Reply