Sie sind auf Seite 1von 11

1) We need a variable to measure time so we construct it by using gen

command, and an internal number (_n) to keep track of where it is in the


dataset
. gen time=_n
. twoway (line gdpconstant2000us time) in 10/41, ytitle ( gdpconstant2000us) xt
> itle( time) title (U.K. GDP)

600000

gdpconstant2000us
800000 1000000 1200000 1400000

U.K. GDP

10

20

. tsset time
time variable:
delta:

30

40

time, 1 to 51
1 unit

gdpconstant2000us

-1.00

Autocorrelations of gdpconstant2000us
-0.50
0.00
0.50
1.00

. ac

time

10

Lag

Bartlett's formula for MA(q) 95% confidence bands

15

20

25

Partial autocorrelations of gdpconstant2000us


-1.00
-0.50
0.00
0.50
1.00

gdpconstant2000us

10

Lag

15

20

25

95% Confidence bands [se = 1/sqrt(n)]

. reg

gdpconstant2000us time in 10/41


Source

SS

df

MS

Model
Residual

1.4299e+12
8.5403e+10

1
30

1.4299e+12
2.8468e+09

Total

1.5153e+12

31

4.8881e+10

gdpconstan~s

Coef.

time
_cons

22894.49
401217.8

Std. Err.
1021.536
27704.17

t
22.41
14.48

Number of obs
F( 1,
30)
Prob > F
R-squared
Adj R-squared
Root MSE

=
=
=
=
=
=

32
502.29
0.0000
0.9436
0.9418
53355

P>|t|

[95% Conf. Interval]

0.000
0.000

20808.24
344638.3

24980.75
457797.3

. predict double uhatlinear, residual


uhatlinear time) in 10/41, ytitle (residual) xtitle(time)

residual
50000

100000

150000

