Page 1 of 1

Compare two series with loop

Posted: Thu Apr 12, 2012 8:58 am
by sauterelle
Hi all, I got trouble comparing two series with unequal observations. My real data is huge so I just create a trial data to work on that at this moment. As in the picture that I attached, originally I have 5 series Analyst, analyst_1, day, day_1 and value_1.
I want to create a new series called Value that takes value of Value_1 if analyst=analyst_1 and day < day_1. The trouble is the comparison is not row by row. For example, if the first line analyst(1) = analyst_1(1) and day(1) > day_1(1), the program will keep compare the next pair day(1) with day_1(2). If the condition is satisfied ( day(1) < day_1(2)), value(1) will equal value_1(2) or 1.1 as in the pic. So for every pair analyst and analyst_1 equal, each obs in day will be compared to each observation in day_1 correspondingly.

This is the code that I write for this trial data

SERIES value

FOR !i=1 TO @obsrange
FOR !j=1 TO @obsrange
IF analyst(!i)=analyst_1(!j) AND day(!i) <= day_1(!j) THEN value(!i)=value_1(!j)

ENDIF
NEXT
NEXT

It works but if I use it for my real data ( which the no of obs is 120 000), the program takes forever to run. I am just wondering if there is a more elegant way to do this.

I am really appreciated if anyone could help.

Re: Compare two series with loop

Posted: Thu Apr 12, 2012 9:04 am
by EViews Gareth

Code: Select all

series value = @recode(analyst = analyst_1 and day<day_1, value_1, NA)

Re: Compare two series with loop

Posted: Thu Apr 12, 2012 10:43 pm
by sauterelle
Hi, thx Gareth
I tried using @recode before but it seems that the comparison is made row by row ( i.e day(1) with day_1(1), day(2) with day_1(2)) rather than between day(1) with each obs of day_1 for the same analyst). I attached the output that I got, the new series value is different from what it is supposed to be as in my previous post.

Re: Compare two series with loop

Posted: Fri Apr 13, 2012 6:47 am
by EViews Gareth
I'm lost then. Perhaps you could describe the comparison you're trying to make again.