# How to perform unbalanced panel data regression in R?

I am attempting to perform an unbalanced panel data regression in R. My code is as follows:

pdata <- plm.data(b2, index = c("ticker", "year"))
try1 <- plm(formula = logDipLoanTotal ~ PrimeFiling  +
logLiabBefore + logSalesBefore + EmplBefore + DebttoAssetRatio +
squareDebttoAssetRatio + FSCashShortTermInvestments + Percent +
NUM_OF_EMPLOYEES, data = pdata, model = "within", effect = "time")
summary(try1)


I run into the following error:

duplicate couples (id-time) in resulting pdata.frame
to find out which, use e.g. table(index(your_pdataframe), useNA = "ifany")
duplicate couples (id-time)


This is obvious - I am having issues because my panel data is unbalanced, where the ticker/year combination can be associated with multiple lines of data. This is because multiple "deals" were done in the year associated with the company ticker in the year, or sometimes no deals were run in the ticker/year combination. How do I run this kind of model in RStudio with unbalanced data? Let me know if this doesn't make sense and I can edit the question.

It would be helpful to provide a reproductible example. In the paper Panel Data Econometrics in R: The plm Package, the authors explicitly mention that economic panel datasets often happen to be unbalanced, which case needs some adaptation to the methods. Hopefully, they provide a solution and the result of their work is bundled in the plm add-on package.
R> emp.gmm <- pgmm(dynformula(emp ~ wage + capital + output, lag = list(2, + 1, 0, 1),