[R] Synthetic Control Method

Bert Gunter bgunter@4567 @end|ng |rom gm@||@com
Tue Apr 16 17:10:24 CEST 2024


Note that your unit.variable and unit.names.variable are indentical. Is
this what you intended?

(I have no idea how the Synth package works).

Bert

On Tue, Apr 16, 2024 at 12:58 AM <nadja.delliehausen using bluewin.ch> wrote:

> Good Morning
>
>
>
> I want to perform a synthetic control method with R. For this purpose, I
> created the following code:
>
>
>
> # Re-load packages
>
> library(Synth)
>
> library(readxl)
>
>
>
> # Pfadeinstellung Excel-Blatt
>
> excel_file_path <-
> ("C:\\Users\\xxxxx\\Desktop\\DATA_INVESTMENTVOLUMEN_FOR_R_WITHOUT_NA.xlsx")
>
>
>
> # Load the Excel file
>
> INVESTMENTVOLUME <- read_excel(excel_file_path)
>
>
>
> # Anzeigen des gesamten Dataframes
>
> print(INVESTMENTVOLUME)
>
>
>
> # Make sure BFS is numeric right before dataprep
>
> INVESTMENTVOLUME$BFS <- as.numeric(INVESTMENTVOLUME$BFS)
>
>
>
> # running dataprep
>
> dataprep_out <- dataprep(
>
>   foo = INVESTMENTVOLUME,
>
>   predictors = c("Predictor 1", " Predictor 2", " Predictor 3" Predictor
> 4",
> " Predictor 5", " Predictor 6"),
>
>   special.predictors = list(list("Special Predictor 1", seq(1, 12, by =
> 1))),
>
>   dependent = "INVESTMENTVOLUME_12_MONTH_AVERAGE",
>
>   unit.variable = "BFS",
>
>   time.variable = "DATE",
>
>   treatment.identifier = XXXX,
>
>   controls.identifier =
> unique(INVESTMENTVOLUME$BFS[-which(INVESTMENTVOLUME$BFS == XXXX)]),
>
>   time.predictors.prior = as.Date("2010-01-01"):as.Date("2017-10-01"),
>
>   time.optimize.ssr = as.Date("2010-01-01"):as.Date("2017-10-01"),
>
>   time.plot = as.Date("2010-01-01"):as.Date("2024-03-01"),
>
>   unit.names.variable = "BFS"
>
> )
>
>
>
> synth_out <- synth(
>
>   data.prep.obj = dataprep_out
>
> )
>
>
>
> I keep getting the same error message. Unfortunately, ChatGPT and solutions
> from various forums do not help. My unit variables are all numeric except
> one, which is a date and has POSIXct as type.
>
> Fehler in dataprep(foo = INVESTMENTVOLUME, predictors = c("Predictor 1",
> :
>
>
>
>  unit.variable not found as numeric variable in foo.
>
>
>
> I would be very grateful if you could help me with my problem.
>
>
>
> Thank you in advance for your efforts.
>
>
>
> Kind regards
>
> Nadja Delliehausen
>
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list