1. Intro

The objective of this .Rmd file is to download data from Eurostat to be used for the students in their assignments

We are going to need some packages, then we are going to load them:


2. Countries available from Eurostat

First, we will see the list of available countries in the Eurostat database. They are in the data.frame called eu_countries

Let’s see the countries list as a table


3. You have to chose your country

Every one of you should choose one different country.

During the lessons/e-meetings we will use data for Spain, then here I choose Spain

We can now start to download the data. I repeat, in the lessons I will use data for Spain , BUT for your assignment you should use other country. Each of you a different country




4. Downloading the data for the assignment

OK. The code below will download some data for the country you have chosen


  1. First, we have to set some parameters to say to the eurostat package API which series we want to download


  1. Already downloading the data for the country you have chosen (my_country)


  1. “Cleaning” the data for the country chosen


let’s see what we have in the data.frame data_c

time Vol GDP Def GDPr
1995-01-01 65.8 112945.8 70.583 160018.4
2019-10-01 111.2 315710.0 116.780 270345.9


  1. Dow loading data for the EU15


let’s see what we have in the data.frame data_15

time Vol_15 GDP_15 Def_15 GDPr_15
1995-01-01 76.1 1738293 80.959 2147127
2019-10-01 113.7 3779499 117.775 3209084


  1. Downloading data for the US


let’s see what we have in the data.frame data_us

time Vol_us GDP_us_e GDP_us tc_e_d
1995-01-01 67.6 1476928 1880572 1.2733
2019-10-01 123.2 4906766 5432281 1.1071




3. Merging the data

We have download data for the country you have chosen, for E15, and for the US. We have to join the data in a unique data.frame. But they have to share the same sample.

Good, we already have all the data we need in one data.frame. We have to save it because you will do your assignment with this data




4. Saving the data in a file

For example we can save the data in .csv format:


Or in .rds format

Please uncomment the two previous chunks to effectively save your data because you are going to need it for your assignment





LS0tCnRpdGxlOiAiRG93bmxvYWRpbmcgbXlfZGF0YSBmb3IgdGhlIGFzc2lnbm1lbnQiCmF1dGhvcjogIllvdSIKZGF0ZTogIjIwMjAsIEFwcmlsIgpvdXRwdXQ6IAogIGh0bWxfZG9jdW1lbnQ6CiAgICB0aGVtZTogdW5pdGVkCiAgICBoaWdobGlnaHQ6IHB5Z21lbnRzIAogICAgbnVtYmVyX3NlY3Rpb25zOiBubwogICAgdG9jOiB0cnVlCiAgICB0b2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