[R] Synthetic Control Method

@@dj@@deiiieh@use@ m@iii@g oii biuewi@@ch @@dj@@deiiieh@use@ m@iii@g oii biuewi@@ch
Mon Apr 15 12:12:22 CEST 2024


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]]



More information about the R-help mailing list