code for "last and first three trading days of a month"
Moderators: EViews Gareth, EViews Steve, EViews Moderator, EViews Jason
code for "last and first three trading days of a month"
Hey Guys,
we are currently working at a study of a data stream sample to identify the “turn-of-them-month-effect” at the stock market. We are facing some difficulties in modeling the OLS equasion as we want to take the last three trading days and the first three trading days for our examination.
The problem is that we do not quite know how to really only take the trading days. We want to compare the return of the last trading day of the month plus the first three trading days, to the average return of the other days.
The @day coding is not sufficient because the trading days vary in every month…
I am looking forward to receive an answer, will also give feedback whether your solutions lead to a sufficient result…
we are currently working at a study of a data stream sample to identify the “turn-of-them-month-effect” at the stock market. We are facing some difficulties in modeling the OLS equasion as we want to take the last three trading days and the first three trading days for our examination.
The problem is that we do not quite know how to really only take the trading days. We want to compare the return of the last trading day of the month plus the first three trading days, to the average return of the other days.
The @day coding is not sufficient because the trading days vary in every month…
I am looking forward to receive an answer, will also give feedback whether your solutions lead to a sufficient result…
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13603
- Joined: Tue Sep 16, 2008 5:38 pm
Re: code for "last and first three trading days of a month"
Perhaps you could clarify what you're trying to do a bit more?
I think the EViews interpretation of what you're trying to do is this (but I'm not sure):
You have a workfile with a daily dated structure (probably d5, but maybe d7, or, indeed, irregular?).
You want to set the sample so that it is the first three days of the month plus the last day of the month?
After that, I'm not sure what you're trying to do.
I think the EViews interpretation of what you're trying to do is this (but I'm not sure):
You have a workfile with a daily dated structure (probably d5, but maybe d7, or, indeed, irregular?).
You want to set the sample so that it is the first three days of the month plus the last day of the month?
After that, I'm not sure what you're trying to do.
Re: code for "last and first three trading days of a month"
first of all: thanks for the quick reaction!
so we have the daily returns for each trading day of the german stock index from 1988 till 2011. Here an example:
date return
4/27/1988 0.007585142798072315
4/28/1988 -0.0001441142828753847
4/29/1988 -0.0037904472078159
5/02/1988 0.00423173162277768
5/03/1988 -0.007365167741465876
5/04/1988 0.01274396280591849
5/05/1988 -0.003534713816107201
.
.
.
and know we want to run a regression with a dummy variable like: return=c+beta*x
x is our dummy variable which equals 1 for the last and the first 3 trading days of each month ( and 0 for the other days).
the problem is that the last and first 3 TRADING DAYS of a month are not necessarily the last and first 3 DAYS of a month (see example: last trading day is the 4/29/1988 and the first three trading days are 5/2/1988,5/3/1988 and 5/4/1988) So we cannot use the command @day for our dummy variable.
how can we define our dummy variable? which command can we use to get the first 3 and the last oberservations (trading days) of each month?
so we have the daily returns for each trading day of the german stock index from 1988 till 2011. Here an example:
date return
4/27/1988 0.007585142798072315
4/28/1988 -0.0001441142828753847
4/29/1988 -0.0037904472078159
5/02/1988 0.00423173162277768
5/03/1988 -0.007365167741465876
5/04/1988 0.01274396280591849
5/05/1988 -0.003534713816107201
.
.
.
and know we want to run a regression with a dummy variable like: return=c+beta*x
x is our dummy variable which equals 1 for the last and the first 3 trading days of each month ( and 0 for the other days).
the problem is that the last and first 3 TRADING DAYS of a month are not necessarily the last and first 3 DAYS of a month (see example: last trading day is the 4/29/1988 and the first three trading days are 5/2/1988,5/3/1988 and 5/4/1988) So we cannot use the command @day for our dummy variable.
how can we define our dummy variable? which command can we use to get the first 3 and the last oberservations (trading days) of each month?
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13603
- Joined: Tue Sep 16, 2008 5:38 pm
Re: code for "last and first three trading days of a month"
What structure does your workfile have?
Re: code for "last and first three trading days of a month"
what do you mean with structure?
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13603
- Joined: Tue Sep 16, 2008 5:38 pm
Re: code for "last and first three trading days of a month"
Do you have daily (5 day week), daily (7 day week), or daily (irregular) data?
The process is different depending on how your workfile is structured. You can check what your workfile currently has by clicking on Proc->Structure/Resize Current Page. Or you can just double click on the "Range: " word at the top of your workfile window.
The process is different depending on how your workfile is structured. You can check what your workfile currently has by clicking on Proc->Structure/Resize Current Page. Or you can just double click on the "Range: " word at the top of your workfile window.
Re: code for "last and first three trading days of a month"
when i click on range the following appears:
workfile structure typ: dated - regular frequency
frequency: daily - 5 day week
start date: 12/30/1987
end date: 11/01/2011
so we have a 5 day week i think
workfile structure typ: dated - regular frequency
frequency: daily - 5 day week
start date: 12/30/1987
end date: 11/01/2011
so we have a 5 day week i think
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13603
- Joined: Tue Sep 16, 2008 5:38 pm
Re: code for "last and first three trading days of a month"
ok.
So on non-trading days that aren't a weekend, that date exists in your workfile, but the series you're interested in doesn't have a data in it (it just has an NA)?
So on non-trading days that aren't a weekend, that date exists in your workfile, but the series you're interested in doesn't have a data in it (it just has an NA)?
Re: code for "last and first three trading days of a month"
the weekends are not in our series and if there is a holiday there is just a 0 for the return of that day
and we are not interested in the return of a holiday because it is always zero, so i think it would be better if there is a NA instead of a zero for the holiday
and we are not interested in the return of a holiday because it is always zero, so i think it would be better if there is a NA instead of a zero for the holiday
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13603
- Joined: Tue Sep 16, 2008 5:38 pm
Re: code for "last and first three trading days of a month"
ok. The easiest thing to do would be to convert the workfile page into an irregular, removing all the observations that are not trading days.
To do this click on Proc->Contract Current Page...
Then in the box that appears, delete what's current in there and replace it with:
Where X is the name of the series that has the data.
Once you have an irregular workfile page, you can use the following code to generate a dummy variable:
To do this click on Proc->Contract Current Page...
Then in the box that appears, delete what's current in there and replace it with:
Code: Select all
@all if X<>0
Once you have an irregular workfile page, you can use the following code to generate a dummy variable:
Code: Select all
smpl @all
series d1=1
smpl @first+1 @last
series d1=@iif(@month<>@month(-1), 1, d1(-1)+1)
smpl @all
series d2=@maxsby(d1,@datefloor(@date,"month"))-d1+1
series dummy = d1=1 or d2=1 or d2=2 or d2=3
Re: code for "last and first three trading days of a month"
ok, thanks a lot! but i havent thought that it is so complicated!! is it much easier if we keep the non-trading days and have a regular five day week? or is it still so complicated? it is very hard for us to understand the code you sent us, so we can't assess if eviews has really done the right thing with this code...
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13603
- Joined: Tue Sep 16, 2008 5:38 pm
Re: code for "last and first three trading days of a month"
Well, obviously, there is nothing built in that will give you then dummy variable that you want, and given the non-standard nature of your data, it takes a little bit of coding to get what you want, but it isn't too hard to follow. I'll break it down for you:
Set the current sample to be everything, and create a series, called D1, that is equal to 1.
Set the sample to be the 2nd observation (@first+1) to the last observation - i.e. every observation apart from the first.
Then set d1 equal to an if condition. The interpretation is "if the month of this observation is not equal to the month of the previous observation, set d1 equal to 1. Other wise set it equal to the previous value of d1 plus 1". This creates an incremental series that resets at 1 on the first, existing, day of each month. It is the equivalent of @day, but rather than using the exact calendar, it uses only the dates you have in your workfile (i.e. only trading days).
Set the sample back to everything again. Then create a second series, D2, that is the opposite of the first - it starts at 1 for the last day of the month, and counts backwards. It does this by finding the maximum number of days in the month (@maxsby(d1, @datefloor(@date, "month"))), and taking off the value of the first series created, d1, plus 1.
Finally create the dummy variable you want. It is equal to 1 whenever (d1=1) (i.e. the first day of the month), or (d2=1) (i.e. the last day of the month), or (d2=2) (i.e. the penultimate day of the month), or (d2=3) (i.e. the antepenultimate day of the month).
Code: Select all
smpl @all
series d1=1
Code: Select all
smpl @first+1 @last
series d1=@iif(@month<>@month(-1), 1, d1(-1)+1)
Then set d1 equal to an if condition. The interpretation is "if the month of this observation is not equal to the month of the previous observation, set d1 equal to 1. Other wise set it equal to the previous value of d1 plus 1". This creates an incremental series that resets at 1 on the first, existing, day of each month. It is the equivalent of @day, but rather than using the exact calendar, it uses only the dates you have in your workfile (i.e. only trading days).
Code: Select all
smpl @all
series d2=@maxsby(d1,@datefloor(@date,"month"))-d1+1
Code: Select all
series dummy = d1=1 or d2=1 or d2=2 or d2=3
Re: code for "last and first three trading days of a month"
ok, it is a little bit clearer now. and i've tried it now...i've converted the workfile and after that i've copied your code in to the window program (file->new->program) and pressed on "run" and than a window appears with the heading "run program" and there is: program name or path: untitled
(and some other things i can choose but i don't understand)
so just clicked ok and than 3 new things appear in my workfile called d1, d2 and dummy but where is my regression or do i have to run a regression now? if yes how should i go on?
(and some other things i can choose but i don't understand)
so just clicked ok and than 3 new things appear in my workfile called d1, d2 and dummy but where is my regression or do i have to run a regression now? if yes how should i go on?
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13603
- Joined: Tue Sep 16, 2008 5:38 pm
Re: code for "last and first three trading days of a month"
What regression? Your clarification post stated you wanted to create a dummy variable (which you appear to have done - its the series called Dummy in your workfile after running the lines of code).
Re: code for "last and first three trading days of a month"
i've written that i want to run a regression like this:
return=c+beta*x
where x is our dummy variable which equals 1 for the last and the first 3 trading days of each month ( and 0 for the other days).
or don't we need a dummy variable for this? but how can i define x so that it only includes the last and first 3 trading days of each month?
return=c+beta*x
where x is our dummy variable which equals 1 for the last and the first 3 trading days of each month ( and 0 for the other days).
or don't we need a dummy variable for this? but how can i define x so that it only includes the last and first 3 trading days of each month?
Who is online
Users browsing this forum: No registered users and 1 guest
