stata代写-SEES0095 AQM
时间:2022-02-23
SEES0095 AQM 2021-22 Autocorrelation & AR(p) modelling Tutorial 3
1

Tutorial 3

Autocorrelation & AR(p) modelling

Start your computer session with:
1) Changing your working directory by typing in command window: cd C:\AQM
2) Opening log file in order to save your work by typing in the command window:
log using tutorial_3, text replace
Do not forget to close your log-file at the end of the session (command log close).

Homework from Tutorial 2 & Workshop 3: discussion.


Exercise 1. Autocorrelation: detection & analysis. File phillips.dta
(see Lecture 5 data folder, UCL week 24 topic; this data is also used as an example in
Lecture 5, pp. 41-51).
In this exercise the following topics will be discussed: (1) Declaring data to be time series & frequency
of TS; (2) TS graphs; (3) Lags & 1st difference of a time series variable; (4) Autocorrelation, ACF &
PAC.


1. Declaring the data to be time series
 Open file phillips.dta and type ‘notes’ to read data description. Open the data browser and
detect frequency of the data and what is the name of the variable that defines time.
 For time‐series analysis, dates and times are critical. You need to have one variable which
records the time index. To let Stata know, that variables are time series of annual frequency,
type:
tsset year, yearly
 You can also use the menu: Statistics -> Time series -> Setup and utilities -> Declare data to
be time series dataset.
 Open (see Moodle) & read PDF file ‘Generating Dates and Time.pdf’.
As an exercise, generate new variable, say, time, that would define year for this dataset:
Hint: generate time=1948+_n-1
format time %ty
tsset time


2. Explore variables in the dataset and plot their graphs and discuss them. The tsline command
generates time‐series plots. Plot time series graphs for inflation (inf) and unemployment (unem):
tsline inf
tsline unem
tsline inf unem
Compare your graphs with those on p. 41, Lecture 5.
SEES0095 AQM 2021-22 Autocorrelation & AR(p) modelling Tutorial 3
2

3. Read description of the variables inf_1, unem_1, d_inf, d_unem. Explain their meaning and how
lag and difference of a time series variable can be created in Stata
Useful Stata lag-operators for working with time series:

Operator Example Description
L. L.Y Creates the 1st lag of the variable tY , that is 1tY  , in Stata memory for using in a
particular command, but does not save it in the file.
L2. L2.Y Creates the 2nd lag of the variable tY , that is 2tY  , in Stata memory for using in a
particular command, but does not save it in the file.
… … …
d. d.Y Creates the 1nd difference of the variable tY , that is 1t tY Y  , in Stata memory for
using in a particular command, but does not save it in the file.


4. To decide on possible autocorrelation in inflation (unemployment)
 Explain the concept of autocorrelation, autocorrelation function and partial autocorrelation.
 Plot scatter of inflation against its 1st lag. Discuss.
 Use command corrgram , to plot ACF and PAC for time series inflation
(inf) and unemployment (unem). Explain Stata output. For example:
corrgram inf
You can specify particular number of lags to be included in the output for ACF/PAC. E.g.
to plot ACF and PAC up to 6 lags use:
corrgram inf, lag(6)
 Discuss possible 1st and higher order autocorrelation in these variables.

Exercise 2. Modelling autoregressive process, AR(p). File AR_models.dta
1. Open the file, read variables’ description. The file contains the following time series variables:
t – time, with unspecified (generic) frequency; 1,..., 751t T  ;
e – independent identically normally distributed with zero mean and variance equals
to one (iind(0,1)); 1,..., 751t T  ;
y - AR(1) process defined as 10.5t t ty y e   ; 2,..., 751t T  ; 1 0y  ;
v - AR(1) process defined as 10.7t t tv v e    ; 2,..., 751t T  ; 1 0v  ;
w - AR(2) process defined as 1 20.2 0.6t t t tw w w e      , 3,..., 751t T  ;
1 2 0w w  ;
x - unit root process defined as 1t t tx x e  , 2,..., 751t T  ; 1 0x  ;
z - explosive (bubble) process defined as 11.2t t tz z e   , 2,..., 751t T  ; 1 0z  .


2. File AR_models.dta contains variable t with unspecified (generic) frequency. You need to let
Stata know that variable t will be used as time index. You can use upper Menu (Statistics->Time
series->Set up and utilities->Declare dataset to be time-series) or give a command:
tsset t, generic
SEES0095 AQM 2021-22 Autocorrelation & AR(p) modelling Tutorial 3
3
3. Time‐series plots.
Plot time series graphs for all the time series on the file. Discuss the graphs and decide with series are
stationary and which are nonstationary unit root and bubble processes. Explain your reasons.
You may use the following commands in Stata:
tsline e
tsline y
tsline x
tsline z
tsline y x
tsline y z
tsline x z


3. Fitting an autoregressive model to variables w.
 Compare ACF and PACF for times series y and w and explain how ACF and PAC can be used
in order to decide on the order of autoregressive process that should be fitted to the data. What
AR process would you fit to y? Why? What AR process would you fit to w? Why?
 After analysis of PACF above it has been decided that time series w follows autoregressive
process of order 2, AR(2). [Explain – why!]. Estimate AR(2) model for variable w. Explain
estimation output and compare estimated coefficients with the theoretical ones given in 1 above.
 Analyse residuals by plotting ACF for residuals as well as a scatter diagram of current residuals
against their lagged values and decide on correctness of chosen specification (that is absence of
autocorrelation in residuals (see Lecture 5, pp. 7 & 17).
reg w L.w L2.w
predict res_w, resid
corrgram res_w

gen res_w_1=L.res_w
scatter res_w resw_1

 Use Ljung-Box Q (χ2) statistic (corrgram) & Breusch-Godfrey test (estat bgodfrey) to
detect higher order autocorrelation. See Lecture 5, pp. 8 & 49-51.


4. Model underspecificaion or overspecification.
 Underspecificaion. Suppose, that instead of correct specification of AR(2) for the process w,
incorrect specification of AR(1) has been chosen. Explain how residual analysis can help in
detecting this mistake. Hint: estimate AR(1) model for w and test residuals for autocorrelation.
 Overspecification. Suppose, that instead of correct specification of AR(2) for the process w,
incorrect specification of AR(3) has been chosen. Explain how residual analysis & significance
of estimated parameters can help in detecting this mistake. Hint: estimate AR(3) model for w and
test the coefficient of the 3rd lag of w for significance. Also test residuals for autocorrelation.

SEES0095 AQM 2021-22 Autocorrelation & AR(p) modelling Tutorial 3
4

Homework
1. Analyse time series v in the AR_models.dta file: compute autocorrelation coefficients, analyse
ACF and PAC and fit AR-model to the data (that is find specification without autocorrelation
in residuals).
2. Analyse time series V in the AR_models.dta file and fit an autoregressive process to it.
3. Using file phillips.dta repeat an example of modelling the Phillips curve from Lecture 5, pp.
41-51.


essay、essay代写