IF statement: make it limited to sample?

For questions regarding programming in the EViews programming language.

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

Danxxx
Posts: 11
Joined: Mon Jun 07, 2010 10:06 am

IF statement: make it limited to sample?

Postby Danxxx » Mon Jun 07, 2010 10:19 am

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

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

Re: IF statement: make it limited to sample?

Postby EViews Gareth » Mon Jun 07, 2010 10:35 am

Not clear what you're trying to do.

You can never use if to compare two series.

Danxxx
Posts: 11
Joined: Mon Jun 07, 2010 10:06 am

Re: IF statement: make it limited to sample?

Postby Danxxx » Mon Jun 07, 2010 10:49 am

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.

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

Re: IF statement: make it limited to sample?

Postby EViews Gareth » Mon Jun 07, 2010 10:53 am

Edit: I'm losing my mind. This post made no sense.

startz
Non-normality and collinearity are NOT problems!
Posts: 3797
Joined: Wed Sep 17, 2008 2:25 pm

Re: IF statement: make it limited to sample?

Postby startz » Mon Jun 07, 2010 10:55 am

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.

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

Re: IF statement: make it limited to sample?

Postby EViews Gareth » Mon Jun 07, 2010 11:02 am

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?

Danxxx
Posts: 11
Joined: Mon Jun 07, 2010 10:06 am

Re: IF statement: make it limited to sample?

Postby Danxxx » Mon Jun 07, 2010 1:20 pm

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.

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

Re: IF statement: make it limited to sample?

Postby EViews Gareth » Mon Jun 07, 2010 1:30 pm

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.

Danxxx
Posts: 11
Joined: Mon Jun 07, 2010 10:06 am

Re: IF statement: make it limited to sample?

Postby Danxxx » Mon Jun 07, 2010 2:31 pm

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.


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests