Dummy variable UP/Down

For questions regarding programming in the EViews programming language.

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

Sima77
Posts: 23
Joined: Sat May 01, 2021 10:07 am

Dummy variable UP/Down

Postby Sima77 » Mon Jul 24, 2023 8:01 am

Hi, I have multiple time series of stock returns, I want to create dummy variables that are 1 when the return increase and 0 when the return decrease. The problem am facing when the returns is the same for several months. For instance, the returns for the following 7 months are 3,4,2,5,5,5,5, I want the dummy variable to be 1 for the last 4 months and not only for the fourth month. Please I would appreciate any help.

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

Re: Dummy variable UP/Down

Postby EViews Gareth » Mon Jul 24, 2023 8:15 am

When you create your dummy variable, instead of using ">", use ">=" instead.
Follow us on Twitter @IHSEViews

Sima77
Posts: 23
Joined: Sat May 01, 2021 10:07 am

Re: Dummy variable UP/Down

Postby Sima77 » Mon Jul 24, 2023 8:41 am

Thanks for reply. I used this command: series dummy=@recode(y>=y(-1),1,0), but I still have the same problem.Please can you advice?

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

Re: Dummy variable UP/Down

Postby EViews Gareth » Mon Jul 24, 2023 9:00 am

It works.

Code: Select all

wfcreate u 7
series y
y.fill 3,4,2,5,5,5,5
series dummy = @recode(y>=y(-1),1,0)
show dummy
Follow us on Twitter @IHSEViews

Sima77
Posts: 23
Joined: Sat May 01, 2021 10:07 am

Re: Dummy variable UP/Down

Postby Sima77 » Mon Jul 24, 2023 9:56 am

Sorry, It is my bad that I did not well explain what I want to do. I attached an Excel file in which I typed the Dummy that I want. Please can you help which code can do that? Much appreciated,
Attachments
Dummy.xlsx
Dummy
(15.71 KiB) Downloaded 112 times

Sima77
Posts: 23
Joined: Sat May 01, 2021 10:07 am

Re: Dummy variable UP/Down

Postby Sima77 » Tue Jul 25, 2023 6:57 am

I would appreciate it if I get a reply to my question.

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

Re: Dummy variable UP/Down

Postby startz » Tue Jul 25, 2023 7:02 am

Gareth's suggestion does what you ask. In your file you have the dummy stay zero if the return stays constant after it first falls. Is that what you want?

Sima77
Posts: 23
Joined: Sat May 01, 2021 10:07 am

Re: Dummy variable UP/Down

Postby Sima77 » Tue Jul 25, 2023 8:35 am

Yes, I want the dummy to stay constant (0 or 1) if the return stays constant. Please can you help?

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

Re: Dummy variable UP/Down

Postby EViews Matt » Tue Jul 25, 2023 1:13 pm

Hello,

Building on Gareth's example, a self-referential expression lets you maintain the previous dummy value in the case that the return is constant.

Code: Select all

series dummy = @recode(y>y(-1),1,@recode(y<y(-1),0,@nan(dummy(-1),1)))

Sima77
Posts: 23
Joined: Sat May 01, 2021 10:07 am

Re: Dummy variable UP/Down

Postby Sima77 » Wed Jul 26, 2023 10:41 am

Amazing, this is exactly what I want. Thanks.


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 22 guests