Search code examples
rlmpanel-dataplm

2-way FE model gives "empty model" in R


I am trying to run a 2-way fixed effect model in R, using plm. I am trying to get the treatment effect of an event on municipalities votes on referenda.

I would like to run the model with municipality and referenda fixed effects. Each row or unit is a pair of municipality*referendum.

I am trying to fit the model using the following:

model_2fe <- plm(vote.ant.immig ~ pre.post, data = clean.df, effect = "twoways", index = c("municipality.code", "ref.code")) 

And I keep on getting the following:

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

If it helps: pre.post is a factor indicating treatment condition (1,0), vote.ant.immig is a numeric object, municipality.code is a factor, as is ref.code.

Could anyone help me? Thanks!


Solution

  • Another way to accomplish what @Helix123 discusses above, is to create a new dummy variable for municipality x referendum fixed effects.

    clean.df$muni_x_ref <- factor(paste(clean.df$municipality, clean.df$refcode, sep='X'))
    

    Then you can tabulate prepost with your new muni_x_ref variable. First few lines below. You see that you have only one realisation of your independent variable for each of the municipality x referendum fixed effects. Your fe's and independent variable are fully collinear, and there is no variation to estimate your model. I believe you need to rethink what you want to estimate.

     table(clean.df$muni_x_refcode, df$prepost)
    
    
                                0 1
      AdlikonX5240              1 0
      AdlikonX5250              1 0
      AdlikonX5320              1 0
      AdlikonX5470              1 0
      AdlikonX5521              1 0
      AdlikonX5522              1 0
      AdlikonX5710              1 0
      AdlikonX5800              0 1
      AdlikonX5880              0 1
      AdlikonX5970              0 1
      AdlikonX6040              0 1
      AdlikonX6090              0 1
      Aeugst am AlbisX5240      1 0
      Aeugst am AlbisX5250      1 0
      Aeugst am AlbisX5320      1 0
      Aeugst am AlbisX5470      1 0
      Aeugst am AlbisX5521      1 0
      Aeugst am AlbisX5522      1 0
      Aeugst am AlbisX5710      1 0
      Aeugst am AlbisX5800      0 1
      Aeugst am AlbisX5880      0 1
      Aeugst am AlbisX5970      0 1
      Aeugst am AlbisX6040      0 1
      Aeugst am AlbisX6090      0 1
      Affoltern am AlbisX5240   1 0
      Affoltern am AlbisX5250   1 0
      Affoltern am AlbisX5320   1 0
      Affoltern am AlbisX5470   1 0
      Affoltern am AlbisX5521   1 0
      Affoltern am AlbisX5522   1 0
      Affoltern am AlbisX5710   1 0 ....