Conditional sum (i.e.: sum if) over a vector

For questions regarding programming in the EViews programming language.

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

grabodan
Posts: 7
Joined: Thu Jun 11, 2015 6:36 am

Conditional sum (i.e.: sum if) over a vector

Postby grabodan » Mon Jun 15, 2015 3:12 am

Dear Members,

I am having a presumably very common problem:
Simulating a time series many times, then conducting a test, and then check how often the Null hypothesis was rejected.
That way I can test the size and power of the test. At the end I store the p-values in a vector (not a series).

I need the sum of entries in that vector that are less then 5%.
And I dont find a command for this. Like the simple Excel "sumif".

The question might have been answered a million times, but I didnt find any of these.
The Problem can be solved by a for loop such as:

Code: Select all

count=0
for !i=1 to !mcmax
    if pvalue(!i) <0.05 then
       count= count+1
    endif
next


Question: Is there a command for this?

Maybe I can use @sumsby. But then it seems to me that I have to (a) use a series instead of a vector which is not so nice and (b) first have to specify a new series containing a 1 if pvalue<0.05 and a zero otherwise. Doing (b) would again require a loop such as the one above, doesn't it?


To add some naivety to my question: How can I, generally, find commands like the sumsby? Or find a command that does what I am looking for in the above question? I often only get anywhere by searching the forum and I am having a hard time finding what I am looking for in the Help files. Am I doing somewhing wrong? ;)

Thanks 2 everyone!
Daniel

trubador
Did you use forum search?
Posts: 1518
Joined: Thu Nov 20, 2008 12:04 pm

Re: Conditional sum (i.e.: sum if) over a vector

Postby trubador » Mon Jun 15, 2015 6:35 am

Code: Select all

vector reject = @elt(pvalue,0.05*@ones(!mcmax))
scalar count = @sum(reject)

grabodan
Posts: 7
Joined: Thu Jun 11, 2015 6:36 am

Re: Conditional sum (i.e.: sum if) over a vector

Postby grabodan » Mon Jun 15, 2015 7:13 am

Thanks a lot trubador!
That does the job.

(I combined it to save space :) scalar count = @sum(@elt(pwerte_05,0.05*@ones(!mcmax)))


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 17 guests