# group fixed-effects, not individual-fixed effects using plm in R

I am analyzing some data to evaluate the impact (causal effect) of a program that is delivered at group level (a village). The outcome of interest is measured at the individual level (individuals within the villages). Program placement was not random, but we have several observations before and after the intervention for both, treatment and control villages. So I want to use a difference-in-differences approach to estimate the impact of the program, so as to try to control for unobservable factors (and hence captured by the error term) that may have influenced the placement of the program. So I want to use the extension for multiple periods and multiple groups (Bertrand, Duflo & Mullainathan, 2004; Hansen, 2007) and following Imbens and Wooldridge (2008) I want to estimate an equation like this:

$y_{i} = \alpha + \sum_{t=1}^T \beta_t \cdot 1_{T_i=t} + \gamma \cdot 1_{G_i=treatment} + \tau_{did} \cdot I_i + \epsilon_i$

"where $I_i$ is now an indicator for unit i being in a group and time period that was exposed to the treatment"

Since my data is a panel of villages and not of individuals, the above equation may have at least two problems. First, it does not recognize that the observations are grouped (clustered?) in villages; and second, it ignores that the observations in different time periods come from the same villages (although not from the same individuals).

So I thought, ok, what I should do is probably to use panel-data methods, in particular, the fixed-effects (within) estimator, including fixed effects at the village level (so as to control for the unobserved factors at the village-level that may affect both the outcome and the participation in the program).

Here's my first question: is it the way to go?, or should I use a different approach.

Ok, now I am trying to do this using R and the plm package. I use a command like this:

plm(formula = y ~ gtreat + time + impact, data = df, index=c("ids", "time"), model="within")

It does not work, though. It throws an error saying:

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

I have been trying to find a solution and it seems it is not at all possible with the plm package to have duplicate observations for time and id (see for example this post https://stackoverflow.com/questions/15960129/r-plm-year-fixed-effects-year-and-quarter-data). I my case, these duplication is natural because I have outcomes measured at the individual level, but my panel is not at the individual level but at village level.

So here's my second question: Is there any workaround to this?, How can I estimate a panel data fixed-effects model (within estimator) in R, given the data I have? (some of the solutions I've found out there consist in aggregating the data at the village level; that works for sure, but it seems to me that it is just ignoring a lot of valuable information and variability at the individual level. In addition, my sample is big in the individual observations -nearly 10,000-, but not so much at the village level -we only have 14 villages, 7 treatment and 7 control-)

Many thanks in advance for any thoughts/answers to any of my questions.

I have worked on similar projects and am confronting one right now. The way that we handle this is to put in a fixed effect for each village and then to cluster the standard errors by village. This is not a perfect solution, but is fairly standard practice.

The plm package in R and xtreg ..., fe command in Stata, and the traditional fixed effect (within) estimator are designed to follow individuals. I believe one of the names for the method that you want is called a hierarchical linear model.

The simplest implementation in R would be something like

myLM <- lm(y ~ x + v v.t*t, data=df)


where y is the outcome of interest, x is some set of controls, v is a factor variable for the villages, v.t is a binary (factor) variable indicating whether a village was treated, and t is an indicator for pre-post treatment.

For standard inference, it is typical and recommended to produce clustered standard errors use either the multiwayvcov package or clusterSEs package.

Another method for inference, and the preferred method in Bertrand, Duflo & Mullainathan, 2004 is to perform a placebo test, where you vary "treatment" across all villages, form an empirical CDF, and see where the effect of treatment for the truly treated village sits in that distribution. Note that this is roughly the same method recommended for inference with synthetic controls of Abadie, Diamond, and Hainmueller, and has ties back to Fisher's 1935 text.