How to run the program for Sampled year only and get result

For questions regarding programming in the EViews programming language.

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

nidhijain
Posts: 4
Joined: Tue Jan 16, 2018 2:10 am

How to run the program for Sampled year only and get result

Postby nidhijain » Wed Jan 17, 2018 2:13 am

I am an EViews10 user.
I have a series from 1990 to 2050, which has mix set of values, 0, positive and negative.(attached work file). I want to check the values inside series for each year from 2022 to 2050 separately and publish result as passed if value is positive and failed if negative.

I have tried using both these methods, but no luck. Every time, this code runs, even after taking sample, the condition run for entire series from 1990 to 2050 and not for one single year, and publish result as "passed" even for negative value years.

Please help how to run the program only for the sampled year and get the desired result.

Method 1:

logmode logmsg
smpl 1990 2050
eth_apd_ag = @recode(eth_apd_ag=NA,0,eth_apd_ag)
for !y = 2022 to 2050
smpl !y !y
if eth_apd_ag<0 then
logmsg failed for year !y
else
logmsg passed for year !y
endif
next


Method 2:

logmode logmsg
smpl 1990 2050
eth_apd_ag = @recode(eth_apd_ag=NA,0,eth_apd_ag)
for !y = 2022 to 2050
smpl 1990 2050
%sname = "Ser" + @str(!y)
series {%sname} = @recode(eth_apd_ag>0,1,0)
smpl !y !y
if {%sname}=0 then
logmsg failed for year !y
else
logmsg passed for year !y
endif
next
Attachments
SampleData.WF1
(12 KiB) Downloaded 218 times

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

Re: How to run the program for Sampled year only and get result

Postby EViews Gareth » Wed Jan 17, 2018 9:26 am

You can't use a series in an if condition.

You can use the max of a series in an if condition.
Follow us on Twitter @IHSEViews

nidhijain
Posts: 4
Joined: Tue Jan 16, 2018 2:10 am

Re: How to run the program for Sampled year only and get result

Postby nidhijain » Wed Jan 17, 2018 11:23 pm

But in that case as well,how to check data only for sample years, like i want to check data for only 2022 to 2050. But each time i put a check, it runs on the entire set of data and not on sample years and gives pass or fail according to that.

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

Re: How to run the program for Sampled year only and get result

Postby EViews Gareth » Thu Jan 18, 2018 12:01 am

Set the sample to the year you want, then check whether the maximum of the series is >0
Follow us on Twitter @IHSEViews

nidhijain
Posts: 4
Joined: Tue Jan 16, 2018 2:10 am

Re: How to run the program for Sampled year only and get result

Postby nidhijain » Thu Jan 18, 2018 10:22 pm

Thanks a lot. It is working now. :D


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 29 guests