Importing, Wrangling and Visualizing GDP and Market Data
Welcome to our opening section on GDP, and the stock market. GDP is much talked about and if you have studied macroeconomics formally or informally, it’s probably quite familiar to you. In this opening section, we will spend time with GDP data, importing it, wrangling it and visualizing it. Our goal is to cover the fundamental data wrangling and visualization skills we will need for the rest of the book, and throughout our journey in economic data science.
This section proceeds as follows:
In the first chapter, GDP we lay the good ground work for exploring quarterly macroeconomic data and also to equip ourselves with sufficient R skills for the remainder of the book. We import and wrangle a spreadsheet, and we import data from FRED. If you’re already an intermediate R coder and familiar with the tidyverse
, timetk
, importing spreadsheets and FRED data, this first chapter might be just review but it’s a good idea to browse it and get familiar with some of the objects and style in this book. Plus we will wrangle a pretty nasty spreadsheet into shape, and if you plan to work in the financial industry, nasty spreadsheets will become your constant companion. The code should help.
In the second chapter, Markets we introduce market prices and returns. We walk through how to import and wrangle that data into a format that can be combined with GDP data. This chapter is important because we will use that market data throughout the rest of the book, and converting daily prices to returns of various periodicities is a skill that will stay with us for a long time.
In the final chapter, Joining GDP and Market Data, we delve into a small project visualizing the relationship between GDP growth and market returns.
Note that most of the code in this section is also meant as an introduction to R and how we approach it for time series. If you’re an advanced R coder, you can probably skim this section but do have a close look at the objects we create because they will appear throughout the book.