Stargazer with result from plm::pgmm() gives ‘Error: Unrecognized object type.’

Total
9
Shares

Although stargazeris said to work with objects created by plm::pgmm() (see here) I get the error Error: Unrecognized object type when running the following code:

require(pder)
require(plm)
require(stargazer)

data("DemocracyIncome", package = "pder")

abond_2step <- plm::pgmm(
  formula = democracy ~ lag(democracy) + lag(income) | lag(democracy, 2:99) | lag(income, 2),
  data = DemocracyIncome, subset = sample==1, index = c("country", "year"),
  model = "twostep", effect = "twoways")

stargazer::stargazer(abond_2step) # yields 'Error: Unrecognized object type'

Am I doing something wrong or does stargazer not support objects created by plm::pgmm() any more? The relevant specification of my session are as follows:

  • R: 4.0.4 (Mac)
  • plm: 2.4-1
  • pder: 1.0-1
  • stargazer: 5.2.2

Thanks a lot for your help!

Edit: I figured out that when removing the explicit plm:: befor pgmm the code works, yet I have no idea why:

abond_2step_alt <- pgmm( # removed plm::
  formula = democracy ~ lag(democracy) + lag(income) | lag(democracy, 2:99) | lag(income, 2),
  data = DemocracyIncome, subset = sample==1, index = c("country", "year"),
  model = "twostep", effect = "twoways")

stargazer::stargazer(abond_2step_alt) # This works!

Solution

Answer

The package does string matching to abond_2step$call[1]. In your case, that would be plm::pgmm(). The package is hardcoded to look for pgmm(), and thus doesn’t properly set it.

Another example of code that doesn’t work

stargazer(stats::lm(Sepal.Length ~ ., iris))

Rationale

stargazer is written quite unconventionally. It has a lot of function definition INSIDE stargazer::stargazer, making it harder to find what actually happens.

At some point, a function named .get.model.name is called, which in turn calls .model.identify, which looks like this:

.model.identify <-
  function(object.name) {
    
    if (class(object.name)[1]=="NULL") {   #### !!!!! continue this
      return("NULL")
    }
    
    if (class(object.name)[1]=="Arima") {
      return("Arima")
    }
    
    if (class(object.name)[1]=="fGARCH") {
      return("fGARCH")
    }
    
    if (class(object.name)[1]=="censReg") {
      return("censReg")
    }
    
    if (class(object.name)[1]=="ergm") {
      return("ergm")
    }
.........

The code that we care about:

else if (object.name$call[1]=="pgmm()") {
   return("pgmm")
}   

That’s also where the problem is: abond_2step$call[1] returns plm::pgmm(). This is also exactly why your alternative call does work: abond_2step_alt$call[1] returns pgmm().

Leave a Reply

Your email address will not be published. Required fields are marked *