1. Intro

As the 20% of my mark for Macroeconometrics depends on the VAR assignment and my participation in the e-meetings, I’m going to start doing my assignment.

For my assignment, I’m going to estimate a VAR model with Eurostat data. I downloaded the data using the to-download-my_data.Rmd file the xx/04/2020. Big thanks to the the eurostat package.

And remember, as the lecturer said repeatedly during the e-meetings, that there are some rules to deliver the assignment to him:

  • you have to deliver the assignment by mail to pedro.j.perez@uv.es BEFORE the 15/05/2020.

  • you should attach in you mail a single .zip file.

  • this single .zip file has to contain your assignment as an Rproject.

  • Remember that you have to name the folder of you Rproject like: . That is, if for instance, in your assignment you have used data from Spain and your name would be “Pedro Pérez Vázquez”, then, the folder of your Rproject should be named: VAR_perez_pedro_spain. Please, all in lower case, except VAR, and no spaces, no punctuation marks in the name of the folder.

  • Then, if the name of the folder of your Rproject is VAR_perez_pedro_spain then the .zip file you have to send me by e-mail should be named: VAR_perez_pedro_spain.zip.




2. Data preparation

As we are going to use the vars package to estimate and analyse a structural VAR model, I need to transform my data to a format suitable for the vars package.


Loading my data

Obviously, first I have to load my data. As I have saved the file with my data in a the folder called datos inside the main folder of the Rproject, THEN, to load my data I have to do:

Other way to load the data. This second way to load the data is preferable.

We are going to use only 3/4 the variables: Vol, Vol_15, Vol_us & time


Creating the ts objects

As the vars package need that the data are in a special format (ts), then, I have to convert my data to the ts format

To do that, first we have to look at the common sample of our 3 series:

Dropping rows with NAs to obtain the The common sample for my data.

calculating the start and end of the common sample of my data:

OK, now we can create the ts object needed to work with the vars package.


Creating logs and first log-differences of the time series


Selecting, binding and naming the 3 series we are going to use:


A dynamic graph (with the dygraph package):




Making a graph for the series in log-first-differences: (1-L)logGDP





3. Estimation of the VAR model

OK, I have to estimate the VAR, let’s load the vars package …..





LS0tCnRpdGxlOiAiTXkgVkFSIG1vZGVsOiBTUEFJTiIKYXV0aG9yOiAiWW91ciBuYW1lIgpkYXRlOiAiYHIgZm9ybWF0KFN5cy50aW1lKCksICclZCAlQiwgJVknKWAiIApvdXRwdXQ6IAogIGh0bWxfZ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