馃攳
Performing time series regression Stata - YouTube
Channel: unknown
[0]
In today's video tutorial we'll discuss聽
how can we perform time series regression聽聽
[5]
using the software Stata. Let's take an example.聽
Here you can see this is Stata software and let's聽聽
[13]
go to the data file. We have three variables聽
inflation, which is our dependent variable聽聽
[20]
and we have two independent variables one is聽
import and another one is exchange rate, so we聽聽
[25]
want to see the impact of import and exchange rate聽
on inflation. As this is time series data we have聽聽
[32]
the last 80 years data we have started from聽聽
[37]
1940 and this ended 2019, so last eight years聽
data. So it is a time series that you can see,聽聽
[46]
right. Now first you need to declare your data set聽
to be time series, so to do this you need to type聽聽
[58]
'tsset' and you can see this is the time variable聽
which we have decoded as a year so I put it there聽聽
[68]
and since this is the yearly data so you聽
can write yearly, press enter so it says聽聽
[74]
it is a time series data so it's from 1940聽
to 2019 and the change is one year. Our next聽聽
[84]
job is to check whether this data, this聽
time is stationary or not, so we'll聽聽
[94]
start by having a graphical analysis of the static聽
variables. So to do this you need to write 'line'聽聽
[106]
and your dependent variable, that is inflation聽
and two independents, import, exchange rate聽聽
[114]
and we'd like to put our time variables as聽
it is here, so here comma and then 'legend'聽聽
[129]
and do not keep any space between legend聽
and this first bracket, so it will聽聽
[136]
come just after this first bracket,聽
will come just after legend, so legend,聽聽
[140]
first bracket and then 'size' and聽
then you can first bracket 'medsmall'
[150]
close up this bracket and press enter. Now聽
we can see the graphical presentation of this聽聽
[159]
three time series data, so it denotes which,聽
indicates on this, you know one is the inflation,聽聽
[167]
exchange rate, so this actually denotes聽
which variable and you can see here that聽聽
[176]
these lines are actually trending upward聽
and almost constant from 1940 to 2020.聽聽
[187]
So this means during specifying聽
our stationarity test that is聽聽
[194]
Augmented Dickey-Fuller test that we will use聽
here. We have to include constant and trend聽聽
[204]
so we will now perform Augmented聽
Dickey-Fuller test and this is actually called聽聽
[211]
in abbreviation ADF test. So let's see what聽
happened to our variables at each level. So聽聽
[223]
to do this we just you can take any of this聽
variable, so you can you need to do this聽聽
[229]
one by one variable, so I'm just聽
taking one variable as an example,聽聽
[234]
so you need to write 'dfuller' and then for聽
example I'm just taking import and trend because聽聽
[246]
we need to use trend that we have seen this聽
from this graphical presentation just before,聽聽
[252]
and 'lag0', so this is actually at level. Press聽
enter. Now you can see the p value it is not聽聽
[261]
statistically significant, that means these聽
variables, this data, actually not stationary聽聽
[270]
at level, so if it is not stationary at level,聽
so we need to then perform the same analysis聽聽
[280]
but including lag length so the fuller import聽
trend lag, so I'm now including first lag. So now聽聽
[291]
you can see this time it is statistically聽
significant right, so as it is less than one聽聽
[298]
percent, so this is statistically significant.聽
That means our data is first order integrated.聽聽
[307]
So if it is not first order integrated, then you聽
again need to run this same formula but adding聽聽
[317]
more lag length here. So in this way we can check聽
for each of these variables and say whether they聽聽
[325]
are stationary at level or stationary at the聽
first difference, or at the second difference.
[332]
So if our variable are first order integrated聽
or variables are stationary in first difference聽聽
[340]
we need to perform co-integration test聽
to establish long-run relationship.聽聽
[346]
Here we'll perform Johansen co-integration test.聽聽
[351]
Our our null hypothesis is no co-integration聽
equation, against the alternative hypothesis聽聽
[357]
there is co-integration relationship. However,聽
we need to select our determined appropriate lag聽聽
[364]
length before running Johansen co-integration聽
test. So to do this we need to use this command聽聽
[376]
'varbasic' it is actually two-step command,聽
so this is the first step, varbasic and our聽聽
[382]
variable dependent variable inflation聽
and two independent variable聽聽
[387]
and I can check this up to for example lag聽
length four you can take like length five,聽聽
[395]
six whatever but I think it's good to聽
check up to five or four, so one by four.
[403]
Press enter, you will get some result here
[411]
and after this command the second step聽
you need to type 'varsoc' now you will get聽聽
[423]
the selection order criteria, so these聽
are different criteria, so this indicates聽聽
[431]
what appropriate lag length you need聽
to select. You can see here that FPE,聽聽
[438]
AIC, HQIC and SBIC this all four actually聽
indicates this actually stars, stars, stars,聽聽
[445]
stars so this all four actually indicates聽
appropriate lag length is 2, although LR,聽聽
[452]
this criteria is saying that appropriate lag聽
length is 4, but it's the only one criteria that's聽聽
[459]
saying this, but you say the maximum of these聽
these four they are actually indicating two. So聽聽
[465]
if you see the maximum criteria, which indicates聽
the appropriate length you need to select that聽聽
[474]
one ,so that is actually in this case two, so聽
our appropriate lag length should be two. Now聽聽
[482]
we know our appropriate lag length, so we now can聽
perform Johansen co-integration test. To do this聽聽
[489]
we need to type 'vecrank' and then our variable聽
so inflation is dependent on import, exchange rate
[501]
and lags and these lags that we have just聽
identified, it is actually two, so you need to聽聽
[510]
write '2' and 'trend'
[517]
'(constant)' and 'levela' 'max'. So this聽
command you need to use this to perform聽聽
[530]
this Johansen co-integration test. So you can see聽
the result of Johansen test for co-integration.
[540]
Now, the decision criteria is that,聽聽
[547]
if your trace statistic, if it is greater聽
than your critical value then you will
[555]
reject the null hypothesis. So in that case,聽
if this trace statistic is greater than聽聽
[562]
our maximum eigen statistic, it is greater聽
than critical value, in that case I can say聽聽
[569]
that there is a co-integration equation,聽
a cointegration relationship exists.聽聽
[575]
So I can see here that this 39 is greater than 29聽
so yeah there is one co-integration relationship,聽聽
[582]
however this one is actually less than 15 and聽
this one also less than this critical value,聽聽
[590]
similarly if you take that maximum again聽
test statistic, you can see here that 28 is聽聽
[598]
greater than 20 so it also indicates that聽
at least one co-integration relationship,聽聽
[603]
however these are less than the critical聽
value. Since both test statistics and max聽聽
[609]
eigen statistics both are indicating that聽
at least one co-integration relationship聽聽
[614]
exists, so we can perform our regression聽
which is in our cases it is actually,
[625]
we call it vector auto regression model. Now to聽
perform vector auto regression model you need to聽聽
[639]
write our formula that is 'var' that is actually聽
vector auto regression model and then you need to
[652]
if you find your dependent inflation聽
and import, exchange rate, these two are聽聽
[656]
independent variables and 'lags' and we previously聽
defined one by obviously defined that our聽聽
[664]
appropriate length is two or聽
two and a bracket and enter.
[672]
So we get this vector auto regression result,聽
right. So this table is a little bit tricky but聽聽
[689]
no matter to worry because, you need聽
to see this this actually inflation and聽聽
[697]
this is the dependent variable and this聽
shows the relationship with this one.聽聽
[702]
So if inflation is the dependent variable聽
and I would like to see the relationship聽聽
[709]
with the import, so there is no significant聽
impact of import on inflation because it聽聽
[716]
is not statistically significant. However聽
we can see here that exchange rate at the聽聽
[723]
second order, you can see here, it is聽
actually statistically significant right.聽聽
[729]
So exchange rate positively actually聽
affect our inflation at the second order聽聽
[739]
and it is statistically significant. Last stage聽
of our analysis is the Granger causality test,聽聽
[750]
so to perform Granger causality test, the first聽
step you need to type this formula so you need to聽聽
[760]
perform vector auto regression that we already聽
have done here. So if you previously not and聽聽
[768]
not do this, then you first need to run聽
this command and then you need to run this聽聽
[774]
Granger causality test command. So already we聽
have performed this, so we got this result.聽聽
[781]
So just after this you need to type the command聽
for the Granger causality which is very easy,聽聽
[788]
just var and granger, so you can聽
see this is the command and press聽聽
[797]
enter. Now you can get this result here. Now,聽
import and so this actually the causality聽聽
[812]
actually runs from this one to that one, this聽
one to that one, this one with that one, so
[820]
you need to see this significance value, a p value聽
and you can see here import, this actually does聽聽
[830]
not- Granger cause inflation because it is not聽
statistically significant and if you consider聽聽
[837]
significance level of 10 percent in that case聽
you can say yeah exchange rate- Granger cause聽聽
[843]
inflation and this all means this all together聽
does not Granger cause inflation. However,聽聽
[851]
from here you can see that in inflation and聽
Granger cause import, exchange rate Granger聽聽
[855]
cause import and these two variables together聽
Granger cause import, so in this way we can um聽聽
[863]
explain the result of Granger causality thank you.
Most Recent Videos:
You can go back to the homepage right here: Homepage