Mapping Quandl Macroeconomic Data

Mapping Quandl Macroeconomic Data

This is my notes for learning Mapping Quandl Macroeconomic Data. In this article, we are going to be working with a macroeconomic data source from the World Bank called World Development Indicators (WDI). The Quandl code for WDI is WWDI, and thus we’ll prepend WWDI/ to each data set call. For more details, you can refer to: https://docs.quandl.com/docs/r-time-series and http://datatopics.worldbank.org/world-development-indicators/

R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
library(purrr)
econIndicators <- c("GDP Per Capita" = "WWDI/CHN_NY_GDP_PCAP_KN",
"GDP Per Capita Growth" = "WWDI/CHN_NY_GDP_PCAP_KD_ZG",
"Real Interest Rate" = "WWDI/CHN_FR_INR_RINR",
"Exchange Rate" = "WWDI/CHN_PX_REX_REER",
"CPI" = "WWDI/CHN_FP_CPI_TOTL_ZG",
"Labor Force Part. Rate" = "WWDI/CHN_SL_TLF_ACTI_ZS")
Quandl.api_key("czxo9-jMWsDtdqRpX9Pj")
China_all_indicators <- econIndicators %>%
map(Quandl, type = "xts") %>%
reduce(merge) %>%
`colnames<-`(names(econIndicators))

tail(China_all_indicators)
GDP Per Capita GDP Per Capita Growth Real Interest Rate Exchange Rate CPI Labor Force Part. Rate
44256.98 7.226936 3.6925969 114.6386 2.621049 76.470
47246.89 6.755778 4.7324242 118.3423 1.921643 76.430
50251.02 6.358383 4.2526974 129.9315 1.437025 76.385
53328.30 6.123804 3.1758408 123.6252 2.000000 76.336
56690.10 6.303967 0.2840018 120.0720 1.593137 76.340
NA NA NA NA NA 76.221

Next, I made a flexdashboard, you can see a live version here: Mapping Quandl Macroeconomic Data | China.

Source Codes:

RMD
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
---
title: "Mapping Quandl Macroeconomic Data | China"
runtime: shiny
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
---

```{r setup, include=FALSE}
library(flexdashboard)
library(Quandl)
library(purrr)
library(dygraphs)
econIndicators <- c("GDP Per Capita" = "WWDI/CHN_NY_GDP_PCAP_KN",
"GDP Per Capita Growth" = "WWDI/CHN_NY_GDP_PCAP_KD_ZG",
"Real Interest Rate" = "WWDI/CHN_FR_INR_RINR",
"Exchange Rate" = "WWDI/CHN_PX_REX_REER",
"CPI" = "WWDI/CHN_FP_CPI_TOTL_ZG",
"Labor Force Part. Rate" = "WWDI/CHN_SL_TLF_ACTI_ZS")
Quandl.api_key("czxo9-jMWsDtdqRpX9Pj")
China_all_indicators <- econIndicators %>%
map(Quandl, type = "xts") %>%
reduce(merge) %>%
`colnames<-`(names(econIndicators))
```

Column {data-width=333}
-----------------------------------------------------------------------

### GDP Per Capita

```{r}
dygraph(China_all_indicators$`GDP Per Capita`,
main = "GDP Per Capita")
```

### GDP Per Capita Growth

```{r}
dygraph(China_all_indicators$`GDP Per Capita Growth`,
main = "GDP Per Capita Growth")
```

Column {data-width=333}
-----------------------------------------------------------------------

### Real Interest Rate

```{r}
dygraph(China_all_indicators$`Real Interest Rate`, main = "Real Interest Rate")
```

### Exchange Rate

```{r}
dygraph(China_all_indicators$`Exchange Rate`, main = "Exchange Rate")
```

Column {data-width=333}
-----------------------------------------------------------------------

### CPI

```{r}
dygraph(China_all_indicators$`CPI`, main = "CPI")
```

### Labor Force Part. Rate

```{r}
dygraph(China_all_indicators$`Labor Force Part. Rate`, main = "Labor Force Part. Rate")
```

GDP-per-capita has been on a steady much higher, labor force participation plummeted (垂直下降) in the 1990’s and 2000’s, probably as the labor market became more market-oriented, and real interest rates look quite choppy (起伏不定的).

Next, it’s on to map-building!

R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
library(rnaturalearth)
library(sp)
world <- ne_countries(
type = "countries",
returnclass = "sf"
)
head(world[c('name', 'gdp_md_est', 'economy')], n = 6)

library(leaflet)
gdpPal <- colorQuantile(
"Purples",
world$gdp_md_est,
n = 9)
popup <- paste0("<strong>Country: </strong>",
world$name,
"<br><strong>Income Group: </strong>",
world$income_grp)
leaflet(world) %>%
addProviderTiles("CartoDB.Positron") %>%
setView(lng = 113, lat = 23, zoom = 2) %>%
addPolygons(stroke = FALSE,
smoothFactor = 0.2,
fillOpacity = 0.7,
color = ~gdpPal(gdp_md_est),
layerId = ~iso_a3,
popup = popup)

Because Quandl uses the ISO 3-letter code to identity a counrey, and because the rnaturalearth sf object already contains a column with iso_a3 country codes, building our map wasn’t very hard.

# R

Comments

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×