## What's the eviews equivalent of Excel's countif?

For questions regarding programming in the EViews programming language.

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

miorinnovo
Posts: 137
Joined: Sun Mar 01, 2015 5:01 pm

### What's the eviews equivalent of Excel's countif?

I want to know how many positive numbers are in a series. in Excel its a simple countif > o type formula. What would be the eviews equivalent?

Thanks!

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

### Re: What's the eviews equivalent of Excel's countif?

@sum(x>0)

miorinnovo
Posts: 137
Joined: Sun Mar 01, 2015 5:01 pm

### Re: What's the eviews equivalent of Excel's countif?

Thanks but I'm not getting that to work.

I get this message:

NA found in matrix in "SCALAR TEST= @SUM(x>0)".

The sereies has some Nas, but even when I fill them in I get this error message:

Scalar sent to function which operates on a matrix in "SCALAR TEST=@SUM(x>0)".

Any ideas?

Thanks

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

### Re: What's the eviews equivalent of Excel's countif?

Not sure, but are you sure that X is a series as opposed to a vector or matrix?

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

### Re: What's the eviews equivalent of Excel's countif?

You have to, unfortunately, do it in two steps.

Code: Select all

`smpl if x1>0scalar test = @obssmpl`

miorinnovo
Posts: 137
Joined: Sun Mar 01, 2015 5:01 pm

### Re: What's the eviews equivalent of Excel's countif?

Thanks Gareth!

miorinnovo
Posts: 137
Joined: Sun Mar 01, 2015 5:01 pm

### Re: What's the eviews equivalent of Excel's countif?

Can I use this sample sample trick to replace outliers in a series with NAs? Say I want to remove the highest and lowest 5% of observations in a series can i put somehting in this blank space that would do that?

Code: Select all

`  smpl if x1>_____    `

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

### Re: What's the eviews equivalent of Excel's countif?

You certainly can, but look at the @replace function which might be easier.

miorinnovo
Posts: 137
Joined: Sun Mar 01, 2015 5:01 pm

### Re: What's the eviews equivalent of Excel's countif?

Im not familiar with the replace function but I found the following code which worked well. Thanks

Code: Select all

`series y = @recode(@abs(x) < @quantile(@abs(x), .9), x, na)`

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

### Re: What's the eviews equivalent of Excel's countif?

I meant @recode. So you're ahead of me.

miorinnovo
Posts: 137
Joined: Sun Mar 01, 2015 5:01 pm

ah, ok. Thanks.