Skip to contents
library(housing)

Downloading the data

This data is downloaded from the luxembourguish Open Data Portal (the data set called Série rétrospective des prix annoncés des maisons par commune, de 2010 à 2021), and the original data is from the “Observatoire de l’habitat”. This data contains prices for houses sold since 2010 for each luxembourguish commune.

The function below uses the permanent URL from the Open Data Portal to access the data, but I have also rehosted the data, and use my link to download the data (for archival purposes):

raw_data <- get_raw_data(url = "https://github.com/b-rodrigues/rap4all/raw/master/datasets/vente-maison-2010-2021.xlsx")
#> New names:
#>  `*` -> `*...3`
#>  `*` -> `*...4`

We need clean the data: “Luxembourg” is “Luxembourg-ville” in 2010 and 2011, then “Luxembourg”. “Pétange” is also spelled non-consistently, and we also need to convert columns to right type. We also directly remove rows where the locality contains information on the “Source”:

flat_data <- clean_raw_data(raw_data)
#> Warning in mask$eval_all_mutate(quo): NAs introduced by coercion

#> Warning in mask$eval_all_mutate(quo): NAs introduced by coercion

We now need to make sure that we got all the communes/localities in there. There were mergers in 2011, 2015 and 2018. So we need to account for these localities.

We’re now scraping data from wikipedia of former Luxembourguish communes:

former_communes <- get_former_communes()

We can scrape current communes:

current_communes <- get_current_communes()

Let’s now create a list of all communes:

former_communes <- get_former_communes()
current_communes <- get_current_communes()

communes <- get_test_communes(former_communes, current_communes)

Let’s test to see if all the communes from our dataset are represented.

If the above code doesn’t show any communes, then this means that we are accounting for every commune.

Let’s keep the national average in another dataset:

country_level_data <- make_country_level_data(flat_data)
#> Joining, by = "year"

We can finish cleaning the commune data:

commune_level_data <- make_commune_level_data(flat_data)

We now save the dataset in a folder for further analysis (keep chunk option to eval = F to avoid running it when knitting):

Functions used for analysis

The following function compute the Laspeyeres prices index:

#' \dontrun{
#' commune_level_data_laspeyeres <- get_laspeyeres(commune_level_data)
#' } 

and this function plots the data:

#' \dontrun{
#'commune_level_data_laspeyeres <- get_laspeyeres(commune_level_data)
#'make_plot(commune_level_data_laspeyeres, "Luxembourg")
#' }