#global parameters for knit knitr::opts_chunk$set(echo = FALSE) knitr::opts_chunk$set(warning = FALSE) knitr::opts_chunk$set(message = FALSE) knitr::opts_chunk$set(fig.align = "center") #knitr::opts_chunk$set(fig.height = 5) #knitr::opts_chunk$set(fig.width = 8) #R package dependencies library(devtools) library(ggplot2) library(rio) library(dplyr) library(plotly) library(forcats) library(lubridate) library(ggrepel) library(stringr) library(fmsb) library(countrycode) library(tidyr) library(OECDHousingToolkit) library(rLDCP) library(kableExtra)
run_edit_par=T struc_cross=rio::import("data/struc_vars_cross.xlsx") #change path accordingly catalogue_struct=rio::import("data/catalogue_structural.xlsx") #change path accordingly house_price_data=rio::import("data/house_prices_data.xlsx") #change path accordingly house_tenure_data=rio::import("data/housing_tenure_data.xlsx") #change path accordingly data_paragraphs=rio::import("data/database_paragraphs_complete.xlsx") #change path accordingly dt=NA all_vars=rio::import("data/data_CF.xlsx") #change path accordingly catalogue<-rio::import("data/catalogue_CF.xlsx") #change path accordingly definition<-rio::import("data/definitions.rda") #change path accordingly all_vars <- all_vars %>% mutate(country_name=countrycode(iso3,origin="iso3c",destination="country.name")) all_vars <- all_vars %>% select(iso3, country_name, everything()) all_vars <- subset(all_vars, !is.na(country_name) ) all_vars <- all_vars %>% rename(Iso_code3=iso3) all_vars=all_vars %>% gather(key=key,value=value,-c("Iso_code3","country_name")) %>% group_by(Iso_code3) %>% mutate(dispo_var=mean(ifelse(!is.na(value),1,0))) %>% spread(key=key,value) %>% ungroup() %>% data.frame()
\chead{ \rule[-1.75\baselineskip]{0pt}{0pt} \includegraphics[height=4\baselineskip,valign=c]{OECDlogo.jpg} \quad% Space Housing Sector Country Fiche: 20/07/2020}
\color{black}
\begin{center} \section{\Large r toupper(params$ctry_name)
}\end{center}
\color{mygray}
\small
The provision of efficient, sustainable and inclusive housing is crucial for the well-being of citizens. Housing markets affect people’s well-being through a wide range of channels including access to decent shelter, environmental quality, efficient use of scarce resources, type and extent of commuting or its contribution to strong and resilient economic growth. Galloping urbanisation coupled with increasing awareness for negative externalities arising from commuting and urban sprawl have put strain on housing markets and their capacity to deliver affordable housing to all while reducing environmental and health costs for current and future generations. This note provides a cross-country perspective of r params$ctry_name
’s housing-related indicators and policy settings.
\bigskip
\begin{figure}[H] \captionsetup[subfigure]{labelformat=empty} \begin{minipage}[b]{0.45\textwidth} \begin{subfigure}[b]{\linewidth} \color{mygray} \caption{Home Outright Across OECD Countries}
#### Plot the graph : "Homeownership across OECD countries" ranking_struc<- catalogue_struct %>% dplyr::select(variable, rank, variable_name) ranking_struc<-ranking_struc %>% mutate(variable_name=gsub("*","\n",ranking_struc$variable_name, fixed = T)) homeownership_data <- struc_cross %>% select("ISO3_code", "Structural_owners_perc") yvar="Structural_owners_perc" title="Homeownership across OECD countries" data_source=homeownership_data #country="FRA" homeownership_graph <- htk_barplot_func(homeownership_data,yvar,params$ctry_code,title=NULL) homeownership_graph #Get the graph
\end{subfigure} \vspace*{10mm} % vertical whitespace \begin{subfigure}[b]{\linewidth} \bigskip \bigskip \color{mygray} \caption{Mortgage Claims as a Share of GDP (in percent)}
mortgage_data <- struc_cross %>% select("ISO3_code", "Structural_resilience_LMHQ") yvar="Structural_resilience_LMHQ" #title="Mortgage claims as a share of GDP" mortgage_graph <- htk_barplot_func(mortgage_data,yvar,params$ctry_code,title=NULL) mortgage_graph #Get the graph
\end{subfigure} \end{minipage} \begin{minipage}[b]{0.45\textwidth} \begin{subfigure}[b]{\linewidth} \color{mygray} \caption{Real House Price Index (100=2016)}
#title_lineplot="House prices evolution across OECD countries" hp_evol<-cf_lineplot_gen(house_price_data, xvar="period", yvar="ISO3_code", valuevar="rhp", title=NULL, Xlabel = NULL, Ylabel=NULL, country=params$ctry_code) hp_evol
\end{subfigure} \vspace*{10mm} % vertical whitespace \begin{subfigure}[b]{\linewidth} \bigskip \bigskip \color{mygray} \caption{Housing Tenure Distribution (in percent)}
housing_tenure_graph <- cf_stackedbars_func(data_source=house_tenure_data, yvar="Tenure_share", fill="Tenure_cat", country=params$ctry_code, title=NULL) housing_tenure_graph
\end{subfigure} \end{minipage} \end{figure}
\small \color{mygray}
The structure of the housing sector is heterogeneous among countries. Price evolutions, modality of ownership, degree of development of mortage markets and the scope of the rental market profoundly shape the outcomes of the housing market. Panel (a) and (d) display the relative position of `r params$country_code` with respect to homeownership and rental markets, panel (b) shows the real house price dynamics in the long run and panel (c) the importance of the housing sector.
\newpage
\color{ultramarineblue} \begin{center} \section{Main Outcomes} \end{center}
\begin{multicols}{3}
\color{Goldenrod} \begin{center} \section{Efficiency} \end{center}
# select the variables according to the ranking mycategory="efficiency" effic_vars<-catalogue %>% filter(category==mycategory) %>% filter(type=="outcome") ranking_eff<-effic_vars %>% select(variable, rank,direction,variable_name_long, variable_name) ranking_eff<-ranking_eff %>% mutate(variable_name=gsub("*","\n",ranking_eff$variable_name, fixed = T)) var_codes_eff<-c(effic_vars$variable) # only select ALL efficiency variables var_names_eff<-c(ranking_eff$variable_name) # only the efficiency ones var_direction_eff<-c(ranking_eff$direction) # only the efficiency ones dt_effic<-all_vars %>% select(Iso_code3,country_name, var_codes_eff) sec_col_eff=c("goldenrod") fig_eff=htk_CyC(dt_effic, ranking_eff, params$ctry_code,var_codes_eff, sec_col_eff, title="Efficiency Outcomes") fig_eff
\color{mygray}
dt=htk_text_generator(data=dt_effic, category=mycategory, ranking=ranking_eff, ctry=params$ctry_code, var_codes=var_codes_eff) paragraph=dt %>% dplyr::select(mycategory) %>% pull() paragraph=gsub("\n","",paragraph) paragraph=gsub("targetadjective",params$ctry_adj,paragraph)
\footnotesize
#cat(paragraph) edited_par=data_paragraphs %>% filter(Iso_code3==params$ctry_code) %>% dplyr::select(mycategory) %>% pull edited_par=gsub("\n","",edited_par) edited_par=str_replace_all(edited_par,"%","percent") if(length(edited_par)==0 | run_edit_par==F){ cat(paragraph) }else{ cat(edited_par) }
\columnbreak
\color{ProcessBlue} \begin{center} \section{Inclusiveness} \end{center}
\color{mygray}
mycategory="inclusiveness" incl_vars<-catalogue %>% filter(category==mycategory) %>% filter(type=="outcome") ranking_incl<-incl_vars %>% select(variable, rank,direction,variable_name_long, variable_name) ranking_incl<-ranking_incl %>% mutate(variable_name=gsub("*","\n",ranking_incl$variable_name, fixed = T)) var_codes_incl<-c(incl_vars$variable) # only select ALL efficiency variables var_names_incl<-c(ranking_incl$variable_name) # only the efficiency ones dt_incl<-all_vars %>% select(Iso_code3,country_name, var_codes_incl) sec_col=c("deepskyblue") fig_incl=htk_CyC(dt_incl,ranking_incl, params$ctry_code,var_codes_incl,sec_col, title="Inclusiveness Outcomes") fig_incl
dt=htk_text_generator(data=dt_incl, category=mycategory, ranking=ranking_incl, ctry=params$ctry_code, var_codes=var_codes_incl) paragraph=dt %>% dplyr::select(mycategory) %>% pull() paragraph=gsub("\n","",paragraph) paragraph=gsub("targetadjective",params$ctry_adj,paragraph)
#cat(paragraph) edited_par=data_paragraphs %>% filter(Iso_code3==params$ctry_code) %>% dplyr::select(mycategory) %>% pull edited_par=gsub("\n","",edited_par) edited_par=str_replace_all(edited_par,"%","percent") if(length(edited_par)==0 | run_edit_par==F){ cat(paragraph) }else{ cat(edited_par) }
\columnbreak
\color{Green} \begin{center} \section{Sustainability} \end{center} \color{mygray}
mycategory="sustainability" sust_vars<-catalogue %>% filter(category==mycategory) %>% filter(type=="outcome") ranking_sust<-sust_vars %>% select(variable, rank,direction,variable_name_long, variable_name) ranking_sust<-ranking_sust %>% mutate(variable_name=gsub("*","\n",ranking_sust$variable_name, fixed = T)) var_codes_sust<-c(sust_vars$variable) # only select ALL sust variables var_names_sust<-c(ranking_sust$variable_name) # only the efficiency ones dt_sust<-all_vars %>% select(Iso_code3,country_name, var_codes_sust) sec_col=c("darkgreen") fig_sust=htk_CyC(dt_sust,ranking_sust, params$ctry_code,var_codes_sust, sec_col, title="Sustainability Outcomes") fig_sust
dt=htk_text_generator(data=dt_sust, category=mycategory, ranking=ranking_sust, ctry=params$ctry_code, var_codes=var_codes_sust) paragraph=dt %>% dplyr::select(mycategory) %>% pull() paragraph=gsub("\n","",paragraph) paragraph=gsub("targetadjective",params$ctry_adj,paragraph)
edited_par=data_paragraphs %>% filter(Iso_code3==params$ctry_code) %>% dplyr::select(mycategory) %>% pull edited_par=gsub("\n","",edited_par) edited_par=str_replace_all(edited_par,"%","percent") if(length(edited_par)==0 | run_edit_par==F){ cat(paragraph) }else{ cat(edited_par) }
\end{multicols}
\newpage
\begin{tabular}{l l} \parbox[t]{0.35\textwidth}{ \color{ultramarineblue} \begin{center} \section{Policy Profile} \end{center}
\small
\color{mygray}
Housing policies shape the efficiency, inclusiveness and sustainability of the housing sector. The radar below shows the five principal indicators capturing the policy profile for r params$ctry_name
.
Higher values of the land-use governance indicators, which reflect more decentralisation to the municipalities and/or more overlap across government levels, have been empirically linked to housing supply that more vigorously responds to changes in demand. Greater amounts of mortgage interest relief, as well as lower marginal effective tax rates on housing, typically result in higher house prices. More stringent rent control, which reduces the expected profitability of housing investment, is empirically associated with weaker response of housing supply to change in demand. Higher government spending on housing allowances is empirically associated with greater residential mobility that can in turn foster efficiency of the housing sector.
\bigskip
data_polvar<-catalogue %>% filter(type=="policy") ranking_pol<-data_polvar %>% dplyr::select(variable, rank, variable_name) ranking_pol<-ranking_pol %>% mutate(variable_name=gsub("*","\n",ranking_pol$variable_name, fixed = T)) var_codes_pol<-c(data_polvar$variable) # only select ALL policy variables var_names_pol<-c(ranking_pol$variable_name) # only the policy ones dt_pol<-all_vars %>% dplyr::select(Iso_code3,country_name, var_codes_pol) sec_col=c("grey") htk_policyradar(dt_pol,ranking_pol, params$ctry_code,var_codes_pol, title="Policy")
} & \parbox[t]{0.2\textwidth}{ \color{ultramarineblue} \begin{center} \section{Definitions} \end{center}
\color{black}
sel_eff<-fig_eff$data %>% select(main_v) sel_eff<-c(sel_eff$main_v) sel_incl<-fig_incl$data%>% select(main_v) sel_incl<-c(sel_incl$main_v) sel_sust<-fig_sust$data%>% select(main_v) sel_sust<-c(sel_sust$main_v) #sel_v<-rbind(sel_eff, sel_incl, sel_sust) #sel_v<-c(sel_v$main_v) # to have it in order dt_table_eff<- catalogue %>% filter(category=="efficiency") %>% select(variable, variable_name, variable_desc) dt_table_eff<-dt_table_eff[which(dt_table_eff$variable %in% sel_eff), ] dt_table_incl<- catalogue %>% filter(category=="inclusiveness") %>% select(variable, variable_name, variable_desc) dt_table_incl<-dt_table_incl[which(dt_table_incl$variable %in% sel_incl), ] dt_table_sust<- catalogue %>% filter(category=="sustainability") %>% select(variable, variable_name, variable_desc) dt_table_sust<-dt_table_sust[which(dt_table_sust$variable %in% sel_sust), ] dt_table<-rbind(dt_table_eff, dt_table_incl, dt_table_sust) #dt_table$variable dt_table<- dt_table %>% select(variable_name, variable_desc) dt_table<-dt_table %>% mutate(variable_name=str_to_sentence(variable_name)) dt_table<-dt_table %>% mutate(variable_desc=str_to_sentence(variable_desc)) dt_table<-dt_table %>% mutate(variable_name=gsub("*","",dt_table$variable_name, fixed = T)) rownames(dt_table)<-dt_table$variable_name dt_table_fin<-subset(dt_table, select = variable_desc ) colnames(dt_table_fin)<-"description" mytb<-kable(dt_table_fin,format="latex", booktabs = TRUE, col.names = NULL) %>% kable_styling(latex_options = "striped")%>% column_spec(1, width = "6cm")%>% column_spec(2, width = "9cm")%>% kable_styling(position = "left")%>% pack_rows( index = c("Efficiency" = 3, "Inclusiveness" = 3, "Sustainability" = 3), hline_before=T, hline_after=T, latex_align="c") mytb
} \end{tabular}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.