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.
Compare two series with loop
Moderators: EViews Gareth, EViews Steve, EViews Moderator, EViews Jason
-
sauterelle
- Posts: 3
- Joined: Mon Sep 05, 2011 9:22 pm
Compare two series with loop
- Attachments
-
- eviews.jpg (65.41 KiB) Viewed 4010 times
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13604
- Joined: Tue Sep 16, 2008 5:38 pm
Re: Compare two series with loop
Code: Select all
series value = @recode(analyst = analyst_1 and day<day_1, value_1, NA)
-
sauterelle
- Posts: 3
- Joined: Mon Sep 05, 2011 9:22 pm
Re: Compare two series with loop
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.
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.
- Attachments
-
- eviews1.jpg (37.97 KiB) Viewed 3995 times
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13604
- Joined: Tue Sep 16, 2008 5:38 pm
Re: Compare two series with loop
I'm lost then. Perhaps you could describe the comparison you're trying to make again.
Who is online
Users browsing this forum: No registered users and 2 guests
