search x and replace with Y IF (eviews 7)

For questions regarding programming in the EViews programming language.

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

mark
Posts: 37
Joined: Thu Mar 12, 2009 3:27 pm

search x and replace with Y IF (eviews 7)

Postby mark » Thu Apr 29, 2010 1:35 pm

Hi
I have a series with 65,000 observations where the value varies from 1 to 12
I need to find values 1 to 3, 4 though 6, 7 through 9 and 10 through 12 then generate a new series containing values of 1, 2, 3, or 4 in the approrpiate cells
I've been attempting this with the following code to no avail
Any suggestions would be appreciated


program mytest
workfile test u 1 65535
fetch allbids09:: openingdate
' transforming date string to common units
series test=@datepart(openingdate, "mm")
series test2=@datepart(openingdate, "yy")
if test >=1 and test <=3 then
series qrtr =1
if test >3 and test <=6 then
series qrtr2=2
if test>6 and test <=9 then
series qrtr3=3
'if test>9 and test <=12 then
series qrtr4=4
endif
endif
endif
endif

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

Re: search x and replace with Y IF (eviews 7)

Postby EViews Gareth » Thu Apr 29, 2010 1:43 pm

You can't use IF statements on series.

Either assign a binary test to the series directly (with no if):

Code: Select all

series qrt1 = test>1 and test<=3
or use the @recode function

Code: Select all

series qrt1 = @recode(test>1 and test<=3, 1, 0)
or use the smpl statement:

Code: Select all

smpl if test>1 and test<=3 series qrt1 = 1 smpl @all
Of course, looking through your earlier code, it might be simpler to just do:

Code: Select all

series qrt1 = @datepart(openingdate, "q") = 1

mark
Posts: 37
Joined: Thu Mar 12, 2009 3:27 pm

Re: search x and replace with Y IF (eviews 7)

Postby mark » Thu Apr 29, 2010 2:03 pm

thanks - would have taken me a week
have 2 beers on me


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests