A Primer on Programming in EViews.4245019

15
Bogazici University first draft Department of Economics 12/31/06 EC634 Applied Macroeconometrics Fall 2007 page 1 A Primer on Programming in E-Views This primer introduces programming in E-Views with a particular focus on rolling and recursive regressions. A background on programming algorithms may be helpful for the learners. 1. Introduction A careful analyst should take into account whether the estimated parameters in a model are stable over the sub-samples. Moreover, it should also be of interest whether the variances of regression coefficients change over time. Consider the following regression output in which the response of interest rates to the anticipated and unanticipated FOMC practices is analyzed. For the period June 1989-October 2006 we have the following result: Dependent Variable: DELTA1R10Y Table 1 Method: Least Squares / Sample: 1989M06 2006M10 Included observations: 209 Newey-West HAC Standard Errors & Covariance (lag truncation=4) Variable Coefficient Std. Error t-Statistic Prob. C 1.328488 1.284744 1.034048 0.3023 A1T -8.372724 10.73277 -0.780109 0.4362 UA1T 41.72883 11.47904 3.635220 0.0004 R-squared 0.069398 Mean dependent var -0.541034 Adjusted R-squared 0.060363 S.D. dependent var 16.80010 S.E. of regression 16.28515 Akaike info criterion 8.432635 Sum squared resid 54632.47 Schwarz criterion 8.480611 Log likelihood -878.2103 F-statistic 7.681082 Durbin-Watson stat 1.799222 Prob(F-statistic) 0.000606 where DELTA1R10Y denotes the yield of Treasury note with 10-year maturity, the coefficient of A1T shows the response of 10-year Treasure note to anticipated FOMC practices, and the coefficient of UA1T shows the response of 10-year Treasury note to unanticipated FOMC practices. Now consider the same relation for the period of November 2001-October 2006: Dependent Variable: DELTA1R10Y Table 2 Method: Least Squares / Sample: 2001M11 2006M10 Included observations: 60 Newey-West HAC Standard Errors & Covariance (lag truncation=3) Variable Coefficient Std. Error t-Statistic Prob. C 1.705205 2.121677 0.803706 0.4249 A1T -20.90297 13.07991 -1.598097 0.1156 UA1T -52.22807 51.09164 -1.022243 0.3110

Transcript of A Primer on Programming in EViews.4245019

Page 1: A Primer on Programming in EViews.4245019

Bogazici University first draft

Department of Economics 12/31/06

EC634 Applied Macroeconometrics

Fall 2007

page 1

A Primer on Programming in E-Views This primer introduces programming in E-Views with a particular focus on rolling and recursive regressions.

A background on programming algorithms may be helpful for the learners.

1. Introduction

A careful analyst should take into account whether the estimated parameters in a

model are stable over the sub-samples. Moreover, it should also be of interest whether the variances of regression coefficients change over time. Consider the following regression output in which the response of interest rates to the anticipated and unanticipated FOMC practices is analyzed. For the period June 1989-October 2006 we have the following result:

Dependent Variable: DELTA1R10Y Table 1

Method: Least Squares / Sample: 1989M06 2006M10

Included observations: 209

Newey-West HAC Standard Errors & Covariance (lag truncation=4)

Variable Coefficient Std. Error t-Statistic Prob.

C 1.328488 1.284744 1.034048 0.3023

A1T -8.372724 10.73277 -0.780109 0.4362

UA1T 41.72883 11.47904 3.635220 0.0004

R-squared 0.069398 Mean dependent var -0.541034

Adjusted R-squared 0.060363 S.D. dependent var 16.80010

S.E. of regression 16.28515 Akaike info criterion 8.432635

Sum squared resid 54632.47 Schwarz criterion 8.480611

Log likelihood -878.2103 F-statistic 7.681082

Durbin-Watson stat 1.799222 Prob(F-statistic) 0.000606

where DELTA1R10Y denotes the yield of Treasury note with 10-year maturity, the coefficient of A1T shows the response of 10-year Treasure note to anticipated FOMC practices, and the coefficient of UA1T shows the response of 10-year Treasury note to unanticipated FOMC practices. Now consider the same relation for the period of November 2001-October 2006:

Dependent Variable: DELTA1R10Y Table 2

Method: Least Squares / Sample: 2001M11 2006M10

Included observations: 60

Newey-West HAC Standard Errors & Covariance (lag truncation=3)

Variable Coefficient Std. Error t-Statistic Prob.

C 1.705205 2.121677 0.803706 0.4249

A1T -20.90297 13.07991 -1.598097 0.1156

UA1T -52.22807 51.09164 -1.022243 0.3110

Page 2: A Primer on Programming in EViews.4245019

Bogazici University first draft

Department of Economics 12/31/06

EC634 Applied Macroeconometrics

Fall 2007

page 2

R-squared 0.037511 Mean dependent var 1.785612

Adjusted R-squared 0.003740 S.D. dependent var 18.22979

S.E. of regression 18.19567 Akaike info criterion 8.688951

Sum squared resid 18871.70 Schwarz criterion 8.793668

Log likelihood -257.6685 F-statistic 1.110738

Durbin-Watson stat 2.189879 Prob(F-statistic) 0.336338

Comparing the two output tables, we can infer that both the value and the associated

t-statistics of the coefficients are not stable over the sub-samples. Accordingly, an economist whose aim is to uncover the relationship between unanticipated/anticipated FOMC actions and the yields on financial assets (specifically the Treasury note with 10-year to maturity (henceforth TNote)), may confront the following criticism if (s)he solely relies on Table 1:

- the effects of A1T and UA1T on DELTA1R10Y are found to be not-changing

over the whole sample. Nevertheless, it is known that FOMC enhances the transparency of its meetings over the last decade, implying that it has become harder to surprise the market, making the effect of unanticipated FOMC actions on yields on TNote negligible. Hence, it is plausible to expect that the UA1T becomes insignificant over time, and market is working more efficiently. Indeed, Table 2 corroborates this expectation.

However, Table 2 is far from a rigorous analysis, since it does not expose the time-

varying nature of the level and the significance of the UA1T coefficient over time. Now consider the following figure:

This figure shows that the effect of unanticipated component on TNote decreases and becomes insignificant over time. This figure is constructed through rolling regression with a fixed window, as:

(i) choosing a window size (here it is 5-year), (ii) moving this window over the sample.

Page 3: A Primer on Programming in EViews.4245019

Bogazici University first draft

Department of Economics 12/31/06

EC634 Applied Macroeconometrics

Fall 2007

page 3

The first sub-sample used is June 1989-May 1994 (60 obs.), the second July 1989-June 1994 (60 obs.), the third August 1989-July 1994 (60 obs.) and so on. The last sub-sample is November 2001-October 2006. For each of these fixed windows (sub-samples) we report the parameters (i.e. beta coefficients, associated t-stats or p-values, R2s, etc.) and sketch them over the sub-samples.

Another type of analyzing the stability of the estimated parameters is the recursive

regressions with either fixed starting date or fixed end date. Recursive regression with a fixed starting date begins with a window size (we

choose it to be 60 obs. in our analysis), and enlarges the sample size one-by-one. Hence, the sub-samples used are June 1989-May 1994 (60 obs.), June 1989-June 1994 (61 obs.), June 1989-July 1994 (62 obs.) and so on. The last sub-sample is June 1989-October 2006 which is the whole sample (209 obs.). See the following figure:

We see that although UA1T is significant over all sub-samples, the t-statistic associated is decreasing over time. Moreover the magnitude of the effect of UA1T on TNote is also decreasing. When we compare this figure with the previous one, one should not be surprised: In recursive regressions, we add an additional observation and the effect of an additional observation on the regression output decreases over time, since the sample size is constantly growing. For instance, the first sub-sample that includes 9/11 is June 1989-September 2001 (148 obs.) and the remaining sub-samples that includes 9/11 increases in sample size up to 209 observations. Hence recursive regressions may hinder sudden ups and downs, contrary to rolling regressions.

Also note that the last point in the figure corresponds to the output using the whole sample and the coefficient seems to be apprx. 41 and the t-statistic 3.6 (as also seen in Table 1).

Recursive regressions with a fixed end date begins with a window size (we

choose it to be 5-year in our analysis) and the sample size is increased by adding an observation to the beginning of the sample. Namely, our first sub-sample is November 2001-October 2006 (60 obs.), the second October 2001-October 2006 (61 obs.), the third

Page 4: A Primer on Programming in EViews.4245019

Bogazici University first draft

Department of Economics 12/31/06

EC634 Applied Macroeconometrics

Fall 2007

page 4

September 2001-October 2006 (62 obs.) and so on. The last sub-sample is June 1989-October 2006 (209 obs.) which is the whole sample.

When we sketch the results of recursive regressions with a fixed end date, the first

data point we sketch is the last sub-sample we use, i.e. the whole sample. The first regression (November 2001-October 2006 (60 obs.)) we done is the last point in the figure. In essence, we just reverse the order of sub-samples and sketch accordingly:

Notice that the first sub-sample is the whole sample from June 1989 to October

2006, and the coefficient and the t-statistic is the same as it is in Table 1. Moreover the last point corresponds to the first regression we done, i.e. (November 2001-October 2006 (60 obs.)).

Note that there are 149*3=447 regression results in these three figures: Is it possible

to have all these done in a few seconds? Yes, this is what you will be equipped with, i.e. programming in EViews.

Page 5: A Primer on Programming in EViews.4245019

Bogazici University first draft

Department of Economics 12/31/06

EC634 Applied Macroeconometrics

Fall 2007

page 5

2. Basics of Programming

First choose File > New > Program, as:

then you will have a blank textpad:

You will use this blank textpad to write your program, and after you complete the program, simply click on the run button to execute the program.

Page 6: A Primer on Programming in EViews.4245019

Bogazici University first draft

Department of Economics 12/31/06

EC634 Applied Macroeconometrics

Fall 2007

page 6

2.1 Basics of Programming:

After writing a code and pressing the run button we have the following:

You see that the command ls(n) delta1r10y c a1t ua1t

performs a least squares regression of DELTA1R10Y on A1T and UA1T, with Newey-West HAC standard errors. The (n) imposes EViews to run the regression with Newey-West option. Other options are also available, you may find them on the web. The sample period is taken as 2001m10 and 2006m10. You can change the sample size by simply writing

smpl 1989m06 2006m10

ls(n) delta1r10y c a1t ua1t

which yields:

Page 7: A Primer on Programming in EViews.4245019

Bogazici University first draft

Department of Economics 12/31/06

EC634 Applied Macroeconometrics

Fall 2007

page 7

Now if you are able to change the sample size in a for loop, then in each iteration you will end up with different regression outputs each have different sample periods. See the following code:

for !horizon=0 to 5

smpl 1989m06+!horizon 1994m05+!horizon

ls(n) delta1r10y c a1t ua1t

next

This code estimates 6 regressions for subsequent sample periods, i.e June 1989-May 1994 to November 1989-October 1994. Notice that this is an example of rolling regressions with a fixed window of 60 observations. Nonetheless, when you run the above code, each estimation output overwrites the previous one:

Page 8: A Primer on Programming in EViews.4245019

Bogazici University first draft

Department of Economics 12/31/06

EC634 Applied Macroeconometrics

Fall 2007

page 8

So we only have the output of the last iteration, and the previous ones are lost. Accordingly we need to save the output of the each iteration so that:

As you see, the result of first iteration is saved under output1, the second iteration under output2, etc. Let us concentrate on the bold part of the following code:

Page 9: A Primer on Programming in EViews.4245019

Bogazici University first draft

Department of Economics 12/31/06

EC634 Applied Macroeconometrics

Fall 2007

page 9

for !horizon=0 to 5

smpl 1989m06+!horizon 1994m05+!horizon

equation output{!horizon}.ls(n) delta1r10y c a1t ua1t

next

This bold part implies that at each iteration save the result of “ls(n) delta1r10y c a1t ua1t” as an “equation”-type under the name output1 or output2 etc. Next task is to save the coefficients and the t-statistics at each iteration. This is done via the code:

for !horizon=0 to 5

smpl 1989m06+!horizon 1994m05+!horizon

equation output{!horizon}.ls(n) delta1r10y c a1t ua1t

matrix output_coeff{!horizon}=output{!horizon}.@coefs

matrix output_tstats{!horizon}=output{!horizon}.@tstats

next

At first iteration a matrix named output_coeff1 is created and the coefficients of output1 equation are saved as a matrix form. Next a matrix named output_tstats1 is created and the t-statistics of each coefficient in the equation output1 is saved as a matrix format, and so on…:

Page 10: A Primer on Programming in EViews.4245019

Bogazici University first draft

Department of Economics 12/31/06

EC634 Applied Macroeconometrics

Fall 2007

page 10

For expositional purposes, let us see the equation-type output0, matrix-type output_coeff0 and output_tstats0. Remember that all of these corresponds to the first sub-sample, i.e. June 1989-May 1994:

Page 11: A Primer on Programming in EViews.4245019

Bogazici University first draft

Department of Economics 12/31/06

EC634 Applied Macroeconometrics

Fall 2007

page 11

Now our task is to save each of the UA1T coefficients and the corresponding t-stats in each regression. We perform this via the following code: vector (6) uacoeff ‘ we initiliaze two vectors with 6 rows, under the

vector (6) uatstat ‘ names uacoeff and uatstat

for !horizon=1 to 6

smpl 1989m05+!horizon 1994m04+!horizon

equation output{!horizon}.ls(n) delta1r10y c a1t ua1t

matrix output_coeff{!horizon}=output{!horizon}.@coefs

matrix output_tstats{!horizon}=output{!horizon}.@tstats

uacoeff(!horizon)=output_coeff{!horizon}(3,1)

‘ the third element of output_coeff which is the third coefficient in each

‘regression is saved on the uacoeff vector one-by-one.

uatstat(!horizon)=@abs(output_tstats{!horizon}(3,1))

‘ the third element of output_tstats is saved on the uatstat vector one-by-one;

‘note also that we take the absolute value of the t-statistics.

next

Notice that the uacoeff and uatstat are vector-type, so they cannot be associated with a date, but we know that the first element of the uacoeff belongs to the first sub-sample that begins with June 1989. Before converting vectors into series so that when we sketch the uacoeff, we have the dates on the horizontal axis, let us expand our analysis by having more subsamples:

Page 12: A Primer on Programming in EViews.4245019

Bogazici University first draft

Department of Economics 12/31/06

EC634 Applied Macroeconometrics

Fall 2007

page 12

We are almost done. Notice that the graphs of both uacoeff and uatstat have number on the horizontal axis, which is undesirable. So we should convert the vectors into series. We do this via the following code:

vector (150) uacoeff

vector (150) uatstat

for !horizon=1 to 150

smpl 1989m05+!horizon 1994m04+!horizon

equation output{!horizon}.ls(n) delta1r10y c a1t ua1t

matrix output_coeff{!horizon}=output{!horizon}.@coefs

matrix output_tstats{!horizon}=output{!horizon}.@tstats

uacoeff(!horizon)=output_coeff{!horizon}(3,1)

