2

I keep encountering a problem while running tidysynth. I'm pretty new to R and I'm applying the tidysynth manual to my data. I keep getting the message "Error in unique(data$.id) : argument "data" is missing, with no default" after the "generate_control() command. Here are my codes.

  synth_js<- synth %>%

  synthetic_control (outcome = q69, # outcome (job satisfaction)
                 unit = name,   # unit index in the panel data
                 time = year,   # time index in the panel data
                 i_unit = "Securities and Exchange Commission, All Other", # unit where the intervention occurred
                 i_time = 2014, # time period when the intervention occurred
                 generate_placebos= T) # generate placebo synthetic controls (for inference) %>%)
 # Generate the aggregate predictors used to fit the weights
 # lnemp lnsal avgtenure profpc collegepc d_politicize richardson from 2006 - 2014
generate_predictor(time_window = 2006:2014,
               salary = mean(lnsal, na.rm = T),
               tenure = mean(avgtenure, na.rm = T),
               professionals = mean(profpc, na.rm = T),
               college = mean(collegepc, na.rm = T),
               politicize = mean(d_politicize, na.rm = T),
               ideology = mean(richardson, na.rm = T)) %>%

 # average Job Satisfaction in the donor pool from 2006 - 2014
 generate_predictor(time_window = 2006:2014,
                 job_satisfaction = mean(q69, na.rm = T)) %>%

 # Lagged Job Satisfaction 
  generate_predictor(time_window = 2008,
                 js_2008 = q69) %>%
  generate_predictor(time_window = 2010,
                 js_2010 = q69) %>%
  generate_predictor(time_window = 2011,
                 js_2011 = q69) %>%
  generate_predictor(time_window = 2012,
                 js_2012 = q69) %>%
  generate_predictor(time_window = 2013,
                 js_2013 = q69) %>%

# Generate the fitted weights for the synthetic control
 generate_weights(optimization_window = 2006:2014, # time to use in the optimization task
               margin_ipop = .02,sigf_ipop = 7,bound_ipop = 6 # optimizer options) %>%
# Generate the synthetic control
generate_control()

I keep getting the following error

+   generate_control()
Error in unique(data$.id) : argument "data" is missing, with no default

Does anyone know why this happens? Thanks.

Yongjin
  • 31
  • 1
  • You haven't passed any arguments to `generate_control()` - it can't do anything without any input. The `argument "data" is missing` - see the `arguments` section at the documentation page - `?generate_control` ( https://rdrr.io/cran/tidysynth/man/generate_control.html ). Maybe `generate_control(synth_js)` ? – thelatemail Jan 29 '22 at 21:15
  • Thanks for your reply. In fact, I have done that, and still doesn't work. I get the message "generate_control(synth_js) Error in generate_control(., synth_js) : unused argument (synth_js)" – Yongjin Jan 29 '22 at 23:18
  • 1
    You started your code with the object `synth`. Can you include that in your question so that your error is reproducible? It looks like you're fairly new to SO; welcome to the community! If you want great answers quickly, it's best to make your question reproducible. This includes sample data like the output from `dput(head(dataObject)))`. Check it out: [making R reproducible questions](https://stackoverflow.com/q/5963269). – Kat Jan 30 '22 at 07:22
  • Please provide enough code so others can better understand or reproduce the problem. – Community Feb 06 '22 at 04:18

1 Answers1

1

It appears that the issue is minor (but easy to make!): you're not closing the generate_weights function.

You have:

... %>% 
# Generate the fitted weights for the synthetic control
 generate_weights(optimization_window = 2006:2014, # time to use in the optimization task
               margin_ipop = .02,sigf_ipop = 7,bound_ipop = 6 # optimizer options) %>%

But you'll note that the close of the parentheses is commented out. Thus the error being registered by generate_control, b/c no data is being passed to it (rather generate_control() is actually being passed as an argument to generate_weights()).

Just close the parentheses and you should be good to go.

... %>% 
generate_weights(optimization_window = 2006:2014, 
                 margin_ipop = .02, sigf_ipop = 7, bound_ipop = 6) %>%
generate_control()