You are on page 1of 6

See discussions, stats, and author profiles for this publication at: https://www.researchgate.

net/publication/326374330

STATA COMMAND FOR TIME SERIES ANALYSIS

Method · July 2018


DOI: 10.13140/RG.2.2.10457.01125/1

CITATIONS READS
0 24,848

3 authors:

Kazi Sohag Umar Bamanga


Ural Federal University Universiti Utara Malaysia
66 PUBLICATIONS 2,180 CITATIONS 5 PUBLICATIONS 5 CITATIONS

SEE PROFILE SEE PROFILE

Md. Mahmudul Alam


Universiti Utara Malaysia
377 PUBLICATIONS 2,990 CITATIONS

SEE PROFILE

Some of the authors of this publication are also working on these related projects:

Investigating the Presence of MFIs Mission Drift in ASEAN Countries and the Mission for Sustainable Microfinance Institutions in Malaysia View project

Investigation of Shrimp/Prawn Disease and their Mitigation Measure View project

All content following this page was uploaded by Md. Mahmudul Alam on 20 December 2020.

The user has requested enhancement of the downloaded file.


STATA COMMAND FOR TIME SERIES ANALYSIS

Stationary at Stationary at level, after Stationary at Stationary after 1st


level I(0) first difference or mixed first difference and 2nd difference

Simple ARDL model Co-integration Autoregressive


Regression models

Variables co- No co-


integrated integration

VECM VAR model

1
How to set time series data:
tsset year, yearly
How to fill missing data for Time Series analysis:
ipolate x time, gen(xi) epolate
How to check unit root using Augmented Dikker Fuller test (ADF):
ADF unit root test using constant
dfuller x
ADF test for constant and trend:
dfuller x, trend
When a variable has unit root, we take difference as follows:
dfuller d.x
ADF test after differencing for constant and trend:
dfuller d.x, trend
If you want to have summary statistics:
sum y x1 x2 x3 x4
How to run correlation matrix for your data:
correlate y x1 x2 x3 x4
Command for running regression model:
regress y x1 x2 x3 x4
If you want to check normality after running regression model, run two commands
consecutively:
predict myResiduals, r
sktest myResiduals
After regression, you can check for serial correlation using either of the following:
dwstat or estat bgodfrey
Use the following command for heteroskedasticity test:
Prob value below 10% means there is heteroskedasticity problem in the model
estat hottest
2
If you want to see whether the model is mis-specified or if some variables are omitted or
not (Ramsy Reset test):
estat ovtest
Command for selecting optimum lags for your model is given below:
varsoc y x1 x2 x3 x4, maxlag(4)
the asterisk (*) indicates the appropriate lag selected
Command for testing co-integration:
vecrank y x1 x2 x3 x4, trend(constant)
When co-integration is established, run VECM otherwise unrestricted VAR model is
appropriate.
Assuming variables are co-integrated, we run VECM using the following command:
vec y x1 x2 x3 x4, trend(contant)
The long-run causality must be negative, significant and in between 0 to 1, representing
error correction term or speed of adjustment.
Command to run impulse response function (you must estimate VECM or VAR model before
running it) as follows:
First you use the following command to create file:
irf create order1, step(10) set(myirf1)
Command for impulse response of all independent variables on dependent variable:
irf graph irf, irf(order1) impulse(y x1 x2 x3 x4) response(smd)
Assuming there is no co-integration, you run VAR model as a replacement for VECM as
follows: (Note VAR model is for short run effect only).
However, cointegration test should be performed on the level form of variables and not on
their first difference. Similarly, it is also okay to use the log transformation of the raw
variables for testing conintegration.
var y x1 x2 x3 x4, lags(1/4)
If you want to check how variables jointly affect the dependent variables, use Granger
causality test as follows:
vargranger
Diagnostic checking for VAR model: Run the following tests:

3
Lagrange multiplier test to check if residuals are auto-correlated or not (whether model is
well-specified):
varlmar
Jarque-Bera test to check whether residuals are normally distributed or not:
varnorm, jbera
jbera stands for Jarque-Bera
Prob value below 10% shows residuals are not normally distributed
Time Series Autoregressive Distributed Lag (ARDL) Model:
ardl y x1 x2 x3 x4, lag(2 1 1 1 1) ec or
ardl y x1 x2 x3 x4, lag(2) ec
The value must be negative, significant and in between 0 to 1, representing error correction
term or speed of adjustment
To confirm existence of long-run relationship, we run bound test as follows:
estat btest
btest stand for bound test
The long-run cointegration is possible if the F statistics value is above the critical value.
After ardl run normality test
Predict myResiduals, r
Sktest myresiduals
Run parameter stability cusum test
cusum6 MK REMR INT EXR BSD, cs(cusum)lw(lower)uw(upper) or
cusum6 MK REMR INT EXR BSD
Command for Zivot-Andrews unit root test (structural break):
zandrews x
zandrews d.x
Gregory-Hansen Cointegration test
Command for g-hansen test with change in level:
ghansen y x1 x2 x3 x4, break(level) lagmethod(aic) maxlags(4)

4
Command for g-hansen test under regime change;
ghansen y x1 x2 x3 x4, break(regime) lagmethod(fixed) maxlags(4)
Command for g-hansen test with change in regime and trend:
ghansen y x1 x2 x3 x4, break(regimetrend) lagmethod(downt) level(0.99) trim(0.1)

Command for Non-linear Autoregressive Distributed Lag (NARDL) for frequency data

nardl y x1 x2 x3 x4, p(2) q(4) constraints (1/2) plot bootstrapt (500) level (95)

p(2) stands for lags of dependent variable, q(4) lags for explanatory variables

Command for non-linear Autoregressive Distributed Lag (NARDL) for fewer observations

nardl y x1 x2 x3 x4

The results include positive and negative coefficients otherwise asymmetric effect

Steps for running Toda and Yamamoto Granger-non causality test


After testing for unitroot
Estimate var model to select appropriate lag as follows
var y x1 x2 x3 x4, lags(1/4)
varsoc
Assuming lag 3 is selected for the model, then run var model to include exogenous variables:
var y x1 x2 x3 x4, lags(1/2) exog(13.y 13.x1 13.x2 13.x3 13.x4)
Then run Toda Yamamoto causality test as follows:
vargranger

View publication stats

You might also like