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.