. twoway (line

-50000

. pac

10

20

time

30

40

The residual plot makes clear what is happening; the linear trend is
inadequate, because the actual trend is nonlinear.

To plot the fitted linear time trend and the actual values of the variable we
do:
. predict double rshatlinear, xb
. twoway (scatter gdpconstant2000us time, msize(vsmall)) (line rshatlinear tim
> e) in 10/41, ytitle ( gdpconstant2000us) xtitle(time) title(U.K. GDP: linear t
> rend)

gdpconstant2000us
600000 800000 1000000 1200000 1400000

U.K. GDP: linear trend

10

20

30

time

GDP (constant 2000 US$)

40
Linear prediction

In order to fit a quadratic trend to the data we need first to create variable
time squared (time2) and then regress the dependent variable
gdpconstant2000us on time and time2.
. gen time2=time^2
. reg

gdpconstant2000us time time2 in 10/41


Source

SS

df

MS

Model
Residual

1.4864e+12
2.8895e+10

2
29

7.4321e+11
996379727

Total

1.5153e+12

31

4.8881e+10

gdpconstan~s

Coef.

time
time2
_cons

-5253.566
551.9227
713054.1

Std. Err.
3786.257
73.28849
44533.78

t
-1.39
7.53
16.01

Number of obs
F( 2,
29)
Prob > F
R-squared
Adj R-squared
Root MSE
P>|t|
0.176
0.000
0.000

=
=
=
=
=
=

32
745.91
0.0000
0.9809
0.9796
31565

[95% Conf. Interval]


-12997.33
402.0309
621972.3

It can be seen that both the linear and quadratic terms are highly
significant. The coefficient of determination is almost 1.

2490.199
701.8145
804135.9

To have a look at the residual type:


. predict double uhatquadratic, residual

-50000

residual
0

50000

. twoway (line uhatquadratic time) in 10/41, ytitle (residual) xtitle(time)

10

20

time

30

40

The residuals still display persistent dynamics.


In order ti look at how the fitted nonlinear trend tracks the evolution gdp we
type:
. predict double rshatquadratic, xb
. twoway (scatter gdpconstant2000us time, msize(vsmall)) (line rshatquadratic t
> ime) in 10/41, ytitle( gdpconstant2000us) xtitle(time) title(UK GDP: Quadratic
> Trend)

gdpconstant2000us
600000 800000 1000000 1200000 1400000

UK GDP: Quadratic Trend

10

20

30

time

GDP (constant 2000 US$)

40
Linear prediction

We need to estimate a different type of nonlinear trend model such as the


exponential trend. Here we need to create the variable log of gdp (lggdp)
and regress it on a constant and a time trend variable.
. gen lggdp=ln( gdpconstant2000us)
. reg

lggdp time time2 in 10/41


Source

SS

df

MS

Model
Residual

1.45651784
.025092898

2
29

.728258922
.000865272

Total

1.48161074

31

.047793895

lggdp

Coef.

time
time2
_cons

.009054
.0002734
13.34497

Std. Err.
.0035284
.0000683
.0415005

t
2.57
4.00
321.56

Number of obs
F( 2,
29)
Prob > F
R-squared
Adj R-squared
Root MSE

=
=
=
=
=
=

32
841.65
0.0000
0.9831
0.9819
.02942

P>|t|

[95% Conf. Interval]

0.016
0.000
0.000

.0018377
.0001337
13.26009

.0162703
.0004131
13.42985

The estimation results show that the exponential nonlinear trend model
seems to feet well.
In order to look at the residuals:
. predict double uhatloglinear, residual
. twoway (line uhatloglinear time) in 10/41, ytitle(residual) xtitle(time)

.06
.04
residual
.02
0
-.02
-.04
10

20

time

30

40

In sharp contrast to the results of fitting a linear time trend to gdp, which
were poor, the results of fitting a time trend to the log of gdp seen much
improved.
. predict double rshatloglinear, xb
. twoway (scatter lggdp time, msize(vsmall)) (line rshatloglinear time) in 10/4
> 1, ytitle ( gdpconstant2000us) xtitle(time) title(U.K. GDP: Long Linear Trend)

13.4

gdpconstant2000us
13.6
13.8
14

14.2

U.K. GDP: Long Linear Trend

10

20

30

time

lggdp

40

Linear prediction

It is hard to compare the log-linear trend-model with the linear and


quadratic models because they are in levels (no logs), which renders
diagnostic statistics that are incomparable. One way around this problem is
to estimate the exponential trend model directly in levels, using nonlinear
least squares.
. nl ( gdpconstant2000us={b0}*exp({b1}*time)) in 10/41
(obs = 32)
Iteration
Iteration
Iteration
Iteration
Iteration
Iteration

0:
1:
2:
3:
4:
5:

Source

residual
residual
residual
residual
residual
residual

SS
SS
SS
SS
SS
SS

SS

=
=
=
=
=
=

1.52e+12
5.40e+11
9.54e+10
4.22e+10
4.22e+10
4.22e+10
df

MS

Model
Residual

3.2522e+13
4.2163e+10

2
30

1.6261e+13
1.4054e+09

Total

3.2564e+13

32

1.0176e+12

gdpconstan~s

Coef.

/b0
/b1

521484.5
.0239659

Std. Err.
12065.97
.0007537

t
43.22
31.80

Number of obs
R-squared
Adj R-squared
Root MSE
Res. dev.

=
=
=
=
=

32
0.9987
0.9986
37489.31
762.7827

P>|t|

[95% Conf. Interval]

0.000
0.000

496842.5
.0224266

546126.5
.0255051

To look at residuals:
. predict double uhatexponential, residual
. twoway (line uhatexponential time) in 10/41, ytitle (residual) xtitle(time)

100000
50000
residual
0
-50000
10

20

30

time

40

In order to look at how the fitted exponential trend tracks the evolution of
retails sales we do:
. predict double rshatexponential
(option yhat assumed; fitted values)
. twoway (scatter gdpconstant2000us time, msize(vsmall)) (line rshatexponentia
> l time) in 10/41, ytitle ( gdpconstant2000us) xtitle(time) title(U.K. GDP: Exp
> onential Trend)

gdpconstant2000us
600000 800000 1000000 1200000 1400000

U.K. GDP: Exponential Trend

10

20

time

GDP (constant 2000 US$)

30

40
Fitted values

In order to settle on a final model, we examine the AIC and the BIC for the
three and models.

. reg

gdpconstant2000us time in 10/41


Source

SS

df

MS

Model
Residual

1.4299e+12
8.5403e+10

1
30

1.4299e+12
2.8468e+09

Total

1.5153e+12

31

4.8881e+10

gdpconstan~s

Coef.

time
_cons

22894.49
401217.8

Std. Err.
1021.536
27704.17

t
22.41
14.48

Number of obs
F( 1,
30)
Prob > F
R-squared
Adj R-squared
Root MSE

=
=
=
=
=
=

32
502.29
0.0000
0.9436
0.9418
53355

P>|t|

[95% Conf. Interval]

0.000
0.000

20808.24
344638.3

24980.75
457797.3

. estimates table, stats(aic bic)


Variable

. reg

active

time
_cons

22894.492
401217.8

aic
bic

789.36922
792.30069

gdpconstant2000us time time2 in 10/41


Source

SS

df

MS

Model
Residual

1.4864e+12
2.8895e+10

2
29

7.4321e+11
996379727

Total

1.5153e+12

31

4.8881e+10

gdpconstan~s

Coef.

time
time2
_cons

-5253.566
551.9227
713054.1

Std. Err.
3786.257
73.28849
44533.78

t
-1.39
7.53
16.01

Number of obs
F( 2,
29)
Prob > F
R-squared
Adj R-squared
Root MSE
P>|t|
0.176
0.000
0.000

=
=
=
=
=
=

32
745.91
0.0000
0.9809
0.9796
31565

[95% Conf. Interval]


-12997.33
402.0309
621972.3

2490.199
701.8145
804135.9

. nl( gdpconstant2000us={b0}*exp({b1}*time))
(obs = 51)
Iteration
Iteration
Iteration
Iteration
Iteration
Iteration

0:
1:
2:
3:
4:
5:

Source

residual
residual
residual
residual
residual
residual

SS
SS
SS
SS
SS
SS

SS

=
=
=
=
=
=

7.69e+12
4.70e+12
1.24e+11
1.13e+11
1.13e+11
1.13e+11
df

MS

Model
Residual

6.4173e+13
1.1321e+11

2
49

3.2086e+13
2.3104e+09

Total

6.4286e+13

51

1.2605e+12

gdpconstan~s

Coef.

/b0
/b1

508319.8
.0253559

Std. Err.
9191.855
.0004748

t
55.30
53.41

Number of obs
R-squared
Adj R-squared
Root MSE
Res. dev.

=
=
=
=
=

51
0.9982
0.9982
48066.58
1242.286

P>|t|

[95% Conf. Interval]

0.000
0.000

489848.1
.0244018

526791.6
.02631

. estimates table, stats(aic bic)


Variable
b0

active

_cons

508319.83

_cons

.02535592

Statistics
aic
bic

1246.2864
1250.15

b1

According to our results we chose quadratic trend model, because it has the
lowest AIC and BIC.
. reg

gdpconstant2000us time time2 in 10/41


Source

SS

df

MS

Model
Residual

1.4864e+12
2.8895e+10

2
29

7.4321e+11
996379727

Total

1.5153e+12

31

4.8881e+10

gdpconstan~s

Coef.

time
time2
_cons

-5253.566
551.9227
713054.1

Std. Err.
3786.257
73.28849
44533.78

. gen low=rshatquadratic-1.96*e(rmse)

. gen high=rshatquadratic+1.96*e(rmse)

t
-1.39
7.53
16.01

Number of obs
F( 2,
29)
Prob > F
R-squared
Adj R-squared
Root MSE
P>|t|
0.176
0.000
0.000

=
=
=
=
=
=

32
745.91
0.0000
0.9809
0.9796
31565

[95% Conf. Interval]


-12997.33
402.0309
621972.3

2490.199
701.8145
804135.9

. twoway (line gdpconstant2000us rshatquadratic low high time) in 41/51, ytitle


> ( gdpconstant2000us) xtitle(time) title(U.K. GDP)

1400000

gdpconstant2000us
1600000 1800000

2000000

U.K. GDP

40

45
time
GDP (constant 2000 US$)
low

50
Linear prediction
high

Das könnte Ihnen auch gefallen