Generate variable with matrix (event study)

For questions regarding programming in the EViews programming language.

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

robbo87
Posts: 8
Joined: Thu Jun 21, 2012 4:20 am

Generate variable with matrix (event study)

Postby robbo87 » Thu Jun 28, 2012 5:35 am

Hi,

many posts on this forum allready helped me with conducting my event study, however I still have some questions. I grouped returns on 96 companies over a period of a year and estimated alpha and beta coefficients via the following program:

matrix(2,96) coefs
equation eq
for !i=1 to 96
%sname = prices.@seriesname(!i)
eq.ls {%sname} c msci
colplace(coefs, eq.@coefs, !i)
next

I now have alpha en beta estimates in a coefs file in my workfile. In my next step I would like to estimate expected returns. For all companies I want to use the company specific alpha en beta estimate and a particular day market return(single object in the market returns) in order to calculate expected return. I figured I could use the genr button, but I don't exactly know how to do it.

E(R)1 = a company1 + b company1 * market return on t=0
E(R)2 = a company2 + b company2 * market return on t=0
........

Then, I would like to create a new variable with abnormal returns. So again I have to generate and calculate Expected Return (hopefully computed via the above mentioned problem) and Actual returns (single object in the grouped returns).

AR 1= Actual Return company1 - E(R)company1
AR2 = Actual Return company2 - E(R)company2

Could someone help me create expected returns and abnormal returns?

Moreover I have to test the abnormal returns for statistical significance. If someone has an idea how to do that, please let me know also!

Regards,

Rob

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

Re: Generate variable with matrix (event study)

Postby EViews Gareth » Thu Jun 28, 2012 7:53 am

Not entirely sure I follow, but something like:

Code: Select all

For !i=1 to 96 series er!i = coefs(1, !i) + coefs(2, !i)*mrktreturn next
Where mrktreturn is the name of your series containing the market return.

robbo87
Posts: 8
Joined: Thu Jun 21, 2012 4:20 am

Re: Generate variable with matrix (event study)

Postby robbo87 » Fri Jun 29, 2012 2:31 am

Perfect, thank you.

I try to figure out how to do all the (very basic) programming in Eviews, instead of moving back and forward between Eviews and Excell.

I now have 96 series of expected returns. I have grouped those returns manually: however I have two more datasets that also need event study analysis, so if you have a program code to group those series at once, that would be very helpfull.

I have two groups now, for about 250 trading days, I have one group with actual returns and one group with the computed expected returns. I want to create a new group, that contains values for all trading days with abnormal returns (so actual returns - expected returns). How to do that?

Thank you in advance!

Rob

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

Re: Generate variable with matrix (event study)

Postby EViews Gareth » Fri Jun 29, 2012 10:05 am

You have to loop through the series one at a time. You can't do a group subtract.

robbo87
Posts: 8
Joined: Thu Jun 21, 2012 4:20 am

Re: Generate variable with matrix (event study)

Postby robbo87 » Mon Jul 09, 2012 9:01 am

Two more questions I would like to post here on this helpfull Forum:

1) I have daily stock returns for a period of 5 years. In those years I have 1 event date per year (all companies have the samen event date, and I have have 97 companies in sample). I manualy programmed to calculate t-test statistic. Now I want to filter the test-statistic in such a way that it is only displayed for the actual event dates. The main question here is: how to create a series with 5 event dates (one per year) and the t-test statistic for that particulair day for every company?

2) I want to assess those t-statistics. Therefore I would like to count for how many companies the test statistic is significant. What I want to do is count in case the statistic is higher then a certain number (if statement?)?

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

Re: Generate variable with matrix (event study)

Postby EViews Gareth » Mon Jul 09, 2012 9:03 am

If your workfile is daily for 5 years, then each series has around 1300 observations. You cannot create a 5 observation series. You might want to put it in a vector or table instead.

If statement seems to be what you want.

robbo87
Posts: 8
Joined: Thu Jun 21, 2012 4:20 am

Re: Generate variable with matrix (event study)

Postby robbo87 » Mon Jul 09, 2012 12:34 pm

So,

can I make a row vector for every event date? Can I work with @sample or @date? I dont really understand how to substract for every company (97) the computed t-statistic for day x...

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

Re: Generate variable with matrix (event study)

Postby EViews Gareth » Mon Jul 09, 2012 1:57 pm

To be honest, I'm don't understand enough of what you're doing. You said that you have manually programmed the t-stat. If so, I assume you have a scalar value. You can then put that scalar value into a vector, or matrix, or table.

