A code to create subgroups and regressions

For questions regarding programming in the EViews programming language.

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

Tadej
Posts: 11
Joined: Sun Mar 14, 2010 8:00 am
Location: Oslo, Norway

A code to create subgroups and regressions

Postby Tadej » Sun Mar 14, 2010 9:01 am

Dear friends,

I have spend hours and hours browsing the forums but I haven't found what I am looking for. I am quite sure that this will seem preety basic for you but I am a beginer in programming and would realy appreciate if you could help me out with several simple programming codes. I am writing my master thesis and analyzing an event study of mergers and acquisitions. I will test the risk of acquiring companies around the event by retreiving a beta from the CAPM and Fama&French three factor model. I retreived all the necessary daily data for three years before and after the event.

(CAPM) Ri - Rf = ai + Bi (Rm - Rf)

In Eviews I have now created series for both,each firm's excess returns (denoted by Y) and market premium (denoted by X). Here I would kindly like to ask you if someone could please post a code that will allow me to create subgroups of 30 days/observations ie. 72 groups for both previously mentioned variables (firm's excess returns, market premia) for the entire event window? The latter will be later used for capturing the beta dynamics.

I have read the introduction of eviews programming post several times but I humbly ask you to also write me the FOR loop code that would regress each of the excess return subgroup with the relevant subgroup of market premia and save the regressions and perhaps additionally save the obtained coefficients separately?

I am aware that some of the things have been partially answered already but I have really spend a lot of time working it out and I could not do it. Therefore, I again kindly ask you for few minutes of your time to help me out. Thanks a lot in advance.

Regards


p.s. I'm using Eviews 6

Tadej
Posts: 11
Joined: Sun Mar 14, 2010 8:00 am
Location: Oslo, Norway

Re: A code to create subgroups and regressions

Postby Tadej » Sun Mar 14, 2010 6:10 pm

Hi again.

I have tried to create a regression code for the second question of my post. For example, I tried to work with random normally distributed values and this is what I managed to do. I am aware that the notation of equality between i's and j's is missing in the pairwise regression code (!i=!j). I do not know how to enter it so that eviews does not occur an error. I would be very grateful if someone could help me out.

'create a workfile
wfcreate d 2004 2010

'create 72 y series
for !i=1 to 72
series y{!i}=nrnd
next

'create 72 X series
for !i=1 to 72
series x{!i}=nrnd
next

'run pairwise regressions between each y and relevant x
for !i=1 to 72
for !j=1 to 72
equation eq{!i}.ls x{!i} c x{!j}
next
next

I would stil need help with the first question please. To explain it more specificaly... I have a daily data of 3 years before and 3 years after the acquisition (6 years). I would like to calculate the dynamics of beta through the acquisition episode. Therefore, I would like to estimate monthly beta for each firm (using 30 daily observations). For this purpose I am asking for the code that will allow me to break the 6 yearly series into 72 subsamples (72 groups/months of 30 daily observations) for each firm. If you need any other specifications please let me know. I have an entire sample of 520 firms. Therefore you can imagine how time consuming estimation of 1 regression at the time would be... Thank you for guidance.

Best regards

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

Re: A code to create subgroups and regressions

Postby EViews Gareth » Mon Mar 15, 2010 9:56 am

In answer to the first part of your post, you can add an equality test pretty easily:

Code: Select all

'run pairwise regressions between each y and relevant x for !i=1 to 72 for !j=1 to 72 if !i<>!j then equation eq{!i}.ls x{!i} c x{!j} endif next next
Note that in the code you posted you were regressing x!i on x!j, with no Ys involved...


I'm not 100% certain I understand the second part. I think terminology isn't helping. But my best guess is that you want to change the workfile sample by 30 observations each time in a loop. Something like:

Code: Select all

for !i=1 to 72 step 30 smpl @first+!i-1 @first+!i+30-1 'do stuff here next

Tadej
Posts: 11
Joined: Sun Mar 14, 2010 8:00 am
Location: Oslo, Norway

Re: A code to create subgroups and regressions

Postby Tadej » Mon Mar 15, 2010 9:58 am

Thank you million times :)

I have managed to correct the regressions equations.. you were right I forgot to include y's in the regression specification. The code that regresses y1 with x1, y2 with x2 .......y72 with x72 is

'run pairwise regressions between each y and relevant x
for !i=1 to 72
for !j=1 to 72
if !i<>!j then
equation eq{!i}.ls y{!i} c x{!i}
endif
next
next

I will later try to finish the 1st part which is the basic for the part you helped me solve.

Tadej
Posts: 11
Joined: Sun Mar 14, 2010 8:00 am
Location: Oslo, Norway

Re: A code to create subgroups and regressions

Postby Tadej » Mon Mar 15, 2010 7:01 pm

Hi again.

The part where I would like to obtain 72 y and 72 x series is a prerequisite for the regressions. I have two large series of 1585 observations: x (excess return) and y (market premia). The workfile is atached with the post
1.wf1
(46.14 KiB) Downloaded 421 times
.
Out of these 2 series I would like to create 72 "subseries" of let's say 22 observations (approx month without weekends and holidays). What is the most important is that the 793th observation is the day when acquisition ocurred. Moreover, it must be used as a break point and should not be included into any series. Therefore, the certain subseries should include observations as followed:

subseries y36 should include observations from 771 to 792,
subseries y35 should include observations from 749 to 770,
.......
subseries y2 should include observations from 23 to 44,
subseries y1 should include observations from 1 to 22

Similary I would like to create subseries for observations greater than the breaking point;
subseries y37 should include observations from 774 to 795
...
finaly subseries y72 should include observations from 1564 to 1585.

With same intuition I will construct 72 subseries for the series x.

What I am wondering is if such programming code can be constructed? If yes, I would kindly ask you if you could please write it down(at least the begining and the part where the 793th observation is excluded)?

Later, I will employ the regression code which you helped me construct earlier to derive to coefficients.

Thanks.

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

Re: A code to create subgroups and regressions

Postby EViews Gareth » Mon Mar 15, 2010 7:26 pm

I think you need to ask yourself whether you really need to create all of those subseries, or if just changing the sample, and the lag/lead specification of the variables upon which you are working will do.

Regression Y(1-10) on X(11-20), could be done by creating a new series from X(11-20), but it is much better to use the lag specification in EViews.

As an example:

Code: Select all

smpl @first @first+10-1 for !i=1 to 3 !xlead = !i*10 equation e!i.ls y c x(!xlead) next
will create three equations, the first will regression Y(1-10) on X(11-20), the second will regression Y(1-10) on X(21-30), and the third will regression Y(1-10) on X(31-40).

Taking a look at some of the rolling regression examples (which will show you how to change the sample in a for loop), and the programming guide (where there is an example of changing lags in a for loop), will probably get you started.

Tadej
Posts: 11
Joined: Sun Mar 14, 2010 8:00 am
Location: Oslo, Norway

Re: A code to create subgroups and regressions

Postby Tadej » Mon Mar 15, 2010 7:33 pm

Thanks a lot for replies.

I need to estimate 72 regressions only...and therefore I need 72 subsamples of series x and y.
y1 c x1
y2 c x2
y3 c x3
....
y72 c x72.


I will later employ rolling window as well. But to show simple dynamics of monthly beta I need these regressions. I hope I expressed myself a bit more clearly now...

The regression code works perfectly...exactly what I needed. Now I just need to create these subsamples and I am ready to start the analysis.


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests