Separate positive and negative values

For questions regarding the import, export and manipulation of data in EViews, including graphing and basic statistics.

Moderators: EViews Gareth, EViews Steve, EViews Jason, EViews Moderator, EViews Pamela

Posts: 4
Joined: Sun Jul 30, 2017 6:26 am

Separate positive and negative values

Postby smrehman » Wed Aug 02, 2017 3:54 am

I need to separate positive and negative values from my file deltaop_us

In the research paper "Oil price shocks and stock market activities: Evidence
from oil-importing and oil-exporting countries" by Yudong Wang (2012)

they use
dopt+=max(0, deltaop_us)
dopt-=min(0, deltaop_us)

and later dopt# E { dopt+,dopt- }

i tried running the code, as well as this code (I got this from another thread on the forum)
Genr Pos_deltaop_us=0.5((@abs(deltaop_us)*deltaop_us))
Genr Neg_deltaop_us=0.5((@abs(deltaop_us)*deltaop_us))

Doing the above, all I could generate was one file with the positive values and a "0" where the negative values were originally.

Does anyone know the solution to my problem?

Thank you for reading!

In addition:
When I try to use genr positive_deltaop_us=max(0,deltaop_us)
It says "Illegal lag or index specification"

EViews Matt
EViews Developer
Posts: 262
Joined: Thu Apr 25, 2013 7:48 pm

Re: Separate positive and negative values

Postby EViews Matt » Wed Aug 02, 2017 10:06 am


The easiest way to do this in EViews is to use samples or @recode. I'll demonstrate an @recode approach:

Code: Select all

genr pos_deltaop_us = @recode(delta_op > 0, delta_op, 0)
genr neg_deltaop_us = @recode(delta_op < 0, delta_op, 0)

If you want the filtered out values to be NAs instead of zeros, you can change the last argument to @recode to NA.

Return to “Data Manipulation”

Who is online

Users browsing this forum: No registered users and 4 guests