Page 1 of 1

IF statement: make it limited to sample?

Posted: Mon Jun 07, 2010 10:19 am
by Danxxx
I need to compare two GDP series, one is 1970-2009 and the other is 1980-2009. So the first has more history. But I only want to compare over 1980-2009. I tried
smpl 1980 2009
and then did
if ser1=ser2 then...
But I got errors due to the NAs in 1970-1979 in the later-starting series.
Q: Is there any way to make the IF condition look at the current sample years only?

TIA,
Dan

Re: IF statement: make it limited to sample?

Posted: Mon Jun 07, 2010 10:35 am
by EViews Gareth
Not clear what you're trying to do.

You can never use if to compare two series.

Re: IF statement: make it limited to sample?

Posted: Mon Jun 07, 2010 10:49 am
by Danxxx
Not clear what you're trying to do.

You can never use if to compare two series.
Are you sure? I just did a simple test:

Made these series

Year ser1 ser2
2001 1.0 1.0
2002 2.5 2.5
2003 3.0 3.0
2004 4.0 4.0

then ran this program
text res1
if ser1=ser2 then
res1.append "ser1=ser2"
endif


and the text was pasted into the text box.

Re: IF statement: make it limited to sample?

Posted: Mon Jun 07, 2010 10:53 am
by EViews Gareth
Edit: I'm losing my mind. This post made no sense.

Re: IF statement: make it limited to sample?

Posted: Mon Jun 07, 2010 10:55 am
by startz
In case it's helpful, the manual says
You should take care when using the IF statement with series or matrices to note that the comparison is defined on the entire object and will evaluate to false unless every element of the element-wise comparison is true.

Re: IF statement: make it limited to sample?

Posted: Mon Jun 07, 2010 11:02 am
by EViews Gareth
My previous (now edited) post was completely wrong, sorry.

I'm still not sure what you are trying to do though.

You're just trying to test whether two series are identical over a sub-sample?

Re: IF statement: make it limited to sample?

Posted: Mon Jun 07, 2010 1:20 pm
by Danxxx
I'm still not sure what you are trying to do though.

You're just trying to test whether two series are identical over a sub-sample?
Yes, exactly. Suppose I have

Year ser1 ser2
2000 1.0 NA
2001 2.0 2.0
2002 3.0 3.0
2003 4.0 4.0

I did
smpl 2001 2003
but then the statement
if ser1=ser2 then ..
yielded an error because of the NA in 2000. I thought 'smpl 2001 2003' would avoid that.

So basically I'm looking for a way to check equality in 2001-2003. Any ideas would be welcome.

Re: IF statement: make it limited to sample?

Posted: Mon Jun 07, 2010 1:30 pm
by EViews Gareth
As I said, you shouldn't really use an if statement on a series.

Perhaps the best way to do it would be something like:

Code: Select all

series equal = (ser1=ser2) smpl 2001 2003 if @sum(equal)=@obssmpl then blah blah blah endif
i.e. create a dummy variable equal to 1 whenever the two series are equal, and 0 if they're not. Then compare the sum of that dummy variable with the total number of observations in the sample.

Re: IF statement: make it limited to sample?

Posted: Mon Jun 07, 2010 2:31 pm
by Danxxx
Thanks, that looks good.
It's possible one of the series might have an NA in the sample period; I'll try to find a function to use on @sum(equal) to check for that.