-
Notifications
You must be signed in to change notification settings - Fork 0
/
analysis.R
132 lines (99 loc) · 3.23 KB
/
analysis.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
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
### log icin degiskiliiikkk
library(dplyr)
library(ggplot2)
library(purrr)
library(tidyr)
#Let's load the datasets:
commune_level_data <- read.csv("datasets/commune_level_data.csv")
country_level_data <- read.csv("datasets/country_level_data.csv")
#Let's compute the Laspeyeres index for each commune:
commune_level_data <- commune_level_data %>%
group_by(locality) %>%
mutate(p0 = ifelse(year == "2010", average_price_nominal_euros, NA)) %>%
fill(p0, .direction = "down") %>%
mutate(p0_m2 = ifelse(year == "2010", average_price_m2_nominal_euros, NA)) %>%
fill(p0_m2, .direction = "down") %>%
ungroup() %>%
mutate(pl = average_price_nominal_euros/p0*100,
pl_m2 = average_price_m2_nominal_euros/p0_m2*100)
#Let's also compute it for the whole country:
country_level_data <- country_level_data %>%
mutate(p0 = ifelse(year == "2010", average_price_nominal_euros, NA)) %>%
fill(p0, .direction = "down") %>%
mutate(p0_m2 = ifelse(year == "2010", average_price_m2_nominal_euros, NA)) %>%
fill(p0_m2, .direction = "down") %>%
mutate(pl = average_price_nominal_euros/p0*100,
pl_m2 = average_price_m2_nominal_euros/p0_m2*100)
#We are going to create a plot for 5 communes and compare the price evolution in the communes
#to the national price evolution. Let's first list the communes:
communes <- c("Luxembourg",
"Esch-sur-Alzette",
"Mamer",
"Schengen",
"Wincrange")
# Luxembourg
filtered_data <- commune_level_data %>%
filter(locality == communes[1])
data_to_plot <- bind_rows(
country_level_data,
filtered_data
)
lux_plot <- ggplot(data_to_plot) +
geom_line(aes(y = pl_m2,
x = year,
group = locality,
colour = locality))
# Esch sur Alzette
filtered_data <- commune_level_data %>%
filter(locality == communes[2])
data_to_plot <- bind_rows(
country_level_data,
filtered_data
)
esch_plot <- ggplot(data_to_plot) +
geom_line(aes(y = pl_m2,
x = year,
group = locality,
colour = locality))
# Mamer
filtered_data <- commune_level_data %>%
filter(locality == communes[3])
data_to_plot <- bind_rows(
country_level_data,
filtered_data
)
mamer_plot <- ggplot(data_to_plot) +
geom_line(aes(y = pl_m2,
x = year,
group = locality,
colour = locality))
# Schengen
filtered_data <- commune_level_data %>%
filter(locality == communes[4])
data_to_plot <- bind_rows(
country_level_data,
filtered_data
)
schengen_plot <- ggplot(data_to_plot) +
geom_line(aes(y = pl_m2,
x = year,
group = locality,
colour = locality))
# Wincrange
filtered_data <- commune_level_data %>%
filter(locality == communes[5])
data_to_plot <- bind_rows(
country_level_data,
filtered_data
)
wincrange_plot <- ggplot(data_to_plot) +
geom_line(aes(y = pl_m2,
x = year,
group = locality,
colour = locality))
# Let's save the plots
ggsave("plots/lux_plot.pdf", lux_plot)
ggsave("plots/esch_plot.pdf", esch_plot)
ggsave("plots/mamer_plot.pdf", mamer_plot)
ggsave("plots/schengen_plot.pdf", schengen_plot)
ggsave("plots/wincrange_plot.pdf", wincrange_plot)