Page 1 of 1
Dummy variable UP/Down
Posted: Mon Jul 24, 2023 8:01 am
by Sima77
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.
Re: Dummy variable UP/Down
Posted: Mon Jul 24, 2023 8:15 am
by EViews Gareth
When you create your dummy variable, instead of using ">", use ">=" instead.
Re: Dummy variable UP/Down
Posted: Mon Jul 24, 2023 8:41 am
by Sima77
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?
Re: Dummy variable UP/Down
Posted: Mon Jul 24, 2023 9:00 am
by EViews Gareth
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
Re: Dummy variable UP/Down
Posted: Mon Jul 24, 2023 9:56 am
by Sima77
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,
Re: Dummy variable UP/Down
Posted: Tue Jul 25, 2023 6:57 am
by Sima77
I would appreciate it if I get a reply to my question.
Re: Dummy variable UP/Down
Posted: Tue Jul 25, 2023 7:02 am
by startz
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?
Re: Dummy variable UP/Down
Posted: Tue Jul 25, 2023 8:35 am
by Sima77
Yes, I want the dummy to stay constant (0 or 1) if the return stays constant. Please can you help?
Re: Dummy variable UP/Down
Posted: Tue Jul 25, 2023 1:13 pm
by EViews Matt
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)))
Re: Dummy variable UP/Down
Posted: Wed Jul 26, 2023 10:41 am
by Sima77
Amazing, this is exactly what I want. Thanks.