Commit 2758dee5 authored by Thomas Brand's avatar Thomas Brand

Add fig and tab.

parent 55b631e7
......@@ -65,7 +65,7 @@ itrqnew <-
tauwh=last(itrq$tauwh))
itrqupdate <- bind_rows(itrq,itrqnew)
df <- rdb(ids = "OECD/EO/OTO.WPBRENT.Q",api_base_url = "https://api.next.nomics.world/series?")
df <- rdb(ids = "OECD/EO/OTO.WPBRENT.Q")
oil_prices <-
df %>%
select(period, value) %>%
......@@ -79,6 +79,8 @@ networth <-
filter(period<="2018-04-01",
period >= "1995-01-01")
tauls_df <- read_csv("tauls.csv")
FR_data <-
FR_rawdata %>%
transmute(period=period,
......@@ -92,7 +94,6 @@ FR_data <-
networth_rpc=networth$value/defgdp,
re=shortrate$value/100,
creditspread=lendingrate/100-re,
#pubexp_rpc=100*1e+6*(totexp-intpay)/(defgdp*pop),
pubcons_rpc=100*1e+6*pubcons/(defgdp*pop),
pubinves_rpc=100*1e+6*pubinves/(defgdp*pop),
tfs_rpc=100*1e+6*tfs/(defgdp*pop),
......@@ -101,7 +102,8 @@ FR_data <-
gdp_rpc=1e+6*gdp/pop,
world_demand,
oil_prices=oil_prices$value) %>%
left_join(itrqupdate)
left_join(itrqupdate) %>%
left_join(tauls_df)
```
```{r}
......@@ -113,6 +115,7 @@ FR_data2017 <-
write_csv(FR_data2017,"dataFR.csv")
```
```{r}
dataFR <- FR_data
hypo <-
......@@ -171,7 +174,7 @@ for (var in vars){
```
```{r}
vars <- c(quo(pubcons_rpc),quo(tfs_rpc),quo(pubinves_rpc),quo(othgov_rpc))
vars <- c(quo(pubcons_rpc),quo(tfs_rpc),quo(pubinves_rpc),quo(othgov_rpc),quo(tauls))
finaltib1bis <- tibble()
for (var in vars){
......@@ -266,7 +269,7 @@ for (var in vars){
```
```{r}
vars <- c(quo(re))
vars <- c(quo(re),quo(tauc),quo(taun),quo(tauwf),quo(tauwh))
finaltib3 <- tibble()
for (var in vars){
......@@ -361,24 +364,12 @@ for (var in vars){
}
```
```{r}
itrq_forecast <-
tibble(period=seq(as.Date("2018-07-01"),
as.Date("2022-10-01"),
by = "quarter"),
tauc=last(itrq$tauc),
taun=last(itrq$taun),
tauwf=last(itrq$tauwf),
tauwh=last(itrq$tauwh)) %>%
gather(var,value,-period)
```
```{r}
dataFR_forecast <-
dataFR %>%
gather(var,value,-period) %>%
na.omit() %>%
bind_rows(finaltib1,finaltib1bis,finaltib2,finaltib3,finaltib4,itrq_forecast) %>%
bind_rows(finaltib1,finaltib1bis,finaltib2,finaltib3,finaltib4) %>%
spread(var,value) %>%
arrange(period)
......@@ -399,6 +390,5 @@ dataFR_forecast_plot <-
ggplot(dataFR_forecast_plot,aes(period,value))+
geom_line()+
facet_wrap(~var,scales = "free_y")
```
No preview for this file type
period,tauls
1995-04-01,0.265765420905782
1995-07-01,0.280274312578691
1995-10-01,0.292400031325431
1996-01-01,0.290764092847355
1996-04-01,0.289569682955046
1996-07-01,0.288080346434518
1996-10-01,0.290538101867435
1997-01-01,0.287302703301406
1997-04-01,0.291572083099746
1997-07-01,0.289502458768674
1997-10-01,0.298566096832013
1998-01-01,0.300817831289655
1998-04-01,0.302221656225587
1998-07-01,0.299289852442195
1998-10-01,0.303921195137952
1999-01-01,0.293380876214424
1999-04-01,0.281873377923989
1999-07-01,0.269117098469608
1999-10-01,0.264392622985225
2000-01-01,0.293339523594545
2000-04-01,0.293904044258294
2000-07-01,0.28324502778588
2000-10-01,0.249023746423666
2001-01-01,0.348457412725856
2001-04-01,0.285701696759403
2001-07-01,0.24164097775783
2001-10-01,0.309318027191933
2002-01-01,0.260553549342954
2002-04-01,0.273330339027939
2002-07-01,0.268424672639161
2002-10-01,0.215130979472147
2003-01-01,0.20664881036175
2003-04-01,0.138880831788731
2003-07-01,0.225589301623054
2003-10-01,0.255034937999202
2004-01-01,0.230723449438582
2004-04-01,0.230492261830234
2004-07-01,0.243574081198988
2004-10-01,0.231568309220886
2005-01-01,0.244352966567298
2005-04-01,0.275332622223539
2005-07-01,0.251167044950289
2005-10-01,0.198913684134589
2006-01-01,0.360907379483575
2006-04-01,0.319761338230913
2006-07-01,0.254857244552722
2006-10-01,0.340506770181038
2007-01-01,0.240116603392196
2007-04-01,0.264786999205122
2007-07-01,0.270038890880026
2007-10-01,0.346903855660041
2008-01-01,0.276252699389197
2008-04-01,0.261444298954339
2008-07-01,0.234043047235165
2008-10-01,0.151151021812751
2009-01-01,0.118696446248401
2009-04-01,-0.022869621577747
2009-07-01,0.143205584307762
2009-10-01,0.244290181713819
2010-01-01,0.274548856842644
2010-04-01,0.22264541738342
2010-07-01,0.350654426215665
2010-10-01,0.287319167863691
2011-01-01,0.302655933113761
2011-04-01,0.176181230001684
2011-07-01,0.275546768383736
2011-10-01,0.225615454708171
2012-01-01,0.199631865238927
2012-04-01,0.271057145162236
2012-07-01,0.289726615372661
2012-10-01,0.24641934470674
2013-01-01,0.267945631920408
2013-04-01,0.246879058741341
2013-07-01,0.247651044946238
2013-10-01,0.214840558263122
2014-01-01,0.277609582625646
2014-04-01,0.257273158915023
2014-07-01,0.23503093339283
2014-10-01,0.282626384927472
2015-01-01,0.238597568771935
2015-04-01,0.29816051067495
2015-07-01,0.231967437146136
2015-10-01,0.248938689110274
2016-01-01,0.268033254916475
2016-04-01,0.199286373602455
2016-07-01,0.242315540759792
2016-10-01,0.274671192408768
2017-01-01,0.236283588887024
2017-04-01,0.232646001517278
2017-07-01,0.265735610077941
2017-10-01,0.266450569849744
2018-01-01,0.264368847799559
......@@ -42,6 +42,7 @@ data_mean.name = [data_mean.name; 'TAUC_OBS'];
data_mean.name = [data_mean.name; 'TAUN_OBS'];
data_mean.name = [data_mean.name; 'TAUWF_OBS'];
data_mean.name = [data_mean.name; 'TAUWH_OBS'];
data_mean.name = [data_mean.name; 'TAULS'];
data_mean.values = dataFR{'[^(?!.*B_OBS|HOURS_OBS).*$]'}(range).mean(true)';
data_mean.values = [data_mean.values; dataFR{'B_OBS'}(range).mean(false)];
data_mean.values = [data_mean.values; dataFR{'HOURS_OBS'}(range).mean(false)];
......@@ -49,6 +50,7 @@ data_mean.values = [data_mean.values; dataFRlevels{'tauc'}(range).mean(false)];
data_mean.values = [data_mean.values; dataFRlevels{'taun'}(range).mean(false)];
data_mean.values = [data_mean.values; dataFRlevels{'tauwf'}(range).mean(false)];
data_mean.values = [data_mean.values; dataFRlevels{'tauwh'}(range).mean(false)];
data_mean.values = [data_mean.values; dataFRlevels{'tauls'}(range).mean(false)];
save('mean.mat', 'data_mean');
// Center the dataFR (with geometric mean for all variables except B_OBS and HOURS_OBS)
......@@ -61,6 +63,7 @@ dataFR{'TAUC_OBS'} = dataFRlevels{'tauc'};
dataFR{'TAUN_OBS'} = dataFRlevels{'taun'};
dataFR{'TAUWF_OBS'} = dataFRlevels{'tauwf'};
dataFR{'TAUWH_OBS'} = dataFRlevels{'tauwh'};
dataFR{'TAULS'} = dataFRlevels{'tauls'};
// Declare dataFR dseries as the sample for estimation
data(series=dataFR, first_obs=1995Q2, last_obs=2018Q1);
......@@ -35,8 +35,8 @@ end;
estimation(presample=12, lyapunov=doubling, mode_compute=0, mh_replic=0, kalman_algo=2, consider_only_observed,mode_file=mars_mode,plot_priors = 0,nograph);
rawdataset = struct(dataset_);
rawdatatime = struct(rawdataset.dates);
rawdataset = struct(dataFR);
rawdatatime = struct(dataFR.dates);
save rawdataset.mat rawdataset;
save rawdatatime.mat rawdatatime;
......@@ -45,24 +45,26 @@ dataForecast = dataFR(2018Q2:2022Q4);
//constrained_vars = {'CONSUMPTION_OBS'; 'B_OBS'; 'INFLATION_OBS'; 'GDP_OBS'; 'INVESTMENT_OBS'; 'POIL_OBS'; ...
// 'OTHGOV_OBS'; 'PINVEST_OBS'; 'GC_OBS'; 'GI_OBS'; 'RE_OBS'; 'TAUC_OBS'; 'TAUN_OBS'; 'TAUWF_OBS'; 'TAUWH_OBS'; 'T_OBS'; 'WAGE_OBS'; 'YWORLD_OBS'};
constrained_vars = {'TAUC_OBS'; 'TAUN_OBS'; 'TAUWF_OBS'; 'TAUWH_OBS'; 'YWORLD_OBS'; 'POIL_OBS'; 'RE_OBS'};
constrained_vars = {'OTHGOV_OBS'; 'GC_OBS'; 'GI_OBS'; 'T_OBS'; 'TAULS'; 'TAUC_OBS'; 'TAUN_OBS'; 'TAUWF_OBS'; 'TAUWH_OBS'; 'YWORLD_OBS'; 'POIL_OBS'; 'RE_OBS'};
//constrained_vars = {'TAUC_OBS'; 'TAUN_OBS'; 'TAUWF_OBS'; 'TAUWH_OBS'; 'YWORLD_OBS'; 'POIL_OBS'; 'RE_OBS'};
[~, constrained_vars_id] = ismember(constrained_vars, M_.endo_names);
dataForecast = dataForecast{constrained_vars{:}};
//conditional_forecast.controlled_varexo = {'OTHGOV_EXO'; 'T_EXO'; 'GC_EXO'; 'GI_EXO'; 'TAULS_EXO'; 'TAUC_EXO'; 'TAUN_EXO'; 'TAUWF_EXO'; 'TAUWH_EXO'; 'YW_EXO'; 'POIL_EXO'; 'R_EXO'};
verbatim;
conditional_forecast.replic = 20000;
conditional_forecast.replic = 10000;
conditional_forecast.parameter_set = 'posterior_mode';
conditional_forecast.conf_sig = .9;
conditional_forecast.controlled_varexo = {'TAUC_EXO'; 'TAUN_EXO'; 'TAUWF_EXO'; 'TAUWH_EXO'; 'YW_EXO'; 'POIL_EXO'; 'R_EXO'};
conditional_forecast.conf_sig = .6;
conditional_forecast.controlled_varexo = {'OTHGOV_EXO'; 'T_EXO'; 'GC_EXO'; 'GI_EXO'; 'TAULS_EXO'; 'TAUC_EXO'; 'TAUN_EXO'; 'TAUWF_EXO'; 'TAUWH_EXO'; 'YW_EXO'; 'POIL_EXO'; 'R_EXO'};
options_.conditional_forecast = conditional_forecast;
end;
imcforecast(dataForecast.data', constrained_vars_id, conditional_forecast);
plot_icforecast(constrained_vars, 40, options_);
%plot_icforecast(constrained_vars, 40, options_);
plot_icforecast({'GDP_OBS'}, 40, options_);
......
if (!"pacman" %in% installed.packages()[,"Package"])
install.packages("pacman", repos='http://cran.r-project.org')
pacman::p_load(R.matlab,tidyverse,magrittr,zoo,stringr,lubridate)
rm(list = ls())
mean <- readMat('../../mod/conditional-forecast/mean.mat',fixNames = F)
data_mean_name <- unlist(mean$data_mean[[1]]) %>%
str_trim()
data_mean_values <- unlist(mean$data_mean[[2]]) %>%
str_trim()
data_mean <-
data.frame(varobs=data_mean_name,
mean=Re(as.complex(data_mean_values)),
stringsAsFactors=F) %>%
mutate(mean=as.numeric(mean))
results <- readMat("../../mod/conditional-forecast/mars_results.mat",fixNames = F)
M_ <- results[["M_"]]
varendo_code <- unlist(subset(M_,row.names(M_)=="endo_names")) %>%
str_trim()
varendo_name <- unlist(subset(M_,row.names(M_)=="endo_names_long")) %>%
str_trim()
varendo_tex <- unlist(subset(M_, row.names(M_)=="endo_names_tex")) %>%
str_trim()
varendo_measure <-
subset(M_,row.names(M_)=="endo_partitions") %>%
first() %>% first() %>% as.matrix() %>%
apply(1,function(x) unlist(x)) %>%
as.matrix() %>% as.data.frame() %>%
mutate(
V1=as.character(V1),
V1=ifelse(nchar(V1)==12,NA,V1)) %>% # If nchar == 12 (<=> empty) then put NA, otherwise keep thewhich(sapply(priorPost, function(x) all(is.na(x))))
unlist() %>% str_trim()
varendo <- data.frame(code=varendo_code,
name=varendo_name,
measure=varendo_measure,
tex = str_c("$",varendo_tex,"$"),
stringsAsFactors = F)
rawdatatime <- readMat("../../mod/conditional-forecast/rawdatatime.mat",fixNames = F)
rawtime <-
as.data.frame(rawdatatime[[1]][[2]]) %>%
unite(time,c(V1,V2),sep="Q")
time <- as.character(as.Date(as.yearqtr(rawtime$time)))
rawdataset <- readMat("../../mod/conditional-forecast/rawdataset.mat",fixNames = F)
rawdat <- as.data.frame(rawdataset[[1]][[1]])
varobs <- unlist(rawdataset[[1]][[2]])
colnames(rawdat) <- varobs
rawdat <- data.frame(time=time,rawdat)
rawdat %<>%
gather(varobs,values,-time)
rawdat %<>%
merge(rename(varendo,varobs=code),
by="varobs") %>%
rename(varobs_name=name) %>%
select(-tex)
rawdat %<>%
left_join(data_mean, by="varobs")
dataRaw <- rawdat
fore <- readMat("../../mod/conditional-forecast/conditional_forecasts.mat")
decile <- c('dec_inf','dec_sup')
fore_cond <- fore[[1]][[3]]
fore_cond_mean <- fore_cond[[1]]
fore_cond_dec <- fore_cond[[2]]
fore_names <- row.names(fore_cond_mean) %>% str_replace(".OBS","_OBS")
fore_cond_mean_df <- data.frame()
for (i in 1:length(fore_names)){
df <- data.frame(var=fore_names[i],
type="mean",
t(unlist(fore_cond_mean[i])))
fore_cond_mean_df <- rbind(fore_cond_mean_df,df)
}
fore_cond_dec_df <- data.frame()
for (i in 1:length(fore_names)){
df <- data.frame(var=fore_names[i],
type=decile,
fore_cond_dec[i])
fore_cond_dec_df <- rbind(fore_cond_dec_df,df)
}
fore_cond <- rbind(fore_cond_dec_df,fore_cond_mean_df)
Timefore <- seq.Date(from = as.Date("2018-01-01"),
by = 'quarter',
length.out = ncol(fore_cond_mean_df)-2)
colnames(fore_cond) <- c("var","type",as.character(Timefore))
fore_cond %<>%
gather(time,values,-var,-type)
fore_cond %<>%
merge(rename(varendo,var=code),
by="var") %>%
rename(varobs_name=name,
varobs = var) %>%
select(-tex)
fore_cond %<>%
left_join(data_mean, by="varobs")
dataFore <- fore_cond
# gdp_raw <-
# dataRaw %>%
# mutate(time=as.Date(time)) %>%
# filter(varobs=="GDP_OBS",
# time<="2018-01-01") %>%
# select(time,values) %>%
# mutate(type="historical")
# gdp_plf <-
# dataRaw %>%
# mutate(time=as.Date(time)) %>%
# filter(varobs=="GDP_OBS",
# time>"2018-01-01") %>%
# select(time,values) %>%
# mutate(type="PLF")
# gdp_fore <-
# dataFore %>%
# mutate(time=as.Date(time)) %>%
# filter(varobs=="GDP_OBS",
# year(time)<2023) %>%
# select(time,values,type)
# gdp_df <- bind_rows(gdp_raw,gdp_plf,gdp_fore) %>% arrange(time) %>% spread(type,values) %>% select(-historical) %>% na.omit()
# text_size=11
# str(gdp_df)
# ggplot(data=gdp_df)+
# #geom_line(aes(time,historical),size=0.73,colour="blue")+
# geom_line(aes(time,mean),size=0.73,colour="red")+
# geom_ribbon(aes(x=time,ymin=dec_inf,ymax=dec_sup),alpha=0.6,fill="#D6E3F3") +
# geom_line(aes(time,PLF),size=0.73,colour="green")+
# scale_x_date(expand=c(0.01,0.01))+
# #facet_wrap(~varobs,ncol=4,scales="free_y")+
# xlab(NULL) + ylab(NULL)+theme_bw()+
# theme(strip.background=element_blank(),
# strip.text=element_text(size=text_size),
# plot.title = element_text(hjust = 0.5,size=20),
# plot.subtitle = element_text(hjust = 0.5,size=12),
# legend.key=element_rect(colour="white"),
# legend.position="bottom",
# legend.title=element_blank(),
# legend.text=element_text(size=text_size),
# axis.text=element_text(size=text_size)) +
# ggtitle("The Forecast of GDP")
dataRawSpread <-
dataRaw %>%
spread(varobs_name,values)
tax_vec <-
dataRawSpread %>%
select(starts_with("Contribution rate"),
starts_with("Tax rate")) %>%
colnames()
public_debt_vec <-
dataRawSpread %>%
select(starts_with("Public debt")) %>%
colnames()
hours_vec <-
dataRawSpread %>%
select(contains("Hours")) %>%
colnames()
dataForeGov <-
dataRaw %>%
mutate(type="ForeGov",
time=as.character(time)) %>%
filter(time >= "2017-01-01")
dataRaw %<>%
mutate(type="mean",
time=as.character(time)) %>%
filter(time <= "2017-10-01")
deciles <- unique(dataFore$type)
deciles <- deciles[!deciles=="mean"]
dataRawPrec <-
dataRaw %>%
filter(time %in% c("2017-01-01","2017-04-01","2017-07-01","2017-10-01"))
for (dec in deciles){
df <-
dataRawPrec %>%
mutate(type=dec)
dataRaw <- rbind(dataRaw,df)
}
dataForecastAnnual <-
bind_rows(dataRaw,dataForeGov,dataFore) %>%
filter(varobs %in% c("GDP_OBS","CONSUMPTION_OBS","INVESTMENT_OBS")) %>%
filter(type %in% c("mean","ForeGov")) %>%
mutate(values=values*mean) %>%
arrange(varobs,time) %>%
select(-mean,-measure)
dataForecastAnnual_mean <-
dataForecastAnnual %>%
filter(type=="mean") %>%
mutate(values=
case_when(varobs=="GDP_OBS" & time=="1995-01-01"~ 10021.7942682663,
varobs=="CONSUMPTION_OBS" & time=="1995-01-01"~ 5296.00126982036,
varobs=="INVESTMENT_OBS" & time=="1995-01-01"~ 2086.57511416591,
TRUE ~ values)) %>%
group_by(varobs) %>%
mutate(values=cumprod(values)) %>%
ungroup()
dataForecastAnnualForeGov2016Q4 <-
dataForecastAnnual_mean %>%
filter(time=="2016-10-01") %>%
mutate(type="ForeGov")
dataForecastAnnual_ForeGov <-
dataForecastAnnual %>%
filter(type=="ForeGov") %>%
bind_rows(dataForecastAnnualForeGov2016Q4) %>%
arrange(varobs,time) %>%
group_by(varobs) %>%
mutate(values=cumprod(values))
dataForecastAnnual2 <-
bind_rows(dataForecastAnnual_mean,dataForecastAnnual_ForeGov) %>%
mutate(year=year(time),
quarter=quarter(time)) %>%
group_by(varobs_name,varobs,type,year) %>%
summarise(values=sum(values)) %>%
filter(!(year==2016 & type=="ForeGov")) %>%
mutate(year=as.Date(paste0(year,"-01-01")),
values=values/lag(values)-1) %>%
na.omit() %>%
ungroup()
dataForecastAnnual2_2017 <-
dataForecastAnnual2 %>%
filter(type=="mean" & year=="2017-01-01") %>%
mutate(type="ForeGov")
gdpq <-
dataForecastAnnual_mean %>%
filter(varobs=="GDP_OBS") %>%
arrange(type,time)
volumedebt <-
bind_rows(dataRaw,dataFore) %>%
filter(type == "mean",
varobs=="B_OBS") %>%
mutate(values=(values+2.2)) %>%
select(-measure,-mean) %>%
bind_rows(gdpq) %>%
select(-varobs_name) %>%
spread(varobs,values) %>%
transmute(values=B_OBS*GDP_OBS,
varobs="volumedebt",
time,
type) %>%
filter(quarter(time)==4) %>%
mutate(year=as.Date(paste0(year(time),"-01-01"))) %>%
select(-time) %>%
arrange(type,year)
gdpy <-
gdpq %>%
mutate(year=year(time),
quarter=quarter(time)) %>%
group_by(varobs_name,varobs,type,year) %>%
summarise(values=sum(values)) %>%
mutate(year=as.Date(paste0(year,"-01-01"))) %>%
na.omit() %>%
ungroup() %>%
arrange(type,year) %>%
select(-varobs_name)
debt <-
volumedebt %>%
bind_rows(gdpy) %>%
filter(year(year)<2023) %>%
spread(varobs,values) %>%
mutate(values=volumedebt/GDP_OBS) %>%
select(-GDP_OBS,-volumedebt) %>%
mutate(varobs_name="Public debt",
varobs="B_OBS")
debt2017 <-
debt %>%
filter(year=="2017-01-01") %>%
mutate(type="ForeGov")
dataForeGovAnnual_debt <-
dataForeGov %>%
filter(type == "ForeGov",
varobs=="B_OBS") %>%
mutate(values=(values+2.2)/4) %>%
arrange(time) %>%
select(-mean,-measure) %>%
filter(quarter(time)==4) %>%
mutate(year=as.Date(paste0(year(time),"-01-01"))) %>%
select(-time) %>%
filter(year(year)!=2017) %>%
bind_rows(debt2017)
pop <-
rdb("Eurostat","demo_pjanbroad",mask = "A.NR.Y15-64.T.FR") %>%
select(period,value) %>%
transmute(pop=value/lag(value)-1,
year=period) %>%
bind_rows(data.frame(year=as.Date(c("2018-01-01","2019-01-01","2020-01-01","2021-01-01","2022-01-01")),
pop=c(-0.0011,-0.0013,0.0004,0.0003,0.0002)))
dataForecastAnnual2_popreflated <-
bind_rows(dataForecastAnnual2,dataForecastAnnual2_2017) %>%
left_join(pop) %>%
mutate(values=values+pop) %>%
select(-pop)
dataForecastAnnual3 <-
bind_rows(dataForecastAnnual2_popreflated,debt,dataForeGovAnnual_debt) %>%
filter(year(year)<2023,
year(year)>1995) %>%
mutate(varobs_name=factor(varobs_name),
type=as.factor(type))
levels(dataForecastAnnual3$varobs_name) <- c("Dette publique (% du PIB)",
"Consommation privée (volume, %)",
"PIB (volume, %)",
"Investissement des entreprises (volume, %)")
levels(dataForecastAnnual3$type) <- c("Gouvernement","Cepremap")
text_size<-11
ggplot(data=dataForecastAnnual3,aes(x=year,y=values,colour=type))+
geom_line(size=0.75)+
geom_line(data=subset(dataForecastAnnual3,year<="2017-01-01"),size=0.8,colour="#1F77B4")+
scale_x_date(expand=c(0.01,0.01))+
facet_wrap(~varobs_name,ncol=2,scales="free_y")+
xlab(NULL) + ylab(NULL)+theme_bw()+
theme(strip.background=element_blank(),
strip.text=element_text(size=text_size),
plot.title = element_text(hjust = 0.5,size=17),
plot.subtitle = element_text(hjust = 0.5,size=12),
legend.key=element_rect(colour="white"),
#legend.position="bottom",
legend.title=element_blank(),
legend.text=element_text(size=text_size),
axis.text=element_text(size=text_size)) +
ggtitle("Prévisions Cepremap en imposant uniquement les contraintes extérieures",subtitle = "(pétrole, demande mondiale, taux d'intérêt : hypothèses PLF + PLPFP)")
ggsave("prev_tax_exp_constant.pdf")
dataForecast <-
rbind(dataRaw,dataForeGov,dataFore) %>%
#rbind(totoRaw,totoFore) %>%
select(-varobs) %>%
rename(varobs=varobs_name) %>%
arrange(varobs, time) %>%
group_by(varobs, type) %>%
mutate(values=
case_when(measure=="%" ~ (values)*(lag(values))*(lag(values,2))*(lag(values,3))-1,
measure %in% c("% APR","% APP") ~ (values)^4-1,
varobs %in% public_debt_vec ~ values/4,
TRUE ~ values)) %>%
mutate(values=
case_when(measure %in% c("%","% APP", "% APR") ~ ((1+values)*mean^4-1)*100,
varobs %in% public_debt_vec ~ (values+0.55)*100,
varobs %in% tax_vec ~ (values)*100,
varobs %in% hours_vec ~ (values)*mean,
TRUE ~ values)) %>%
na.omit() %>%
ungroup() %>%
select(-mean) %>%
spread(type,values)
text_size <- 10
dataForecast$time <- as.Date(dataForecast$time)
dataForecast %<>%
filter(year(time)>=2000,
year(time)<=2022)
dataForecast %<>% filter(varobs!="Real net worth per capita")
# write_csv(dataForecast,"gdp.csv")
ggplot(data=dataForecast,aes(x=time,y=mean))+
geom_ribbon(aes(ymin=dec_inf,ymax=dec_sup),alpha=0.6,fill="#D6E3F3") +
geom_line(data=subset(dataForecast,time>="2018-01-01"),size=0.73,colour="red")+
geom_line(data=subset(dataForecast,time<="2018-01-01"),size=0.8,colour="#1F77B4")+
geom_line(aes(x=time,y=ForeGov),colour="green")+
scale_x_date(expand=c(0.01,0.01))+
facet_wrap(~varobs,ncol=3,scales="free_y")+
xlab(NULL) + ylab(NULL)+theme_bw()+
theme(strip.background=element_blank(),
strip.text=element_text(size=text_size),
plot.title = element_text(hjust = 0.5,size=20),
plot.subtitle = element_text(hjust = 0.5,size=12),
legend.key=element_rect(colour="white"),
legend.position="bottom",
legend.title=element_blank(),
legend.text=element_text(size=text_size),
axis.text=element_text(size=text_size)) +
ggtitle("The Forecast of Observed Variables",
subtitle="Year-on-year growth rates / Annualized percentage points and rates / Percent of annual GDP for debt")
ggsave("forecast.pdf")
# subDataForecast <-
# dataForecast %>%
# filter(varobs %in% c("Real GDP per capita","Public debt","Real consumption per capita","Real investment per capita"))
#
# ggplot(data=subDataForecast,aes(x=time,y=mean))+
# geom_ribbon(aes(ymin=dec_inf,ymax=dec_sup),alpha=0.6,fill="#D6E3F3") +
# geom_line(data=subset(subDataForecast,time>="2018-01-01"),size=0.73,colour="red")+
# geom_line(data=subset(subDataForecast,time<="2018-01-01"),size=0.8,colour="#1F77B4")+
# geom_line(aes(x=time,y=ForeGov),colour="slateblue",size=0.73)+
# scale_x_date(expand=c(0.01,0.01))+
# facet_wrap(~varobs,ncol=2,scales="free_y")+
# xlab(NULL) + ylab(NULL)+theme_bw()+
# theme(strip.background=element_blank(),
# strip.text=element_text(size=text_size),
# plot.title = element_text(hjust = 0.5,size=20),
# #plot.subtitle = element_text(hjust = 0.5,size=12),
# #legend.key=element_rect(colour="white"),
# #legend.position="bottom",
# #legend.title=element_blank(),
# #legend.text=element_text(size=text_size),
# axis.text=element_text(size=text_size)) +
# ggtitle("Forecast")
#
# ggsave("forecast_lpfp.pdf")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment