/* Introduction to Time Series Analysis, DG ECFIN Laura Mayoral November 2021 */ /******************FITTING AN ARMA PROCESS************** In this file we are going to fit an ARMA process Steps: 0. Plot the data 1. Identify a model--(the data should be stationary at this point!) 2. Estimation 3. Diagnostic checking ***********************************************************************/ *Measure of real output, 2005 prices *Replace by your own path: cd "/Users/lauramayoral/Dropbox/docum_dropbox/clases/ECFIN_time series/STATA/files" use quarterly, clear tsset date gen lgdp=log(gdp2005) label var lgdp "Log of real gdp" *Step 0: always plot the data first tsline lgdp ac lgdp pac lgdp *Looks very non-stationary, define first differences gen growth=d.lgdp **NOTE: we should test for stationarity. We'll learn how to do this soon. *plot the transformed series tsline growth ac growth pac growth **STEP 1: IDENTIFICATION *Let's estimate an AR(3) model--function ARIMA (estimation) and estat ic (information criteria) *Estimate a bunch of models and choose the one with smallest IC: *ARIMA has 3 set of parameters: p, d, q. Let's set d=0 for the time being *Which model? IC gives you information criteria. You can run a bunch of models, choose the one with smallest value of IC. *For instance, all combinations of models of p, q<3 arima growth, arima(1,0,0) estat ic arima growth, arima(2,0,0) estat ic arima growth, arima(3,0,0) estat ic arima growth, arima(0,0,1) estat ic arima growth, arima(0,0,2) estat ic arima growth, arima(0,0,3) estat ic arima growth, arima(1,0,1) estat ic arima growth, arima(2,0,1) estat ic arima growth, arima(3,0,1) estat ic arima growth, arima(1,0,2) estat ic arima growth, arima(2,0,2) estat ic arima growth, arima(3,0,2) estat ic arima growth, arima(1,0,3) estat ic arima growth, arima(2,0,3) estat ic arima growth, arima(3,0,3) estat ic **Or write a loop with all possible values of p,q>k, store the ICs **Or a trick: estimate a "VAR", and add maxlag option--but only valid for AR(p)s! varsoc growth, maxlag(8) *Prefered model: ARMA(3,2) *OR ********************************************* *Step 3: test for autocorrelation in the residual term ********************************************* arima growth, arima(3,0,2) predict resid, residual wntestq resid *cannot reject white noise Portmanteau test for white noise --------------------------------------- Portmanteau (Q) statistic = 28.0216 Prob > chi2(40) = 0.9231 • *********************************************************************** *Computing IRFs *********************************************************************** capture erase myirf.irf arima growth, arima(3,0,2) *compute IRF irf create myirf, step(10) set(myirf1) irf graph oirf