Predictions in logistic regression model by group

This is perfect - many thanks @andresrcs!!! I couldn't get it to work the way you did.

Two more small questions:

  1. is it easily possibly to adjust the code so that the output also includes the date of the fit_data = year_mon?
  2. when applying the code on my complete dataset, I noticed that for cases where there was no matching LPERMNO in the fit data but where a model was created from the model input (i.e. a stock is included in the model_data but not in the fit_data), the output still includes some fit values which are probably based on empty data. It's probably easiest to just exclude these stocks from both data sets in the first place, or can we adjust the "left_join" for that?
    thanks for your help!
1 Like