-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path002_solution_homework1_format.Rmd
347 lines (289 loc) · 14.6 KB
/
002_solution_homework1_format.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
---
title: "Homework 1"
author:
- XXXXXXXX (Only code no name)
- XXXXXXXX (Only code no name)
- XXXXXXXX (Only code no name)
- XXXXXXXX (Only code no name)
- XXXXXXXX (Only code no name)
- XXXXXXXX (Only code no name)
date: ""
output:
html_document:
df_print: paged
highlight: tango
number_sections: yes
theme: flatly
toc: yes
toc_depth: 3
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE,
warning = FALSE,
message = FALSE,
fig.align = "center")
```
```{r}
library(tidyverse)
library(tidyquant)
library(wbstats)
library(plotly)
```
# Gross Domestic Product (GDP)
## Real and Nominal GDP
- Enter into the World Bank's Human Development Indicators database using the link:
<**https://databank.worldbank.org/source/world-development-indicators**>
- In *Country* select *Colombia*
- In *Series* select *GDP (current LCU)*
- In *Time* select *VIEW RECENT YEARS: 50*
- Apply changes and download the data using *Download options > Excel* at the upper right corner of the platform
1. Make a plot of the **Nominal GDP** of *Colombia* where the x-axis corresponds to the years and y-axis corresponds to the value of the **Nominal GDP**. **(4 points)**
```{r}
# Data
## Colombia Nominal GDP
nominal_gdp_col <- wbstats::wb_data(country = c("COL"),
indicator = c("NY.GDP.MKTP.CN"),
return_wide = FALSE) %>%
select(country, date, value) %>%
mutate(label_text = str_glue("Year: {date}
Nominal GDP: {value}"))
# Plot
static_plot1 <- nominal_gdp_col %>%
ggplot(aes(x = date,
y = value)) +
geom_point(aes(text = label_text),
shape = 21,
fill = palette_light()[[2]],
color = "black") +
geom_line() +
labs(x = "Year",
y = "Billions (Long scale)",
title = "Nominal GDP Colombia") +
scale_y_continuous(labels = scales::number_format(scale = 1e-12,
suffix = "B",
accuracy = 1)) +
theme(panel.border = element_rect(fill = NA, color = "black"),
plot.background = element_rect(fill = "#f3fcfc"),
panel.background = element_rect(fill = "#f3f7fc"),
legend.background = element_rect(fill = "#f3fcfc"),
plot.title = element_text(face = "bold"),
axis.title = element_text(face = "bold"),
legend.title = element_text(face = "bold"),
axis.text = element_text(face = "bold"))
# Interactivity
static_plot1 %>%
ggplotly(tooltip = "text")
```
2. Explain why **Nominal GDP** is not a good measure of the aggregate production for *Colombia*. **(4 points)**
The **Nominal GDP** captures the variation in quantities and prices related to production of *Colombia* in monetary terms. Therefore it is difficult to identify what is really increasing or decreasing. A better metric to measure final production in *Colombia* would be the **Real GDP** which tries to eliminate the effect that prices have on production to examine the increase or decrease in quantities.
- In *Country* select *Colombia*
- In *Series* select *GDP (constant LCU)*
- In *Time* select *VIEW RECENT YEARS: 50*
- Apply changes and download the data using *Download options > Excel* at the upper right corner of the platform
3. Make a plot of the **Nominal GDP** and the **Real Nominal GDP** of *Colombia* where the x-axis corresponds to the years and y-axis corresponds to the values of the **Nominal GDP** and **Real GDP**. **(4 points)**
```{r}
# Data
## Colombia Real and Nominal GDP
real_nominal_gdp_col <- wbstats::wb_data(country = c("COL"),
indicator = c("NY.GDP.MKTP.CN", "NY.GDP.MKTP.KN"),
return_wide = FALSE) %>%
select(country, date, value, indicator) %>%
mutate(label_text = case_when(
indicator == "GDP (current LCU)" ~ str_glue("Year: {date}
Nominal GDP: {value}"),
indicator == "GDP (constant LCU)" ~ str_glue("Year: {date}
Real GDP: {value}"),
TRUE ~ indicator)) %>%
group_by(indicator) %>%
arrange(date) %>%
ungroup()
# Plot
static_plot2 <- real_nominal_gdp_col %>%
ggplot(aes(x = date,
y = value)) +
geom_point(aes(fill = indicator, text = label_text),
color = "black",
shape = 21) +
geom_line(aes(color = indicator,
group = indicator)) +
geom_vline(xintercept = 2015,
color = palette_light()[[1]]) +
labs(x = "Year",
y = "Billions (Long scale)",
title = "Nominal and Real GDP Colombia",
color = "") +
scale_x_continuous(breaks = c(1960, 1980, 2000, 2015, 2020)) +
scale_y_continuous(labels = scales::number_format(scale = 1e-12,
suffix = "B",
accuracy = 1)) +
scale_color_tq() +
scale_fill_tq() +
theme(panel.border = element_rect(fill = NA, color = "black"),
plot.background = element_rect(fill = "#f3fcfc"),
panel.background = element_rect(fill = "#f3f7fc"),
legend.background = element_rect(fill = "#f3fcfc"),
legend.position = "none",
plot.title = element_text(face = "bold"),
axis.title = element_text(face = "bold"),
legend.title = element_text(face = "bold"),
axis.text = element_text(face = "bold"))
# Interactivity
static_plot2 %>%
ggplotly(tooltip = "text")
```
4. Explain why **Real GDP** is a better measure of the aggregate production than **Nominal GDP** for *Colombia*. **(4 points)**
**Real GDP** is a better measure of the aggregate production than **Nominal GDP** because it tries to control for the effect that prices have on production (measure in monetary terms). In the case of *Colombia* the **Nominal GDP** increased during the last years of the plot but it is mainly because of a persistent increase in prices.
5. Explain why **Real GDP** and **Nominal GDP** have the same value in one year. **(4 points)**
**Real GDP** and **Nominal GDP** have the same value in the year __2015__ because this is the base year that was used to calculate the **Real GDP** for *Colombia*. This can be seen in the previous plot.
- In *Country* select *Colombia*
- In *Series* select *Population, total*
- In *Time* select *VIEW RECENT YEARS: 50*
- Apply changes and download the data using *Download options > Excel* at the upper right corner of the platform
6. Calculate *Real GDP per-capita* for **Colombia**. **(4 points)**
```{r}
# Data
## Colombia Real per capita GDP
per_capita_gdp_col <- wbstats::wb_data(country = c("COL"),
indicator = c("NY.GDP.MKTP.KN", "SP.POP.TOTL"),
return_wide = TRUE) %>%
select(country, date, NY.GDP.MKTP.KN, SP.POP.TOTL) %>%
set_names(c("country", "date", "real_gdp", "pop")) %>%
mutate(real_per_capita_gdp = real_gdp / pop,
label_text = str_glue("Year: {date},
Real GDP: {real_gdp},
Population: {pop},
Real GDP per-capita: {real_per_capita_gdp %>% round()}"))
# Plot
static_plot3 <- per_capita_gdp_col %>%
ggplot(aes(x = date,
y = real_per_capita_gdp)) +
geom_point(aes(text = label_text),
shape = 21,
fill = palette_light()[[2]],
color = "black") +
geom_line() +
labs(x = "Year",
y = "Colombian pesos (COP)",
title = "Real GDP per-capita Colombia (COP) Base Year 2015",
color = "") +
scale_x_continuous(breaks = c(1960, 1980, 2000, 2020)) +
scale_y_continuous() +
scale_color_tq() +
scale_fill_tq() +
theme(panel.border = element_rect(fill = NA, color = "black"),
plot.background = element_rect(fill = "#f3fcfc"),
panel.background = element_rect(fill = "#f3f7fc"),
legend.background = element_rect(fill = "#f3fcfc"),
legend.position = "none",
plot.title = element_text(face = "bold"),
axis.title = element_text(face = "bold"),
legend.title = element_text(face = "bold"),
axis.text = element_text(face = "bold"))
# Interactivity
static_plot3 %>%
ggplotly(tooltip = "text")
```
7. Explain why *Real GDP per-capita* is a better measure for the production than *Real GDP* for *Colombia* **(4 points)**
**Real GDP per-capita** is a better measure for the production than **Real GDP** because it controls for the population. Making a population adjustment is important because production can increase simply because there are more people. In territories where there are more people, more production is expected but not because they are more productive but because there is more workforce. Therefore it is better to use per-capita data.
8. Plot the growth of the *Real GDP per-capita* for *Colombia*. **(4 points)**
```{r}
# Data
## Colombia Real per capita GDP
growth_per_capita_gdp_col <- per_capita_gdp_col %>%
select(country, date, real_per_capita_gdp) %>%
mutate(growth_per_capita_gdp = (real_per_capita_gdp - lag(real_per_capita_gdp)) / lag(real_per_capita_gdp),
label_text = str_glue("Year: {date},
Real GDP per-capita: {real_per_capita_gdp %>% round()},
Growth Real GDP per-capita: {growth_per_capita_gdp %>% scales::percent(accuracy = 0.01)}"))
# Plot
static_plot4 <- growth_per_capita_gdp_col %>%
ggplot(aes(x = date,
y = growth_per_capita_gdp)) +
geom_point(aes(text = label_text),
shape = 21,
fill = palette_light()[[2]],
color = "black") +
geom_line() +
geom_hline(yintercept = 0,
color = palette_light()[[3]]) +
labs(x = "Year",
y = "Percent",
title = "Growth real GDP per-capita Base Year 2015",
color = "") +
scale_x_continuous(breaks = c(1960, 1980, 2000, 2020)) +
scale_y_continuous(labels = scales::percent_format(accuracy = 1)) +
scale_color_tq() +
scale_fill_tq() +
theme(panel.border = element_rect(fill = NA, color = "black"),
plot.background = element_rect(fill = "#f3fcfc"),
panel.background = element_rect(fill = "#f3f7fc"),
legend.background = element_rect(fill = "#f3fcfc"),
legend.position = "none",
plot.title = element_text(face = "bold"),
axis.title = element_text(face = "bold"),
legend.title = element_text(face = "bold"),
axis.text = element_text(face = "bold"))
# Interactivity
static_plot4 %>%
ggplotly(tooltip = "text")
```
# Inflation
9. Calculate the **GDP Deflator** using the information collected in the previous section. **(4 points)**
```{r}
deflator_gdp <- wbstats::wb_data(country = c("COL"),
indicator = c("NY.GDP.MKTP.CN", "NY.GDP.MKTP.KN"),
return_wide = TRUE) %>%
select(country, date, NY.GDP.MKTP.CN, NY.GDP.MKTP.KN) %>%
set_names(nm = c("country", "date", "nominal_gdp", "real_gdp")) %>%
mutate(gdp_deflator = (nominal_gdp / real_gdp)*100)
deflator_gdp %>%
set_names(c("Country", "Year", "Nominal GDP", "Real GDP", "GDP Deflator"))
```
10. Calculate the annual **inflation** for *Colombia* using the **GDP Deflator**. **(4 points)**
```{r}
inflation_deflator_gdp <- deflator_gdp %>%
select(country, date, gdp_deflator) %>%
mutate(inflation = (gdp_deflator - lag(gdp_deflator)) / lag(gdp_deflator),
label_text = str_glue("Year: {date},
Annual Inflation: {inflation %>% scales::percent(accuracy = 0.01)}"))
inflation_deflator_gdp %>%
mutate(inflation = scales::percent(inflation, accuracy = 0.01)) %>%
select(-label_text) %>%
set_names(nm = c("Country", "Year", "GDP Deflator", "Annual Inflation"))
```
11. Make a plot of the **inflation** where the x-axis corresponds to the years and y-axis corresponds to the values of the **inflation**. **(4 points)**
```{r}
static_plot5 <- inflation_deflator_gdp %>%
ggplot(aes(x = date,
y = inflation)) +
geom_point(aes(text = label_text),
shape = 21,
fill = palette_light()[[2]],
color = "black") +
geom_line() +
labs(x = "Year",
y = "Percent",
title = "Inflation Colombia using GDP deflator Base Year 2015",
color = "") +
scale_x_continuous(breaks = c(1960, 1980, 2000, 2020)) +
scale_y_continuous(labels = scales::percent_format()) +
scale_color_tq() +
scale_fill_tq() +
theme(panel.border = element_rect(fill = NA, color = "black"),
plot.background = element_rect(fill = "#f3fcfc"),
panel.background = element_rect(fill = "#f3f7fc"),
legend.background = element_rect(fill = "#f3fcfc"),
legend.position = "none",
plot.title = element_text(face = "bold"),
axis.title = element_text(face = "bold"),
legend.title = element_text(face = "bold"),
axis.text = element_text(face = "bold"))
# Interactivity
static_plot5 %>%
ggplotly(tooltip = "text")
```
12. Describe what you see in the plot and point out why is important for a company in a country to have an economic macroenvironment with a low and stable **inflation** rate. *Hint*: Review the videos found in **Primer corte 30% > Learning Resources > Links of interest**. **(6 points)**
Based on the information available, *Colombia* has had periods of persistent price increases where for this period the highest **inflation** rate is presented in the year __1990__. For a company in a country it is important to have an economic macroenvironment with a low and stable **inflation** rate because:
- The purchasing power of consumers' money is preserved, allowing more products to be purchased from companies.
- Resources by a company can be managed more efficiently since the prices of raw materials and inputs are more predictable, making it easier to plan future production.
- In an environment with low and stable inflation, government institutions can adopt better policies that particularly benefit businesses.