{"cells":[{"cell_type":"markdown","metadata":{},"source":["# Vector Autoregression\n","\n","In this notebook we will run Vector Autoregression (VAR) using python packages. We will revisit the exercise from Vector Autoregression by Stock and Watson (2001).\n","\n","## VAR(p) Process##\n","\n","We are interested in modeling a $T\\times K$ multivariate time series $Y$, where $T$ denotes the number of observations and $K$ the number of variables. One way of estimating relationships between the time series and their lagged values is the vector autoregression process:\n","\n","$$\n","Y_t = A + B_1 Y_{t-1} + B_2 Y_{t-2} + \\cdots + A_p Y_{t-p} + u_t\n","$$\n","where $u_t \\sim N(0,\\sigma_u)$ and $A_i$ is a $K\\times K$ coefficient matrix. "]},{"cell_type":"code","execution_count":1,"metadata":{"ExecuteTime":{"end_time":"2019-10-25T02:00:12.975297Z","start_time":"2019-10-25T02:00:12.970308Z"}},"outputs":[],"source":["import pandas as pd\n","import numpy as np\n","import statsmodels.api as sm\n","from statsmodels.tsa.api import VAR"]},{"cell_type":"markdown","metadata":{},"source":["### Prepare data"]},{"cell_type":"code","execution_count":37,"metadata":{"ExecuteTime":{"end_time":"2019-10-25T02:10:09.192792Z","start_time":"2019-10-25T02:10:09.153897Z"}},"outputs":[],"source":["data = pd.read_excel('SW2001_data.xlsx')\n","data.index = pd.DatetimeIndex(data['obs'])\n","data_use = data[['Inflation','Unemployment','Fed Funds']]"]},{"cell_type":"code","execution_count":18,"metadata":{"ExecuteTime":{"end_time":"2019-10-25T02:03:31.207320Z","start_time":"2019-10-25T02:03:31.194353Z"}},"outputs":[{"data":{"text/html":["
\n"," | Inflation | \n","Unemployment | \n","Fed Funds | \n","
---|---|---|---|
obs | \n","\n"," | \n"," | \n"," |
1960-01-01 | \n","0.908472 | \n","5.133333 | \n","3.933333 | \n","
1960-04-01 | \n","1.810777 | \n","5.233333 | \n","3.696667 | \n","
1960-07-01 | \n","1.622720 | \n","5.533333 | \n","2.936667 | \n","
1960-10-01 | \n","1.795335 | \n","6.266667 | \n","2.296667 | \n","
1961-01-01 | \n","0.537033 | \n","6.800000 | \n","2.003333 | \n","
1961-04-01 | \n","0.714924 | \n","7.000000 | \n","1.733333 | \n","
1961-07-01 | \n","0.891862 | \n","6.766667 | \n","1.683333 | \n","
1961-10-01 | \n","1.067616 | \n","6.200000 | \n","2.400000 | \n","
1962-01-01 | \n","2.303439 | \n","5.633333 | \n","2.456667 | \n","
1962-04-01 | \n","1.234841 | \n","5.533333 | \n","2.606667 | \n","