0

I am running a fixed effects regression in R where the unit of analysis is the individual respondent. I want to implement region and Year fixed effects for the regression. I have used the within estimator in the plm function of package plm, but this does not work, because it rejects the regression, claiming there are duplicates. However, there are no duplicate units, the data are all individual respondents. It is not panel data, as respondents are only surveyed once, but plm wants c("ID", "Time"). My desired fixed effect is not unit-year, because the respondents are only surveyed once, it should be region, year. However, because there are multiple respondents within one region, this is rejected based on the alleged duplicates.

How can I add region-year fixed effects when my unit of analysis is below the region level.

Updating to add code for context:

My regression is as follows

regression <- plm(government ~ (sex + age + factor(education) + IV3)*incumbency + (sex + age + factor(education) + IV2)*incumbency + (sex + age + factor(education) + IV3)*incumbency, index = c("region", “year”), model = "within", data = data)

government is a continuous numerical measure of government satisfaction.

region is a categorical variable, and year is the date of the respondent interview

The individual units are respondents

IV1, IV2, and IV3 are all dummy variables for which group the individual respondent fits into (mutually exclusive)

incumbency is a dummy variable for whether the individuals’ preferred party is in power.

The data is not panel data, so there are multiple respondents within the region and year but they are unique respondents.

Because there are more than one respondent within each region for the same time I receive the following error:

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

Error in pdim.default(index[[1L]], index[[2L]]) : duplicate couples (id-time)

There are no duplicates, however, as I have already run both the unique and distinct functions to remove them. I assume it is treating the individuals within the same region as duplicates, but they are not. I have used different settings (ie.effect = “twoways”) but this has not changed anything. How can I implement a region and year fixed effect for these, when there are multiple individuals within one region? (ie. regionis not the unit of analysis, the individual within the region is the unit of analysis)

flâneur
  • 633
  • 2
  • 8

1 Answers1

0

It is very hard to diagnose your problem because you do not supply a MINIMAL REPRODUCIBLE EXAMPLE

This does not exactly answer your question, but if all you need is a fixed effects model, I would strongly encourage you to check out the fixest package: https://lrberge.github.io/fixest/

It is much faster and feature-complete for fixed effects models.

library(fixest)
dat <- read.csv("https://vincentarelbundock.github.io/Rdatasets/csv/plm/EmplUK.csv")
mod <- feols(wage ~ emp + capital | firm + year, data = dat)
summary(mod)
#> OLS estimation, Dep. Var.: wage
#> Observations: 1,031 
#> Fixed-effects: firm: 140,  year: 9
#> Standard-errors: Clustered (firm) 
#>          Estimate Std. Error  t value Pr(>|t|)    
#> emp     -0.081695   0.053307 -1.53254 0.127663    
#> capital  0.181507   0.082138  2.20978 0.028757 *  
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> RMSE: 1.80889     Adj. R2: 0.879981
#>                 Within R2: 0.012178
Vincent
  • 15,809
  • 7
  • 37
  • 39
  • Regards speed, plm catched up quite a lot since version 2.6-0 (making use of pkg 'collapse' and - if installed additionally - fixest's fast projection for fixed effects). A benchmark for the speed-up is given in `?plm::plm.fast`. – Helix123 Mar 30 '22 at 18:12
  • Thanks, I was not aware. This is very good news! – Vincent Mar 30 '22 at 19:18