Search code examples
rregressionlinear-regressionpanelplm

Regression model without predictors using plm in R?


I have an unbalance panel data table with variables ID, year, and outcome. The data for each ID spans from 2005-2020, although each ID won't have all 15 years of data. Here's a sample:

ID, year, outcome
1, 2005, 70
1, 2006, 73
1, 2007, 70
1, 2008, 68
2, 2005, 65
2, 2006, 71
2, 2007, 68
2, 2008, 64
2, 2009, 63
3, 2011, 78
3, 2012, 81
4, 2008, 75

I want to run a plm regression model without predictors (i.e. a regression model on the intercept).

I tried running the following but get the error message "empty model":

feModel <- plm(damMean ~ 1, data = finalDT, model = "within", index = c("sireID", "year"))

# Error in plm.fit(data, model, effect, random.method, random.models, random.dfcor,  : 
  empty model

Is this possible to do using the plm package in R?


Solution

  • I think this is not so much a programming question but rather a statistical question. Also I think it is not so much a question about the capabilities of package "plm" per se but rather if such a within model makes sense and the technical estimation approach to within models implemented.

    plm's within models (fixed effect models) do not contain an intercept. Some other statistical software packages have a somewhat artifical intercept in their within models (most notably probably Stata, but gretl as well). You may want to look at ?plm::within_intercept and the literature it references for more details about the intercept in within models.

    Let's see what happens in case of only an intercept as regressor in a within model:

    library("plm")
    data("Grunfeld", package = "plm")
    pGrun <- pdata.frame(Grunfeld)
    plm(inv ~ 1, data = pGrun, model = "within") # errors with "empty model"
    
    pGrun$int <- 1 # intercept
    within_int <- Within(pGrun$int) # within transformation of intercept
    # -> all zeros:
    head(within_int)
    ##  1-1935 1-1936 1-1937 1-1938 1-1939 1-1940 
    ##       0      0      0      0      0      0 
    all.equal(as.numeric(within_int), rep(0, 200L), check.attributes = FALSE)
    ##  TRUE
    

    The within transformation of the intercept is all zeros, thus the error message by plm about an empty model is sane. gretl, an econometrics package with an intercept for within models, outputs an estimate for such an intercept-only model:

                 coefficient   std. error   t-ratio    p-value 
      ---------------------------------------------------------
      const        145.958      7.68517      18.99    8.85e-046 ***
    

    What is this value? Well it is the mean of the dependend variable

    mean(pGrun$inv)
    ##   145.9582
    

    Or, if you want to derive this mean by a model estimation with plm you can estimate a "pooling" model with intercept only:

    plm(inv ~ 1, data = pGrun, model = "pooling")
    ##  Model Formula: inv ~ 1
    
    ##  Coefficients:
    ##  (Intercept) 
    ##       145.96