# Unit root test and cointegration

maybe someone can help me with my data.

I analyse how macroeconomic indicators affect stock index. For this analysis I prefer VAR model.In my case data of all variables are non-stationary - I have checked it by plots and also with adf test.Also I made unit root test and it says that all variables have unit root. After that I decided to apply differencing method with first order. After that with adf test I got results that all variables are stationary, because p-value is less than 0.05 but unit root test shows that some variables still have unit root.

My question is should I also apply cointegration test in this case after I found that differenced data still has unit roots? Or should it be applied before making changes as differencing in data? Basicly through a lot of sources I don't understand when should I use unit root test and cointegration test when I want to create VAR model.

• After that with adf test I got results that all variables are stationary, because p-value is less than 0.05 but unit root test shows that some variables still have unit root. ADF test is a unit root test, so what other unit root test are you talking about? Commented May 7, 2023 at 18:55
• I used adf.test function in R to see p-values and whether data is stationary or not and for unit root I used this function ur.df Commented May 8, 2023 at 16:36
• Both of these are just alternative implementations of the same ADF test. There may be differences in the precise specification of the test (depending on what options you specified in adf.test and ur.df), otherwise you should get identical results. Commented May 8, 2023 at 16:38
• Yes, sorry, probably I made some mistakes in code and now I see same results. But what about cointegration, can You help me with that? I differenced my data with first order so I got all variables integrated in level 1 . Now all of them don't have unit root and are stationary, so should I do cointegration test for those differenced in order 1 variables or when should I apply cointegration test? You see, I don't really understand sequence of testing cointegration in VAR modeling. Commented May 8, 2023 at 16:54
• Check out my answer. And do not look for cointegration between variables or their transformations that are I(0), as cointegration requires the variables under consideration to be integrated of order 1 or higher. Commented May 8, 2023 at 16:56

Let us say the highest order of integration is $$d$$; usually, $$d=1$$ though sometimes $$d=2$$.
1. If $$d=1$$ and there is a single series that is I(1) while the other ones are I(0), you take first differences of that variable and model that together with the other variables using a VAR.
2. If $$d=1$$ and there are two or more I(1) variables, you test for cointegration between them. If they are not cointegrated, you take first differences of them and model them together with I(0) variables using a VAR. If, on the other hand, the I(1) variables are cointegrated, you model them using VECM; you also include the I(0) variables on the side as in this answer. (Watch out that the left hand side of your equations is of the same order of integration as the right hand side.)
3. If $$d=2$$ and there is a single series that is I(2) while the other ones are I(1) and I(0), you take first differences of the I(2) variable and then proceed as in 1., now treating the differenced I(2) variable as a primitive.
4. If $$d=2$$ and there are two or more I(2) variables, you test for cointegration between them. If they are not cointegrated, you take first differences of them and model them together with the other variables as in 1. If, on the other hand, the I(2) variables are cointegrated, you obtain the error correction term(s) and the first-differences of all the I(2) variables and proceed as in (2). This is a bit terse, but trying to cover all cases in detail is quite tedious. (Again, watch out that the left hand side of your equations is of the same order of integration as the right hand side.)