'"Error in svd(c) : infinite or missing values in 'x'" when using synth() in R

I am using the synth package in R to implement a synthetic control method, where I use the dataprep() function to construct the appropriate matrices to be passed to synth(). That is, I call dataprep() as follows:

dataprep_out <- dataprep(foo = csv_data,
                           predictors = vars_dep,      
                           predictors.op = "mean",
                           time.predictors.prior = 2000:2010,
                           dependent = "Log_gdp",    
                           unit.variable = "REG_FACTOR",
                           unit.names.variable = "REG_ID",
                           time.variable = "Year",
                           treatment.identifier = my_factor_treated,
                           controls.identifier = my_controls,
                           time.optimize.ssr = 2000:2010,
                           time.plot = 2000:2017
  )

after which I call synth():

synth_out <- synth(data.prep.obj = dataprep_out)

This works fine and gives me the results I expect. However, when I repeat the same piece of code for another treated observation but with exactly the same controls (i.e., my_factor_treated is the only argument in dataprep() that has changed), I get the following error upon calling synth():

Error in svd(c) : infinite or missing values in 'x'.

I am struggling to find the cause of this error, also because I am unsure which object is being passed to the svd() function during the execution of synth(). None of the columns in the objects returned by dataprep() contain only zeroes, and they contain no Inf values (which makes sense, because otherwise this error should have occurred on the first treated observation as well, right?).

I would appreciate if someone could tell me why this error occurs and how I can prevent it. I have checked out multiple related questions but haven't been able to find my answer. Thanks!

PS. I am not sure how to provide a suitable MWE since I guess my problem is data-related and I won't be able to share the dataset that I am using.



Solution 1:[1]

I encountered the same issue, and the same as you did I confirmed there is no missing value or all 0's in my data set. Later I realized this is caused by optimization algorithm used in generating weights. One thing you can try is to add argument "optimxmethod='All'" in synth function. This will try all available methods and report you the one with best performance.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dharman