library(sf) |> suppressMessages()
## Warning: package 'sf' was built under R version 4.3.3
library(dplyr) |> suppressMessages()
## Warning: package 'dplyr' was built under R version 4.3.2
library(units) |> suppressMessages()
## Warning: package 'units' was built under R version 4.3.3
library(tmap)
## Warning: package 'tmap' was built under R version 4.3.3
library(tidyr)
## Warning: package 'tidyr' was built under R version 4.3.3
library(here)
## Warning: package 'here' was built under R version 4.3.3
## here() starts at C:/Users/yogad/OneDrive/Documents/Personal/PG/Applied/Hertie/Actual Studying/SEM-IV/Thesis/Pedestrianisation of Friedrichstrasse/O1_Accidents
library(sf) # dealing w spatial objects in R
library(ggplot2)
library(lubridate) # for joining monat and jahr columns
## Warning: package 'lubridate' was built under R version 4.3.3
##
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
##
## date, intersect, setdiff, union
library(readr)
## Warning: package 'readr' was built under R version 4.3.2
library(gsynth)
## Warning: package 'gsynth' was built under R version 4.3.3
## ## Syntax has been updated since v.1.2.0.
## ## Comments and suggestions -> yiqingxu@stanford.edu.
library(panelView)
## ## See bit.ly/panelview4r for more info.
## ## Report bugs -> yiqingxu@stanford.edu.
library(PanelMatch)
## Warning: package 'PanelMatch' was built under R version 4.3.3
##
## Attaching package: 'PanelMatch'
## The following object is masked from 'package:tidyr':
##
## extract
## The following object is masked from 'package:stats':
##
## weights
#table1, panelmatch, panelview below
library(tidyverse)
## Warning: package 'tidyverse' was built under R version 4.3.3
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ purrr 1.0.2 ✔ tibble 3.2.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ PanelMatch::extract() masks tidyr::extract()
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(haven)
## Warning: package 'haven' was built under R version 4.3.3
library(Synth)
## Warning: package 'Synth' was built under R version 4.3.3
## ##
## ## Synth Package: Implements Synthetic Control Methods.
##
## ## See https://web.stanford.edu/~jhain/synthpage.html for additional information.
library(devtools)
## Warning: package 'devtools' was built under R version 4.3.3
## Loading required package: usethis
## Warning: package 'usethis' was built under R version 4.3.3
library(SCtools)
## Warning: package 'SCtools' was built under R version 4.3.3
## Loading required package: future
library(readxl)
## Warning: package 'readxl' was built under R version 4.3.3
NL_accidents <- read.csv("NL_accidents.csv")
NL_accidents <- NL_accidents %>%
arrange(Date) %>%
mutate(Time_numeric = as.integer(dense_rank(Date)))
NL_accidents %>%
select(Date, Time_numeric) %>%
distinct() %>%
arrange(Time_numeric)
## Date Time_numeric
## 1 2018-01-01 1
## 2 2018-02-01 2
## 3 2018-03-01 3
## 4 2018-04-01 4
## 5 2018-05-01 5
## 6 2018-06-01 6
## 7 2018-07-01 7
## 8 2018-08-01 8
## 9 2018-09-01 9
## 10 2018-10-01 10
## 11 2018-11-01 11
## 12 2018-12-01 12
## 13 2019-01-01 13
## 14 2019-02-01 14
## 15 2019-03-01 15
## 16 2019-04-01 16
## 17 2019-05-01 17
## 18 2019-06-01 18
## 19 2019-07-01 19
## 20 2019-08-01 20
## 21 2019-09-01 21
## 22 2019-10-01 22
## 23 2019-11-01 23
## 24 2019-12-01 24
## 25 2020-01-01 25
## 26 2020-02-01 26
## 27 2020-03-01 27
## 28 2020-04-01 28
## 29 2020-05-01 29
## 30 2020-06-01 30
## 31 2020-07-01 31
## 32 2020-08-01 32
## 33 2020-09-01 33
## 34 2020-10-01 34
## 35 2020-11-01 35
## 36 2020-12-01 36
## 37 2021-01-01 37
## 38 2021-02-01 38
## 39 2021-03-01 39
## 40 2021-04-01 40
## 41 2021-05-01 41
## 42 2021-06-01 42
## 43 2021-07-01 43
## 44 2021-08-01 44
## 45 2021-09-01 45
## 46 2021-10-01 46
## 47 2021-11-01 47
## 48 2021-12-01 48
## 49 2022-01-01 49
## 50 2022-02-01 50
## 51 2022-03-01 51
## 52 2022-04-01 52
## 53 2022-05-01 53
## 54 2022-06-01 54
## 55 2022-07-01 55
## 56 2022-08-01 56
## 57 2022-09-01 57
## 58 2022-10-01 58
## 59 2022-11-01 59
## 60 2022-12-01 60
## 61 2023-01-01 61
## 62 2023-02-01 62
## 63 2023-03-01 63
## 64 2023-04-01 64
## 65 2023-05-01 65
## 66 2023-06-01 66
## 67 2023-07-01 67
## 68 2023-08-01 68
## 69 2023-09-01 69
## 70 2023-10-01 70
## 71 2023-11-01 71
## 72 2023-12-01 72
# interactive FE model
# Define outcome (Y), treatment (D), and index
gsynth_model2 <- gsynth(
formula = NULL,
data = NL_accidents,
Y = "Count_PKW_vs_VRU", # outcome variable
D = "D", # treatment variable
X = NULL, # no covariates for now
na.rm = FALSE,
index = c("Street_Group", "Time_numeric"), # panel structure
force = "two-way", # unit fixed effects (can try "two-way" later)
r = 1, # fixed number of latent factors (try 1 or 2)
CV = FALSE, # avoid unstable CV with 1 treated unit
estimator = "ife", # interactive fixed effects model
se = TRUE, # no standard errors for now
nboots = 200,
inference = "parametric", # not used since se = FALSE
cov.ar = 1,
parallel = TRUE,
tol = 0.001,
min.T0 = 5 # must have at least 5 pre-treatment periods
)
## Parallel computing ...
## Simulating errors ...Bootstrapping ...
##
gsynth_model2
## Call:
## gsynth.default(formula = NULL, data = NL_accidents, Y = "Count_PKW_vs_VRU",
## D = "D", X = NULL, na.rm = FALSE, index = c("Street_Group",
## "Time_numeric"), force = "two-way", r = 1, CV = FALSE,
## estimator = "ife", se = TRUE, nboots = 200, inference = "parametric",
## cov.ar = 1, parallel = TRUE, tol = 0.001, min.T0 = 5)
##
## Average Treatment Effect on the Treated:
## Estimate S.E. CI.lower CI.upper p.value
## ATT.avg -0.2366 0.3017 -0.8279 0.3546 0.4328
##
## ~ by Period (including Pre-treatment Periods):
## ATT S.E. CI.lower CI.upper p.value n.Treated
## -31 -0.3913357 1.1461 -2.63771 1.8550 0.732771 0
## -30 -0.1867067 1.0200 -2.18597 1.8126 0.854769 0
## -29 -0.3023841 1.2469 -2.74623 2.1415 0.808383 0
## -28 0.5553599 0.4928 -0.41051 1.5212 0.259765 0
## -27 -0.0053331 1.0728 -2.10800 2.0973 0.996034 0
## -26 0.1474648 1.0918 -1.99237 2.2873 0.892557 0
## -25 0.5553599 0.4928 -0.41051 1.5212 0.259765 0
## -24 -0.9473820 1.9480 -4.76545 2.8707 0.626735 0
## -23 -0.3696493 1.0495 -2.42658 1.6873 0.724671 0
## -22 0.0001198 1.0659 -2.08899 2.0892 0.999910 0
## -21 1.7417513 0.6320 0.50296 2.9805 0.005856 0
## -20 0.3174783 1.0842 -1.80746 2.4424 0.769652 0
## -19 0.0885163 0.7495 -1.38052 1.5576 0.905991 0
## -18 0.5133263 1.3702 -2.17228 3.1989 0.707938 0
## -17 1.4339841 0.9961 -0.51829 3.3863 0.149970 0
## -16 -0.7002659 1.1344 -2.92373 1.5232 0.537050 0
## -15 -0.8585888 0.9497 -2.71999 1.0028 0.365969 0
## -14 -0.9219478 1.0049 -2.89151 1.0476 0.358904 0
## -13 1.4862949 0.7670 -0.01695 2.9895 0.052640 0
## -12 0.1819658 1.4812 -2.72117 3.0851 0.902227 0
## -11 -0.8701118 1.2777 -3.37436 1.6341 0.495874 0
## -10 -0.6386797 1.0867 -2.76850 1.4911 0.556704 0
## -9 1.5318463 1.0828 -0.59041 3.6541 0.157156 0
## -8 -0.2430050 0.8651 -1.93855 1.4525 0.778786 0
## -7 -0.3149850 0.9637 -2.20371 1.5737 0.743769 0
## -6 -0.3131017 1.1340 -2.53572 1.9095 0.782470 0
## -5 0.3585113 0.4666 -0.55607 1.2731 0.442313 0
## -4 0.1085910 0.9284 -1.71096 1.9281 0.906883 0
## -3 -0.2684448 0.9018 -2.03591 1.4990 0.765946 0
## -2 -0.2250160 1.9472 -4.04139 3.5914 0.908001 0
## -1 -0.7314707 1.5086 -3.68834 2.2254 0.627779 0
## 0 -0.7321615 1.1907 -3.06590 1.6016 0.538623 0
## 1 -1.4865288 1.9339 -5.27696 2.3039 0.442097 1
## 2 -0.5357670 0.9140 -2.32708 1.2555 0.557735 1
## 3 -0.4402270 0.9645 -2.33053 1.4501 0.648067 1
## 4 -0.1936448 0.6553 -1.47803 1.0907 0.767612 1
## 5 -0.0765341 0.8270 -1.69740 1.5443 0.926264 1
## 6 0.2938337 0.8945 -1.45931 2.0470 0.742536 1
## 7 0.0959522 0.9475 -1.76109 1.9530 0.919336 1
## 8 0.1793196 0.6696 -1.13305 1.4917 0.788849 1
## 9 -0.5811336 1.1400 -2.81553 1.6533 0.610221 1
## 10 -0.1836876 0.6959 -1.54759 1.1802 0.791807 1
## 11 -0.9807079 1.1494 -3.23350 1.2721 0.393531 1
## 12 -0.3075900 0.5313 -1.34883 0.7336 0.562595 1
## 13 -0.8316949 1.4598 -3.69283 2.0294 0.568856 1
## 14 -0.6864644 1.0039 -2.65407 1.2811 0.494103 1
## 15 0.0548484 0.6856 -1.28891 1.3986 0.936237 1
## 16 0.2507344 0.5813 -0.88868 1.3901 0.666249 1
## 17 -0.1573942 0.8334 -1.79079 1.4760 0.850201 1
## 18 0.3611929 0.7774 -1.16257 1.8850 0.642225 1
## 19 0.0277056 0.7879 -1.51647 1.5719 0.971948 1
## 20 -0.4193692 0.8139 -2.01457 1.1758 0.606369 1
## 21 -0.9411684 1.1128 -3.12218 1.2398 0.397675 1
## 22 -0.9939790 1.3888 -3.71592 1.7280 0.474161 1
## 23 -0.1870663 1.1533 -2.44751 2.0734 0.871149 1
## 24 -0.2094844 1.0353 -2.23860 1.8196 0.839647 1
## 25 -0.3983236 2.0411 -4.39884 3.6022 0.845276 1
## 26 -1.3575379 1.6942 -4.67818 1.9631 0.422976 1
## 27 -0.1945983 1.2356 -2.61643 2.2272 0.874861 1
## 28 0.1396435 0.8833 -1.59155 1.8708 0.874381 1
## 29 -0.0713642 1.3264 -2.67098 2.5283 0.957091 1
## 30 1.0615483 1.0622 -1.02031 3.1434 0.317605 1
## 31 -0.2798535 0.8085 -1.86458 1.3049 0.729254 1
## 32 -0.4192596 0.9628 -2.30633 1.4678 0.663232 1
## 33 -0.8225503 0.9179 -2.62164 0.9765 0.370197 1
## 34 -0.0425456 0.9710 -1.94568 1.8606 0.965051 1
## 35 0.0193634 1.2274 -2.38623 2.4250 0.987413 1
## 36 -0.3728414 0.9454 -2.22581 1.4801 0.693308 1
## 37 -0.5763992 1.5816 -3.67630 2.5235 0.715531 1
## 38 0.7793050 0.7805 -0.75054 2.3092 0.318083 1
## 39 0.7265813 0.7768 -0.79595 2.2491 0.349618 1
## 40 0.2917123 0.7251 -1.12954 1.7130 0.687476 1
plot(gsynth_model2)
NL_accidents_46 <- NL_accidents %>%
filter(Time_numeric <= 46)
# interactive FE model
# Define outcome (Y), treatment (D), and index
gsynth_model3 <- gsynth(
formula = NULL,
data = NL_accidents_46,
Y = "Count_PKW_vs_VRU", # outcome variable
D = "D1", # treatment variable
X = NULL, # no covariates for now
na.rm = FALSE,
index = c("Street_Group", "Time_numeric"), # panel structure
force = "two-way", # unit fixed effects (can try "two-way" later)
r = 1, # fixed number of latent factors (try 1 or 2)
CV = FALSE, # avoid unstable CV with 1 treated unit
estimator = "ife", # interactive fixed effects model
se = TRUE, # no standard errors for now
nboots = 200,
inference = "parametric", # not used since se = FALSE
cov.ar = 1,
parallel = TRUE,
tol = 0.001,
min.T0 = 5 # must have at least 5 pre-treatment periods
)
## Parallel computing ...
## Simulating errors ...Bootstrapping ...
##
gsynth_model3
## Call:
## gsynth.default(formula = NULL, data = NL_accidents_46, Y = "Count_PKW_vs_VRU",
## D = "D1", X = NULL, na.rm = FALSE, index = c("Street_Group",
## "Time_numeric"), force = "two-way", r = 1, CV = FALSE,
## estimator = "ife", se = TRUE, nboots = 200, inference = "parametric",
## cov.ar = 1, parallel = TRUE, tol = 0.001, min.T0 = 5)
##
## Average Treatment Effect on the Treated:
## Estimate S.E. CI.lower CI.upper p.value
## ATT.avg -0.4133 0.4243 -1.245 0.4182 0.33
##
## ~ by Period (including Pre-treatment Periods):
## ATT S.E. CI.lower CI.upper p.value n.Treated
## -31 -0.393695 1.0230 -2.3987 1.6114 0.70035 0
## -30 -0.153692 0.9481 -2.0119 1.7045 0.87122 0
## -29 -0.278650 1.1113 -2.4568 1.8995 0.80202 0
## -28 0.548773 0.4967 -0.4247 1.5222 0.26920 0
## -27 -0.006374 1.0500 -2.0643 2.0516 0.99516 0
## -26 0.178897 1.0829 -1.9435 2.3013 0.86878 0
## -25 0.548773 0.4967 -0.4247 1.5222 0.26920 0
## -24 -0.996655 1.9061 -4.7325 2.7392 0.60105 0
## -23 -0.352391 1.0766 -2.4625 1.7577 0.74342 0
## -22 -0.002057 0.9488 -1.8617 1.8576 0.99827 0
## -21 1.743748 0.6827 0.4058 3.0817 0.01064 0
## -20 0.312853 1.0723 -1.7887 2.4144 0.77046 0
## -19 0.111653 0.8314 -1.5178 1.7411 0.89316 0
## -18 0.471930 1.3703 -2.2138 3.1576 0.73054 0
## -17 1.417482 0.9030 -0.3524 3.1874 0.11649 0
## -16 -0.685714 1.2633 -3.1617 1.7903 0.58727 0
## -15 -0.881428 0.8833 -2.6126 0.8498 0.31833 0
## -14 -0.913168 1.0062 -2.8852 1.0589 0.36410 0
## -13 1.473705 0.7419 0.0196 2.9278 0.04699 0
## -12 0.163637 1.3897 -2.5601 2.8874 0.90626 0
## -11 -0.870336 1.2532 -3.3266 1.5860 0.48739 0
## -10 -0.658085 0.9392 -2.4988 1.1827 0.48349 0
## -9 1.560896 1.0596 -0.5158 3.6376 0.14071 0
## -8 -0.260058 0.7722 -1.7736 1.2535 0.73630 0
## -7 -0.298162 1.0421 -2.3406 1.7443 0.77479 0
## -6 -0.285987 1.2501 -2.7361 2.1641 0.81904 0
## -5 0.376108 0.4422 -0.4907 1.2429 0.39507 0
## -4 0.128410 0.8166 -1.4721 1.7289 0.87505 0
## -3 -0.242767 0.8353 -1.8800 1.3944 0.77134 0
## -2 -0.285876 1.9730 -4.1528 3.5810 0.88479 0
## -1 -0.736451 1.5369 -3.7488 2.2759 0.63182 0
## 0 -0.735319 1.1513 -2.9918 1.5212 0.52303 0
## 1 -1.565839 1.9177 -5.3245 2.1928 0.41420 1
## 2 -0.559963 0.9404 -2.4031 1.2832 0.55154 1
## 3 -0.443544 0.8916 -2.1910 1.3039 0.61884 1
## 4 -0.181949 0.6957 -1.5455 1.1816 0.79369 1
## 5 -0.050696 0.7318 -1.4850 1.3836 0.94477 1
## 6 0.311479 0.8221 -1.2998 1.9227 0.70477 1
## 7 0.102255 0.8563 -1.5760 1.7805 0.90494 1
## 8 0.177400 0.5948 -0.9885 1.3433 0.76553 1
## 9 -0.564128 1.0628 -2.6473 1.5190 0.59558 1
## 10 -0.200350 0.6010 -1.3783 0.9776 0.73887 1
## 11 -1.008095 1.1908 -3.3420 1.3258 0.39723 1
## 12 -0.325885 0.5343 -1.3731 0.7214 0.54192 1
## 13 -0.823716 1.2836 -3.3395 1.6921 0.52105 1
## 14 -0.652998 0.8794 -2.3765 1.0705 0.45774 1
plot(gsynth_model3)
# NL_accidents has this variable now
NL_accidents <- NL_accidents %>%
mutate(unit_id = as.integer(factor(Street_Group)))
street_mapping <- NL_accidents %>%
select(Street_Group, unit_id) %>%
distinct() %>%
arrange(unit_id)
print(street_mapping)
## Street_Group unit_id
## 1 Boxhagenerstraße 1
## 2 Friedrichstrasse_Flaniermeile_Treated 2
## 3 Kastanienallee 3
## 4 Kudamm 4
## 5 Leipziger Straße 5
## 6 Northern_Friedrichstraße 6
## 7 Potsdamer Straße 7
## 8 Schönhauser_Allee 8
## 9 Tauentzienstraße 9
## 10 Unter den Linden 10
## 11 Wilmersdorfer Straße 11
dataprep_out <- dataprep(
foo = NL_accidents, # your full panel dataset,
predictors = c(), # <<-- Put time-invariant or pre-treatment variables here (e.g., average traffic count, demographic info)
predictors.op = "mean", # average them across pre-treatment periods
time.predictors.prior = 1:32, # Time periods **before treatment** (D1 starts at Time_numeric = 33)
special.predictors = list(
list("Count_PKW_vs_VRU", 1:32, "mean")),
# <<-- for example: outcome variable average before treatment
dependent = "Count_PKW_vs_VRU",
unit.variable = "unit_id", # numeric ID for each street
unit.names.variable = "Street_Group", # actual street names
time.variable = "Time_numeric", # numeric time 1–72
treatment.identifier = 2, # the unit_id of "Friedrichstrasse_Flaniermeile_Treated" — double-check this with your mapping
controls.identifier = c(1,3,4,5,6,7,8,9,10,11), # all other unit_ids EXCEPT the treated one
time.optimize.ssr = 1:32, # the period over which to minimize pre-treatment MSE
time.plot = 1:72 # full time window for plotting
)
synth_out <- synth(data.prep.obj = dataprep_out)
##
## X1, X0, Z1, Z0 all come directly from dataprep object.
##
##
## ****************
## optimization over w weights: computing synthtic control unit
##
##
##
## ****************
## ****************
## ****************
##
## MSPE (LOSS V): 0.6895945
##
## solution.v:
## 1
##
## solution.w:
## 0.04006605 0.041449 0.01360608 0.04217476 0.04074706 0.02263298 0.02224836 0.06883887 0.041449 0.6667878
path.plot(synth_out, dataprep_out)
gaps.plot(synth_out,dataprep_out,Ylab = "Gap = Treated-Synthetic",Main = "Effect of Car-free FS on Bikers and Pedestrians over time")
::: Can observe poor pre-treatment match :::
# mapping weights synth model-1
unit_map <- NL_accidents %>%
select(unit_id, Street_Group) %>%
distinct()
control_ids <- setdiff(unique(NL_accidents$unit_id), 2) # assuming treated unit_id = 2
control_units <- unit_map %>%
filter(unit_id %in% control_ids) %>%
arrange(unit_id) # ensure same order as weights
data.frame(
Street = control_units$Street_Group,
Weight = synth_out$solution.w
)
## Street w.weight
## 1 Boxhagenerstraße 0.04006605
## 3 Kastanienallee 0.04144900
## 4 Kudamm 0.01360608
## 5 Leipziger Straße 0.04217476
## 6 Northern_Friedrichstraße 0.04074706
## 7 Potsdamer Straße 0.02263298
## 8 Schönhauser_Allee 0.02224836
## 9 Tauentzienstraße 0.06883887
## 10 Unter den Linden 0.04144900
## 11 Wilmersdorfer Straße 0.66678783
dataprep_out2 <- dataprep(
foo = NL_accidents, # your full panel dataset,
predictors = c(), # <<-- Put time-invariant or pre-treatment variables here (e.g., average traffic count, demographic info)
predictors.op = "mean", # average them across pre-treatment periods
time.predictors.prior = 1:32, # Time periods **before treatment** (D1 starts at Time_numeric = 33)
special.predictors = list(
list("Count_PKW_vs_VRU", 1:32, "mean")),
# <<-- for example: outcome variable average before treatment
dependent = "Count_PKW_vs_VRU",
unit.variable = "unit_id", # numeric ID for each street
unit.names.variable = "Street_Group", # actual street names
time.variable = "Time_numeric", # numeric time 1–72
treatment.identifier = 2, # the unit_id of "Friedrichstrasse_Flaniermeile_Treated" — double-check this with your mapping
controls.identifier = c(1,3,4,5,6,7,8,9,10,11), # all other unit_ids EXCEPT the treated one
time.optimize.ssr = 1:32, # the period over which to minimize pre-treatment MSE
time.plot = 1:46 # full time window for plotting
)
synth_out2 <- synth(data.prep.obj = dataprep_out2)
##
## X1, X0, Z1, Z0 all come directly from dataprep object.
##
##
## ****************
## optimization over w weights: computing synthtic control unit
##
##
##
## ****************
## ****************
## ****************
##
## MSPE (LOSS V): 0.6895945
##
## solution.v:
## 1
##
## solution.w:
## 0.04006605 0.041449 0.01360608 0.04217476 0.04074706 0.02263298 0.02224836 0.06883887 0.041449 0.6667878
path.plot(synth_out, dataprep_out2)
gaps.plot(synth_out2,dataprep_out2,Ylab = "Gap = Treated-Synthetic",Main = "Effect of Car-free FS Phase-1 on Bikers and Pedestrians until phase-1 end")
# mapping weights synth model-2
data.frame(
Street = control_units$Street_Group,
Weight = synth_out2$solution.w
)
## Street w.weight
## 1 Boxhagenerstraße 0.04006605
## 3 Kastanienallee 0.04144900
## 4 Kudamm 0.01360608
## 5 Leipziger Straße 0.04217476
## 6 Northern_Friedrichstraße 0.04074706
## 7 Potsdamer Straße 0.02263298
## 8 Schönhauser_Allee 0.02224836
## 9 Tauentzienstraße 0.06883887
## 10 Unter den Linden 0.04144900
## 11 Wilmersdorfer Straße 0.66678783
dataprep_out3 <- dataprep(
foo = NL_accidents, # your full panel dataset,
predictors = c(), # <<-- Put time-invariant or pre-treatment variables here (e.g., average traffic count, demographic info)
predictors.op = "mean", # average them across pre-treatment periods
time.predictors.prior = 1:32, # Time periods **before treatment** (D1 starts at Time_numeric = 33)
special.predictors = list(
list("Count_PKW_vs_VRU", 1:32, "mean")),
# <<-- for example: outcome variable average before treatment
dependent = "Count_PKW_vs_VRU",
unit.variable = "unit_id", # numeric ID for each street
unit.names.variable = "Street_Group", # actual street names
time.variable = "Time_numeric", # numeric time 1–72
treatment.identifier = 2, # the unit_id of "Friedrichstrasse_Flaniermeile_Treated" — double-check this with your mapping
controls.identifier = c(1,3,4,5,6,7,8,9,10,11), # all other unit_ids EXCEPT the treated one
time.optimize.ssr = 1:32, # the period over which to minimize pre-treatment MSE
time.plot = 1:61 # full time window for plotting
)
synth_out3 <- synth(data.prep.obj = dataprep_out3)
##
## X1, X0, Z1, Z0 all come directly from dataprep object.
##
##
## ****************
## optimization over w weights: computing synthtic control unit
##
##
##
## ****************
## ****************
## ****************
##
## MSPE (LOSS V): 0.6895945
##
## solution.v:
## 1
##
## solution.w:
## 0.04006605 0.041449 0.01360608 0.04217476 0.04074706 0.02263298 0.02224836 0.06883887 0.041449 0.6667878
path.plot(synth_out, dataprep_out3)
gaps.plot(synth_out3,dataprep_out3,Ylab = "Gap = Treated-Synthetic",Main = "Effect of Car-free FS Phase-1 on Bikers and Pedestrians until phase-2 begins")
data.frame(
Street = control_units$Street_Group,
Weight = synth_out3$solution.w
)
## Street w.weight
## 1 Boxhagenerstraße 0.04006605
## 3 Kastanienallee 0.04144900
## 4 Kudamm 0.01360608
## 5 Leipziger Straße 0.04217476
## 6 Northern_Friedrichstraße 0.04074706
## 7 Potsdamer Straße 0.02263298
## 8 Schönhauser_Allee 0.02224836
## 9 Tauentzienstraße 0.06883887
## 10 Unter den Linden 0.04144900
## 11 Wilmersdorfer Straße 0.66678783