Please provide a reprex. Without it, it is not clear to me which packages you use.
It is also not clear to me if you have actually run part of this code:
did a construct such as mod_3 <- pam(A_bar ~ B_bar + sfe(C_bar)data = PanelS1)
actually run without errors ?
And not knowing anything about your subject I would think that mod_3
would be derived from PanelS2
.
And res_2
is derived from mod1
???
I think (but could be wrong) that these are errors that can be avoided by presenting code that has actually run.
At this moment I can not help you any further than suggesting that you pack the repeating parts of code in a function that returns in a list of data.frame all the elements that you need for the ongoing calculation.