Skip to content

Commit

Permalink
updated save_data.R
Browse files Browse the repository at this point in the history
  • Loading branch information
b-rodrigues committed Oct 2, 2023
1 parent 5835b06 commit d3f8d8b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
10 changes: 5 additions & 5 deletions scripts/analysis.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ library(ggplot2)
library(purrr)
library(tidyr)

#Lets load the datasets:
#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")

#Lets compute the Laspeyeres index for each commune:
#Let's compute the Laspeyeres index for each commune:

commune_level_data <- commune_level_data %>%
group_by(locality) %>%
Expand All @@ -21,7 +21,7 @@ commune_level_data <- commune_level_data %>%
pl_m2 = average_price_m2_nominal_euros/p0_m2*100)


#Lets also compute it for the whole country:
#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)) %>%
Expand All @@ -33,7 +33,7 @@ country_level_data <- country_level_data %>%


#We are going to create a plot for 5 communes and compare the price evolution in the communes
#to the national price evolution. Lets first list the communes:
#to the national price evolution. Let's first list the communes:

communes <- c("Luxembourg",
"Esch-sur-Alzette",
Expand Down Expand Up @@ -122,7 +122,7 @@ wincrange_plot <- ggplot(data_to_plot) +
group = locality,
colour = locality))

# Lets save the plots
# 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)
Expand Down
12 changes: 7 additions & 5 deletions scripts/save_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ raw_data <- raw_data |>

str(raw_data)

# Lets take a look at the spelling
# Let's take a look at the spelling
raw_data |>
dplyr::filter(grepl("Luxembourg", locality)) |>
dplyr::count(locality)
Expand Down Expand Up @@ -91,17 +91,19 @@ country_level_data <- full_join(country_level, offers_country) |>


# We need to check if communes are all in our data
current_communes <- "https://en.wikipedia.org/wiki/List_of_communes_of_Luxembourg" |>
current_communes <- "https://is.gd/lux_communes" |>
rvest::read_html() |>
rvest::html_table() |>
purrr::pluck(1) |>
janitor::clean_names()
purrr::pluck(2) |>
janitor::clean_names() |>
dplyr::filter(name_2 != "Name") |>
dplyr::rename(commune = name_2)

# Test if all communes are there
setdiff(unique(commune_level_data$locality), current_communes$commune)

# We need former communes
former_communes <- "https://en.wikipedia.org/wiki/Communes_of_Luxembourg#Former_communes" |>
former_communes <- "https://is.gd/lux_former_communes" |>
rvest::read_html() |>
rvest::html_table() |>
purrr::pluck(3) |>
Expand Down

0 comments on commit d3f8d8b

Please sign in to comment.