robbo87
Posts: 8
Joined: Thu Jun 21, 2012 4:20 am

Re: Generate variable with matrix (event study)

Postby robbo87 » Tue Jul 10, 2012 1:36 pm

Dear Gareth,

I don't get the event study done, so I post again here, since you seem to know how it all works. I also attached a sample eviews workfile, that hopefully makes it easier for me to explain my problems.

The sample workfile contains:

Daily stock returns on 9 companies for two years
Daily returns on the MSCI index

Via the following program I derive at the attached workfile:

? I make the group returns_log by clicking, what is the command to program this group? I tried:


group returns_log logr (1 to 9) but It did not work

matrix(2,9) coefs
equation eq
for !i=1 to 9
%sname = returns_log.@seriesname(!i)
eq.ls {%sname} c msci
colplace(coefs, eq.@coefs, !i)
next

For !i=1 to 9
series er!i = coefs(1, !i) + coefs(2, !i)*msci
next

for !i=1 to 9
series ar!i = logr!i - er!i
next

for !i=1 to 9
scalar stdev_ar!i = @stdev (ar!i)
next


At this point I dont get any further. I want to compute a t-statistic with some kind of the following command:

for !i=1 to 97
series ???? t_statistic!i = ar!i/stdev_ar!i
next

However I only want to do that for the event window. How can I adjust the above computation for:

1) only check for event date (for example 26/11/2002), I want someting like:

company 1 company 2 company 3 ............ company 9
26/11/2002 t-statisctic t-statisctic t-statisctic ........... t-statisctic

Next I want to count al the t-statistic that have a value larger than value x! How to program that?

2) check for event window (for example -1 - +1, with t=0 = 26/11/2002), I want something like:

company 1 company 2 company 3 ............ company 9
25/11/2002 t-statisctic t-statisctic t-statisctic ........... t-statisctic
26/11/2002 t-statisctic t-statisctic t-statisctic ........... t-statisctic
27/11/2002 t-statisctic t-statisctic t-statisctic ........... t-statisctic

Thank you very much for your help and patience,

Rob
Attachments
eviews_forum.wf1
(203.4 KiB) Downloaded 238 times

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

Re: Generate variable with matrix (event study)

Postby EViews Gareth » Tue Jul 10, 2012 1:55 pm

Still not sure I follow. Perhaps you should just use the smpl command to set the sample?

Also, I'll point out that I don't really see why you have four for loops. Why not just do everything in one loop?

robbo87
Posts: 8
Joined: Thu Jun 21, 2012 4:20 am

Re: Generate variable with matrix (event study)

Postby robbo87 » Wed Jul 11, 2012 8:33 am

You are right, it does not make sense to do so many loops, It was me trying to get all the steps one by one.

The sample command works just fine to "filter" values for certain dates.

I still have two questions:

I can not get it done to generate or create a group from series, I used the following command, what do I do wrong?

for !i=1 to 97
group areturns ar!i
next

I try to convert a group into a matrix and and get rid of all the NA (due to sample) and use the following command:

matrix matrixname = @convert (groupname)

The group contains 3 rows and 97 columns, the matrix I make contains 1 row and 97 columns. Any solution for that?

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

Re: Generate variable with matrix (event study)

Postby EViews Gareth » Wed Jul 11, 2012 8:36 am

I don't understand what you mean by "generate a group from a series".

@convert uses whatever the current sample is, so if the current sample only has one row, then resultant matrix will only have one row.

robbo87
Posts: 8
Joined: Thu Jun 21, 2012 4:20 am

Re: Generate variable with matrix (event study)

Postby robbo87 » Wed Jul 11, 2012 8:42 am

What I mean is that I have multiple series and I want to group them. I normaly do so by selecting the different series and open them as a group. But I would like to run this also by the program....

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

Re: Generate variable with matrix (event study)

Postby EViews Gareth » Wed Jul 11, 2012 8:45 am

The general syntax is:

Code: Select all

group groupname series1 series2 series3 series4 ...
You can add a series to an existing group by:

Code: Select all

groupname.add seriesname

robbo87
Posts: 8
Joined: Thu Jun 21, 2012 4:20 am

Re: Generate variable with matrix (event study)

Postby robbo87 » Wed Jul 11, 2012 8:52 am

Ok, thank you again. That was what I also found in the Eviews Help Guide, but since I have 97 series, I thought there might have been a quicker way...

@convert uses whatever the current sample is, so if the current sample only has one row, then resultant matrix will only have one row.

I had three rows, but some of the rows had some missing values. I tried again with rows without any missing values and it worked, just like you posted.

Thanks again.


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests