I am conducting a study to estimate the effect of Medicaid expansion on the uninsured rate using a classic Difference-in-Differences (DID) design with two-way fixed effects (twfe) model. My mathematical model is as follows:

$$ UNINS_{ist} = \alpha_s + \delta_t + \beta EXPANSION_{ist} + \epsilon_{ist} $$

In this model:

$UNINS_{ist}$ is a binary variable indicating whether an individual in the survey is uninsured (1) or insured (0) in state $s$ and year $t$. $\alpha_s$ represents state fixed effects, capturing time-invariant differences across states. $\delta_t$ represents time fixed effects, capturing common time trends across all states. $\beta$ is the parameter of interest, representing the causal effect of Medicaid expansion on the uninsured rate. $EXPANSION_{ist}$ is a binary treatment variable that equals 1 for states that adopted Medicaid expansion and 0 for states that did not. $\epsilon_{ist}$ is the error term accounting for unobserved factors and random variation.

I have data from the American Community Survey (ACS) for the years 2011 to 2019, which consists of repeated cross-sectional data. Here are the top 15 observations of my dataset:

enter image description here

To estimate this model, I am using the feols command from the fixest package in R. However, when running the feols command with the following code:

reg1 = feols(UNINS ~ expansion | ST + YEAR ,  data = Data) # state and year fixed effect

I encounter the following error message:

Error: in feols(UNINS ~ expansion | StateN, data = Data):
 The only variable 'expansion' is collinear with the fixed effects. In such circumstances, the estimation
is void.

I've done the same thing using stata running the code

reghdfe UNINS expansion , absorb(ST YEAR) cluster(ST)

eventhough I got the regression result I got the following error

note: expansion is probably collinear with the fixed effects (all partialled-out values are close to z
> ero; tol = 1.0e-09)
(MWFE estimator converged in 4 iterations)
note: expansion omitted because of collinearity

I am seeking guidance on how to address this issue and estimate the TWFE model.

I suspect that could be due to the fact that my data is repeated cross-sections and maybe by aggregating the variable by calculating mean of each variable at state and year might help. But, this might be problematic with the categorical variable like race or education level.

  • $\begingroup$ Welcome. Please describe, in detail, how you coded your treatment variable? Did states adopt at different times? $\endgroup$ Commented May 18, 2023 at 2:31
  • $\begingroup$ @ThomasBilach Thank you 😊 That's correct. The policy was introduced in 2014, and different states adopted it at various times. My dataset covers the period from 2011 to 2019. In the dataset, the treatment variable is coded as zero for states that did not adopt the policy during the 2011-2019 timeframe. For states that adopted the policy between 2014 and 2019, the treatment variable is coded as one. For example, for states that adopted the policy in 2014, the treatment variable is zero for years prior to 2014 and one for years from 2014 onwards. $\endgroup$
    – Shadi
    Commented May 18, 2023 at 3:56
  • $\begingroup$ @ThomasBilach Oh wow, thanks for asking that question. I totally missed a mistake in my treatment variable. The coding was supposed to be just as I explained earlier, but it looks like I messed up somewhere because I see that treatment is set to 1 for the year 2011, which is not right. I apologize for that. The correct coding should be 0 for years before 2014 and 1 for years from 2014 onwards for states that adopted the policy. I'll fix this coding error, and I'm hopeful that it will resolve the issue. Thanks again for catching that mistake! $\endgroup$
    – Shadi
    Commented May 18, 2023 at 4:07
  • $\begingroup$ Correct. Just be careful because a simply interaction term doesn't always return what you want. The variable should account for the "staggered" nature of the expansion policy. My answer should address the problem. $\endgroup$ Commented May 19, 2023 at 2:41

2 Answers 2


It appears the fixed effects fully absorb your policy variable. This may boil down to a simple coding error.

$EXPANSION_{ist}$ is a binary treatment variable that equals 1 for states that adopted Medicaid expansion and 0 for states that did not

Not quite.

I have two concerns. First, the subscripts suggest you have a policy that varies at the level of the individual. But, in fact, this is a state level policy change, which exhibits variation across states and time. Thus, it should be $s$- and $t$-subscripted (e.g., $EXPANSION_{st}$). In short, just drop the $i$ and you're good to go.

Second, this variable is not 1 for states that adopt, 0 otherwise. If I am taking this literally, then you instantiated a policy dummy with no variation over time; software would definitely drop it in the presence of the state fixed effects. To code it up properly, the variable should "switch on" (i.e., change from 0 to 1) when a treated state $s$ adopts in year $t$, 0 otherwise. In other words, it should only change from 0 to 1 in those state-year combinations when the policy is active, and strictly 0 otherwise. For example, say California adopts in 2015. For this state, it is 0 in the pre-period, then changes from 0 to 1 in 2015 and stays equal to 1 until 2019. Similarly, if Colorado adopt in 2018, it equals 0 from 2011 through 2017, then changes from 0 to 1 in 2018 and stays equal to 1. For the non-adopters, they consistently equal 0; we do not know when any non-expanding state would have adopted. Note how we have variation across states and time, whereas your earlier description suggests the variable will only equal 1 for "treated" states (i.e., equal to 1 in all time periods). The language matters, as I suspect this is what went awry. As a final word, I highly recommend comparing TWFE with methods proposed by, e.g., Callaway and Sant'Anna 2021.

I suspect that could be due to the fact that my data is repeated cross-sections and maybe by aggregating the variable by calculating mean of each variable at state and year might help.

This is not necessary, though nothing is stopping you from aggregating your data up to a higher geographic level. By aggregating the data up to the state level you create a "pseudo-panel" of sorts, but this will not absolve you of the collinearity issue. Note, DiD methods may be used with repeated cross-sections of individuals, so long as you have a state level policy. In short, keep the repeated cross-sections of individuals and focus on the coding of the policy variable.


Thanks to @Thomas' question, I realized that the treatment variable in my dataset wasn't capturing the dynamic nature of the treatment as I had thought.To address this, I created a dynamic treatment variable by multiplying the post variable (indicating the occurrence of an event) with the expansion variable (representing the expansion indicator). The resulting variable, treat, captures the interaction between the event occurrence and the expansion.

Data <- Data %>% 
  mutate(treat = post * expansion)


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.