# Wichgers, Jacobs & Van Spanje 2020 # Input Output TRIAL 1 ############# Create a time series (ts) object from the InputOutput data (for each variable you're using) attach(OutputInput_agg_finalV2) ### Output ##V21 Output (Anti-discrimination) V21O_TS <- ts(V21_O, start=c(2009,1), end=c(2018,365), frequency=365) V21O_TS1 <- window(V21O_TS, start=c(2009, 21), end=c(2011, 181)) plot(V21O_TS1) ##V24 Output (Free speech) V24O_TS <- ts(V24_O, start=c(2009,1), end=c(2018,365), frequency=365) V24O_TS1 <- window(V24O_TS, start=c(2009, 21), end=c(2011, 181)) plot(V24O_TS1) ##V27 Output (Political trial) V27O_TS <- ts(V27_O, start=c(2009,1), end=c(2018,365), frequency=365) V27O_TS1 <- window(V27O_TS, start=c(2009, 21), end=c(2011, 181)) plot(V27O_TS1) ##V30 Output (Unfair trial) V30O_TS <- ts(V30_O, start=c(2009,1), end=c(2018,365), frequency=365) V30O_TS1 <- window(V30O_TS, start=c(2009, 21), end=c(2011, 181)) plot(V30O_TS1) ##V33 Output (Above the law) V33O_TS <- ts(Abovelaw_O, start=c(2009,1), end=c(2018,365), frequency=365) V33O_TS1 <- window(V33O_TS, start=c(2009, 21), end=c(2011, 181)) plot(V33O_TS1) ##V36 Output (Societal Debate) V36O_TS <- ts(Debate_O, start=c(2009,1), end=c(2018,365), frequency=365) V36O_TS1 <- window(V36O_TS, start=c(2009, 21), end=c(2011, 181)) plot(V36O_TS1) ##V39 Output (Benefit) V39O_TS <- ts(Benefit_O, start=c(2009,1), end=c(2018,365), frequency=365) V39O_TS1 <- window(V39O_TS, start=c(2009, 21), end=c(2011, 181)) plot(V39O_TS1) ## All frames together Output FrameO_TS <- ts(Frame_O, start=c(2009,1), end=c(2018,365), frequency=365) FrameO_TS1 <- window(FrameO_TS, start=c(2009, 21), end=c(2011, 181)) plot(FrameO_TS1) ## Elections Elections_TS <- ts(Elections, start=c(2009,1), end=c(2018,365), frequency=365) Elections_TS1 <- window(Elections_TS, start=c(2009, 21), end=c(2011, 181)) plot(Elections_TS1) ## Objection Objection_TS <- ts(Objection, start=c(2009,1), end=c(2018,365), frequency=365) Objection_TS1 <- window(Objection_TS, start=c(2009, 21), end=c(2011, 181)) plot(Objection_TS1) ## Acquittal Acquittal_TS <- ts(Acquittal, start=c(2009,1), end=c(2018,365), frequency=365) Acquittal_TS1 <- window(Acquittal_TS, start=c(2009, 21), end=c(2011, 181)) plot(Elections_TS1) ### Input ##V21 Input (Anti-discrimination) V21I_TS <- ts(V21_I, start=c(2009,1), end=c(2018,365), frequency=365) V21I_TS1 <- window(V21I_TS, start=c(2009, 21), end=c(2011, 181)) plot(V21I_TS1) ##V24 Input (Free speech) V24I_TS <- ts(V24_I, start=c(2009,1), end=c(2018,365), frequency=365) V24I_TS1 <- window(V24I_TS, start=c(2009, 21), end=c(2011, 181)) plot(V24I_TS1) ##V27 Input (Political trial) V27I_TS <- ts(V27_I, start=c(2009,1), end=c(2018,365), frequency=365) V27I_TS1 <- window(V27I_TS, start=c(2009, 21), end=c(2011, 181)) plot(V27I_TS1) ##V30 Input (Unfair trial) V30I_TS <- ts(V30_I, start=c(2009,1), end=c(2018,365), frequency=365) V30I_TS1 <- window(V30I_TS, start=c(2009, 21), end=c(2011, 181)) plot(V30I_TS1) ##V33 Input (Above the law) V33I_TS <- ts(Abovelaw_I, start=c(2009,1), end=c(2018,365), frequency=365) V33I_TS1 <- window(V33I_TS, start=c(2009, 21), end=c(2011, 181)) plot(V33I_TS1) ##V36 Input (Debate) V36I_TS <- ts(Debate_I, start=c(2009,1), end=c(2018,365), frequency=365) V36I_TS1 <- window(V36I_TS, start=c(2009, 21), end=c(2011, 181)) plot(V36I_TS1) ##V39 Input (Benefit) V39I_TS <- ts(Benefit_I, start=c(2009,1), end=c(2018,365), frequency=365) V39I_TS1 <- window(V39I_TS, start=c(2009, 21), end=c(2011, 181)) plot(V39I_TS1) ## All frames together Input FrameI_TS <- ts(Frame_I, start=c(2009,1), end=c(2018,365), frequency=365) FrameI_TS1 <- window(FrameI_TS, start=c(2009, 21), end=c(2011, 181)) plot(FrameI_TS1) ## Input (Anti-discrimination - victim) V21_6supI_TS <- ts(V22_6sup_I, start=c(2009,1), end=c(2018,365), frequency=365) V21_6supI_TS1 <- window(V21_6supI_TS, start=c(2009, 21), end=c(2011, 181)) plot(V21_6supI_TS1) ## Input (Free speech - defendant) V24_45supI_TS <- ts(V25_45sup_I, start=c(2009,1), end=c(2018,365), frequency=365) V24_45supI_TS1 <- window(V24_45supI_TS, start=c(2009, 21), end=c(2011, 181)) plot(V24_45supI_TS1) ## Input (Free speech - victims) V24_6oppI_TS <- ts(V25_6opp_I, start=c(2009,1), end=c(2018,365), frequency=365) V24_6oppI_TS1 <- window(V24_6oppI_TS, start=c(2009, 21), end=c(2011, 181)) plot(V24_6oppI_TS1) ## Input (Political trial - defendant) V27_45supI_TS <- ts(V28_45sup_I, start=c(2009,1), end=c(2018,365), frequency=365) V27_45supI_TS1 <- window(V27_45supI_TS, start=c(2009, 21), end=c(2011, 181)) plot(V27_45supI_TS1) ## Input (Unfair trial - defendant) V30_45supI_TS <- ts(V31_45sup_I, start=c(2009,1), end=c(2018,365), frequency=365) V30_45supI_TS1 <- window(V30_45supI_TS, start=c(2009, 21), end=c(2011, 181)) plot(V30_45supI_TS1) ########### Var analysis # no exogenous variables included, only endogeneous variables (frame coverage input, frame coverage output) # each variable is taken both as IV and Dv library(vars) ### Step 1: test for stationarity. # See the above. All variables are stationary ### Step 2: determine how many lags should be included in the variables (equal for each endogenous variable included) ### Estimate best lag (lag. max = 1 week, 7 days) # Frame sum regressors <- cbind(FrameI_TS1, FrameO_TS1) control <- cbind(Elections_TS1, Objection_TS1, Acquittal_TS1) VARselect(regressors, lag.max = 7, exogen = control) ### Anti-discrimination # Anti-discrimination sum regressors <- cbind(V21I_TS1, V21O_TS1) control <- cbind(Elections_TS1, Objection_TS1, Acquittal_TS1) VARselect(regressors,lag.max = 7, exogen = control) # Anti-discrimination victims regressors <- cbind(V21_6supI_TS1, V21O_TS1) control <- cbind(Elections_TS1, Objection_TS1, Acquittal_TS1) VARselect(regressors,lag.max = 7, exogen = control) ### Free speech # Free speech sum regressors <- cbind(V24I_TS1, V24O_TS1) control <- cbind(Elections_TS1, Objection_TS1, Acquittal_TS1) VARselect(regressors, lag.max = 7, exogen = control) # Free speech defendant regressors <- cbind(V24_45supI_TS1, V24O_TS1) control <- cbind(Elections_TS1, Objection_TS1, Acquittal_TS1) VARselect(regressors, lag.max = 7, exogen = control) ### Political trial # Political trial sum regressors <- cbind(V27I_TS1, V27O_TS1) control <- cbind(Elections_TS1, Objection_TS1, Acquittal_TS1) VARselect(regressors, lag.max = 7, exogen = control) # Political trial defendant regressors <- cbind(V27_45supI_TS1, V27O_TS1) control <- cbind(Elections_TS1, Objection_TS1, Acquittal_TS1) VARselect(regressors, lag.max = 7, exogen = control) ### Unfair trial # Unfair trial sum regressors <- cbind(V30I_TS1, V30O_TS1) control <- cbind(Elections_TS1, Objection_TS1, Acquittal_TS1) VARselect(regressors, lag.max = 7, exogen = control) # Unfair trial defendant regressors <- cbind(V30_45supI_TS1, V30O_TS1) control <- cbind(Elections_TS1, Objection_TS1, Acquittal_TS1) VARselect(regressors, lag.max = 7, exogen = control) ### Estimate VAR moddels ########### Estimate best lag (lag. max = 1 week, 7 days) ##### Frame sum regressors <- cbind(FrameO_TS1, FrameI_TS1) control <- cbind(Elections_TS1, Objection_TS1, Acquittal_TS1) VAR <- VAR(regressors, p=7, exogen = control) serial.test(VAR, lags.pt = 7, type="PT.asymptotic") ### Anti-discrimination # Anti-discrimination sum regressors <- cbind(V21I_TS1, V21O_TS1) control <- cbind(Elections_TS1, Objection_TS1, Acquittal_TS1) VAR <- VAR(regressors, p=7, exogen = control) serial.test(VAR, lags.pt = 7, type="PT.asymptotic") # Anti-discrimination victim regressors <- cbind(V21_6supI_TS1, V21O_TS1) control <- cbind(Elections_TS1, Objection_TS1, Acquittal_TS1) VAR <- VAR(regressors, p=7, exogen = control) serial.test(VAR, lags.pt = 7, type="PT.asymptotic") #### Free speech # Total free speech sum regressors <- cbind(V24I_TS1, V24O_TS1) control <- cbind(Elections_TS1, Objection_TS1, Acquittal_TS1) VAR <- VAR(regressors, p=1, exogen = control) serial.test(VAR, lags.pt = 7, type="PT.asymptotic") # Free speech defendant regressors <- cbind(V24_45supI_TS1, V24O_TS1) control <- cbind(Elections_TS1, Objection_TS1, Acquittal_TS1) VAR <- VAR(regressors, p=2, exogen = control) serial.test(VAR, lags.pt = 7, type="PT.asymptotic") ### Political trial # political trial sum regressors <- cbind(V27I_TS1, V27O_TS1) control <- cbind(Elections_TS1, Objection_TS1, Acquittal_TS1) VAR <- VAR(regressors, p=5, exogen = control) serial.test(VAR, lags.pt =7, type="PT.asymptotic") # Political trial defendant regressors <- cbind(V27_45supI_TS1, V27O_TS1) control <- cbind(Elections_TS1, Objection_TS1, Acquittal_TS1) VAR <- VAR(regressors, p=2, exogen = control) serial.test(VAR, lags.pt = 7, type="PT.asymptotic") ### Unfair trial # unfair trial sum regressors <- cbind(V30I_TS1, V30O_TS1) control <- cbind(Elections_TS1, Objection_TS1, Acquittal_TS1) VAR <- VAR(regressors, p=5, exogen = control) serial.test(VAR, lags.pt = 7, type="PT.asymptotic") # Unfair trial defendant regressors <- cbind(V30_45supI_TS1, V30O_TS1) control <- cbind(Elections_TS1, Objection_TS1, Acquittal_TS1) VAR <- VAR(regressors, p=5, exogen = control) serial.test(VAR, lags.pt = 7) ############ Granger causality test ###### Anti-discrimination ## Anti-discrimination sum # Combine the two variables you want to test regressors <- cbind(V21O_TS1, V21I_TS1) control <- cbind(Elections_TS1, Objection_TS1, Acquittal_TS1) # Fit a VAR model (lag 7) VAR <- VAR(regressors, p=7, type="const", exogen = control) summary(VAR) AIC(VAR) BIC(VAR) # H0: Input does not cause output, then causality(VAR, cause = "V21I_TS1")$Granger #H0: Output does not cause input, then causality(VAR, cause = "V21O_TS1")$Granger # Plot the IRF irf(VAR, n.ahead = 7, ortho = TRUE, cumulative = TRUE, boot = TRUE, ci = 0.95,runs = 100, seed = NULL) plot(irf(VAR, ahead=7)) # Forecast error fevd(VAR, n.ahead = 7) ## Victims # Combine the two variables you want to test regressors <- cbind(V21_6supI_TS1, V21O_TS1) control <- cbind(Elections_TS1, Objection_TS1, Acquittal_TS1) # Fit a VAR model (lag 7) VAR <- VAR(regressors, p=7, type="const", exogen = control) summary(VAR) AIC(VAR) BIC(VAR) # H0: Input does not cause output, then causality(VAR, cause = "V21_6supI_TS1")$Granger #H0: Output does not cause input, then causality(VAR, cause = "V21O_TS1")$Granger # Plot the IRF irf(VAR, n.ahead = 7, ortho = TRUE, cumulative = TRUE, boot = TRUE, ci = 0.95,runs = 100, seed = NULL) plot(irf(VAR, ahead=7)) # Forecast error fevd(VAR, n.ahead = 7) ######## Free speech ## Frame sum # Combine the two variables you want to test regressors <- cbind(V24I_TS1, V24O_TS1) control <- cbind(Elections_TS1, Objection_TS1, Acquittal_TS1) # Fit a VAR model (lag 1) VAR <- VAR(regressors, p=1, type="const", exogen = control) summary(VAR) AIC(VAR) BIC(VAR) # H0: Input does not cause output, then causality(VAR, cause = "V24I_TS1")$Granger #H0: Output does not cause input, then causality(VAR, cause = "V24O_TS1")$Granger # Plot the IRF irf(VAR, n.ahead = 7, ortho = TRUE, cumulative = TRUE, boot = TRUE, ci = 0.95,runs = 100, seed = NULL) plot(irf(VAR, ahead=7)) # Forecast error fevd(VAR, n.ahead = 7) ## Defendant # Combine the two variables you want to test regressors <- cbind(V24_45supI_TS1, V24O_TS1) control <- cbind(Elections_TS1, Objection_TS1, Acquittal_TS1) # Fit a VAR model (lag 2) VAR <- VAR(regressors, p=2, type="const", exogen = control) summary(VAR) AIC(VAR) BIC(VAR) # H0: Input does not cause output, then causality(VAR, cause = "V24_45supI_TS1")$Granger #H0: Output does not cause input, then causality(VAR, cause = "V24O_TS1")$Granger # Plot the IRF irf(VAR, n.ahead = 7, ortho = TRUE, cumulative = TRUE, boot = TRUE, ci = 0.95,runs = 100, seed = NULL) plot(irf(VAR, ahead=7)) # Forecast error fevd(VAR, n.ahead = 7) ## Victims # Combine the two variables you want to test regressors <- cbind(V24_6oppI_TS1, V24O_TS1) control <- cbind(Elections_TS1, Objection_TS1, Acquittal_TS1) regressors <- cbind(V24O_TS1, V24_6oppI_TS1) control <- cbind(Elections_TS1, Objection_TS1, Acquittal_TS1) # Fit a VAR model (lag 1) VAR <- VAR(regressors, p=1, type="const", exogen = control) summary(VAR) AIC(VAR) BIC(VAR) # H0: Input does not cause output, then causality(VAR, cause = "V24_6oppI_TS1")$Granger #H0: Output does not cause input, then causality(VAR, cause = "V24O_TS1")$Granger # Plot the IRF irf(VAR, n.ahead = 7, ortho = TRUE, cumulative = TRUE, boot = TRUE, ci = 0.95,runs = 100, seed = NULL) plot(irf(VAR, ahead=7)) # Forecast error fevd(VAR, n.ahead = 7) ### Political trial ## Frame sum # Combine the two variables you want to test (make sure that they are stationary) regressors <- cbind(V27I_TS1, V27O_TS1) control <- cbind(Elections_TS1, Objection_TS1, Acquittal_TS1) # Fit a VAR model (lag 5) VAR <- VAR(regressors, p=5, type="const", exogen = control) summary(VAR) AIC(VAR) BIC(VAR) # H0: Input does not cause output, then causality(VAR, cause = "V27I_TS1")$Granger #H0: Output does not cause input, then causality(VAR, cause = "V27O_TS1")$Granger # Plot the IRF irf(VAR, n.ahead = 7, ortho = TRUE, cumulative = TRUE, boot = TRUE, ci = 0.95,runs = 100, seed = NULL) plot(irf(VAR, ahead=7)) # Forecast error (variable behind $ is the DV) fevd(VAR, n.ahead = 7) ## Defendant # Combine the two variables you want to test regressors <- cbind(V27_45supI_TS1, V27O_TS1) control <- cbind(Elections_TS1, Objection_TS1, Acquittal_TS1) # Fit a VAR model (lag 2) VAR <- VAR(regressors, p=2, type="const", exogen = control) summary(VAR) AIC(VAR) BIC(VAR) # H0: Input does not cause output, then causality(VAR, cause = "V27_45supI_TS1")$Granger #H0: Output does not cause input, then causality(VAR, cause = "V27O_TS1")$Granger # Plot the IRF irf(VAR, n.ahead = 7, ortho = TRUE, cumulative = TRUE, boot = TRUE, ci = 0.95,runs = 100, seed = NULL) plot(irf(VAR, ahead=7)) # Forecast error fevd(VAR, n.ahead = 7) ### Unfair trial ## Frame sum # Combine the two variables you want to test regressors <- cbind(V30I_TS1, V30O_TS1) control <- cbind(Elections_TS1, Objection_TS1, Acquittal_TS1) # Fit a VAR model (lag 5) VAR <- VAR(regressors, p=5, type="const", exogen = control) summary(VAR) AIC(VAR) BIC(VAR) # H0: Input does not cause output, then causality(VAR, cause = "V30I_TS1")$Granger #H0: Output does not cause input, then causality(VAR, cause = "V30O_TS1")$Granger # Plot the IRF irf(VAR, n.ahead = 7, ortho = TRUE, cumulative = TRUE, boot = TRUE, ci = 0.95,runs = 100, seed = NULL) plot(irf(VAR, ahead=7)) # Forecast error variance fevd(VAR, n.ahead = 7) ## Defendant # Combine the two variables you want to test regressors <- cbind(V30_45supI_TS1, V30O_TS1) control <- cbind(Elections_TS1, Objection_TS1, Acquittal_TS1) # Fit a VAR model (lag 5) VAR <- VAR(regressors, p=5, type="const", exogen = control) summary(VAR) AIC(VAR) BIC(VAR) # H0: Input does not cause output, then causality(VAR, cause = "V30_45supI_TS1")$Granger #H0: Output does not cause input, then causality(VAR, cause = "V30O_TS1")$Granger # Plot the IRF irf(VAR, n.ahead = 7, ortho = TRUE, cumulative = TRUE, boot = TRUE, ci = 0.95,runs = 100, seed = NULL) plot(irf(VAR, ahead=7))