Вы находитесь на странице: 1из 15

Bogazici University Department of Economics EC634 Applied Macroeconometrics Fall 2007

first draft 12/31/06

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 Method: Least Squares / Sample: 1989M06 2006M10 Included observations: 209 Newey-West HAC Standard Errors & Covariance (lag truncation=4) Variable C A1T UA1T R-squared Adjusted R-squared S.E. of regression Sum squared resid Log likelihood Durbin-Watson stat Coefficient 1.328488 -8.372724 41.72883 0.069398 0.060363 16.28515 54632.47 -878.2103 1.799222 Std. Error 1.284744 10.73277 11.47904 t-Statistic 1.034048 -0.780109 3.635220 Prob. 0.3023 0.4362 0.0004 -0.541034 16.80010 8.432635 8.480611 7.681082 0.000606 Table 1

Mean dependent var S.D. dependent var Akaike info criterion Schwarz criterion F-statistic Prob(F-statistic)

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 Method: Least Squares / Sample: 2001M11 2006M10 Included observations: 60 Newey-West HAC Standard Errors & Covariance (lag truncation=3) Variable C A1T UA1T Coefficient 1.705205 -20.90297 -52.22807 Std. Error 2.121677 13.07991 51.09164 t-Statistic 0.803706 -1.598097 -1.022243 Prob. 0.4249 0.1156 0.3110 Table 2

page 1

Bogazici University Department of Economics EC634 Applied Macroeconometrics Fall 2007

first draft 12/31/06

R-squared Adjusted R-squared S.E. of regression Sum squared resid Log likelihood Durbin-Watson stat

0.037511 0.003740 18.19567 18871.70 -257.6685 2.189879

Mean dependent var S.D. dependent var Akaike info criterion Schwarz criterion F-statistic Prob(F-statistic)

1.785612 18.22979 8.688951 8.793668 1.110738 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 timevarying 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 2

Bogazici University Department of Economics EC634 Applied Macroeconometrics Fall 2007

first draft 12/31/06

The first sub-sample used is June 1989-May 1994 (60 obs.), the second July 1989June 1994 (60 obs.), the third August 1989-July 1994 (60 obs.) and so on. The last subsample 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 1989September 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 3

Bogazici University Department of Economics EC634 Applied Macroeconometrics Fall 2007

first draft 12/31/06

September 2001-October 2006 (62 obs.) and so on. The last sub-sample is June 1989October 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 4

Bogazici University Department of Economics EC634 Applied Macroeconometrics Fall 2007

first draft 12/31/06

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 5

Bogazici University Department of Economics EC634 Applied Macroeconometrics Fall 2007

first draft 12/31/06

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 6

Bogazici University Department of Economics EC634 Applied Macroeconometrics Fall 2007

first draft 12/31/06

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 7

Bogazici University Department of Economics EC634 Applied Macroeconometrics Fall 2007

first draft 12/31/06

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 8

Bogazici University Department of Economics EC634 Applied Macroeconometrics Fall 2007

first draft 12/31/06

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 9

Bogazici University Department of Economics EC634 Applied Macroeconometrics Fall 2007

first draft 12/31/06

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 10

Bogazici University Department of Economics EC634 Applied Macroeconometrics Fall 2007

first draft 12/31/06

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 vector (6) 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 we initiliaze two vectors with 6 rows, under the names uacoeff and uatstat

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 11

Bogazici University Department of Economics EC634 Applied Macroeconometrics Fall 2007

first draft 12/31/06

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 12

Bogazici University Department of Economics EC634 Applied Macroeconometrics Fall 2007

first draft 12/31/06

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 tstatistics is constant and has d.o.f of n-k. The following code uses the @tdist(m,d)

page 13

Bogazici University Department of Economics EC634 Applied Macroeconometrics Fall 2007

first draft 12/31/06

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

Another point that should be clear to a careful coder is that while finding the critical t-value, using

ifandthen instead of ifthen is unnecessary since the t-distribution is smooth; hence this code makes

the run-time longer.

page 14

Bogazici University Department of Economics EC634 Applied Macroeconometrics Fall 2007

first draft 12/31/06

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.

page 15

Вам также может понравиться