uatstat(!horizon)=@abs(output_tstats{!horizon}(3,1))

next

smpl 1989m06 2001m11

mtos(uacoeff,ua_coeff)

mtos(uatstat,ua_tstat)

Now focus on the bold part of the code. First we need to initialize the sample, we know that the first element of the vector uacoeff belongs to the sample beginning with 1989m06. The last element of the vector uacoeff corresponds to the sample beginning with 2001m11. Then we acknowledge this by simply initializing the sample size as smpl 1989m06 2001m11, and then we use the code

mtos(uacoeff,ua_coeff) ‘ mtos:matrix to series

mtos(uatstat,ua_tstat)

Page 13: A Primer on Programming in EViews.4245019

Bogazici University first draft

Department of Economics 12/31/06

EC634 Applied Macroeconometrics

Fall 2007

page 13

which means convert uacoeff vector into a series called ua_coeff.

After some manipulation using the Graph options in EViews, you can have the

following graph:

Now we can also perform recursive regressions with a fixed-starting and a fixed-end

date. This is simply done by changing the range of the for loop. For recursive regressions

with a fixed-starting date, just change the sample range by smpl 1989m06

1994m04+!horizon, for a recursive regressions with a fixed-end date, use smpl

1989m05+!horizon 2006m10. Do not forget to rename the vectors or series that you use for the rolling regressions.

Another point is that the critical t-value for the recursive regressions is not constant

as the sample size is changing. For the rolling regressions with a fixed window, the critical t-statistics is constant and has d.o.f of n-k. The following code uses the @tdist(m,d)

Page 14: A Primer on Programming in EViews.4245019

Bogazici University first draft

Department of Economics 12/31/06

EC634 Applied Macroeconometrics

Fall 2007

page 14

command which takes two arguments, first the t-critical value (m), second the degrees of freedom (d). The command gives out the corresponding p-value on a two-tail basis. Accordingly, to find a critical t-value for the rolling regressions with a fixed window can be calculated as:

vector (150) t_criticalfixedwindow

scalar m

for j=1 to 150

for m=1.95 to 2.05 step +0.0001

if @tdist(m,57)>0.04999 and @tdist(m,57)<0.0501 then

t_criticalfixedwindow(j)=m

endif

next

next

smpl 1989m06 2001m11

mtos(t_criticalfixedwindow,tcrit_fixedwindow)

Similarly, the critical t-value for the recursive regressions with a fixed starting date can be calculated as:1

vector (150) t_criticalfixedstart

scalar m

for j=1 to 150

for m=1.95 to 2.05 step +0.0001

if @tdist(m,56+j)>0.04999 and @tdist(m,56+j)<0.0501 then

t_criticalfixedstart(j)=m

endif

next

next

smpl 1994m05 2006m10

mtos(t_criticalfixedstart,tcrit_fixedstart)

And, the critical t-value for the recursive regressions with a fixed end date can be calculated as:

vector (150) t_criticalfixedend

for j=1 to 150

for m=1.95 to 2.05 step +0.0001

if @tdist(m,207-j)>0.04999 and @tdist(m,207-j)<0.0501 then

t_criticalfixedend(j)=m

endif

1 Another point that should be clear to a careful coder is that while finding the critical t-value, using if…and…then instead of if…then… is unnecessary since the t-distribution is smooth; hence this code makes the run-time longer.

Page 15: A Primer on Programming in EViews.4245019

Bogazici University first draft

Department of Economics 12/31/06

EC634 Applied Macroeconometrics

Fall 2007

page 15

next

next

smpl 1989m06 2001m11

mtos(t_criticalfixedend,tcrit_fixedend)

Note also that for the recursive regressions with a fixed-starting date, the sample begins with 1994m05, i.e. the first element of UA1T coefficient belongs to the sample that begins with May 1994. On the other hand, when we perform rolling regressions and recursive regressions with a fixed-end date, the first element is June 1989.