<p>As you answered already, this is related to the fact that you are using the a varying base period. You want to use the universal base period. By default, Stata uses a  &quot;short-gap-varying base&quot;. You can re-estimate using the long2 option in the csdid command.</p>

CC BY-SA 4.0
2023-02-07T12:57:16.927Z
2023-02-07T12:57:16.927Z
aliki43
<p>As it turns out, the issue was resolved when setting the reference period as &quot;universal&quot; instead of &quot;varying&quot;, which is a problem when you have long-running linear pretrends as in this example. Here is a <a href="https://bcallaway11.github.io/posts/event-study-universal-v-varying-base-period" rel="nofollow noreferrer">link</a> with more information.</p>

CC BY-SA 4.0
2023-01-16T17:23:06.610Z
2023-01-16T17:23:06.610Z
Oberberg
<p>I have noticed that in some of my event study regressions, depending on which R package I use I get different results regarding the violation of parallel pretrends. Specifically, I ran an event study regression using the &quot;fixest&quot; package, which indicated that the treatment and control groups were not on parallel trends before treatment, whereas the &quot;did&quot; package by <a href="https://bcallaway11.github.io/did/articles/did-basics.html" rel="noreferrer">Callaway and Sant'Anna</a> showed that both groups were on the same trend pre-treatment, i.e. the coefficients were around zero. All treated units were treated at the same time, so it couldn't be because of staggered treatment effects.</p>
<p>I then generated some other data to see whether this issue was limited to my dataset. I generated a dataset of &quot;treated&quot; and &quot;untreated&quot; observations over 10 periods, with 100 observations per group (2000 observations in total), where the observations of the untreated group are around zero in every period, but the observations of the treated group linearly grow from -5 to 5 over the 10 periods (see plot).</p>
<p><a href="https://i.sstatic.net/UjX1n.png" rel="noreferrer"><img src="https://i.sstatic.net/UjX1n.png" alt="enter image description here" /></a></p>
<p>I would therefore expect the coefficients of the event study regression to also indicate a violation of parallel trends, with no change in trend at the time of treatment (5). Indeed, the fixest package shows exactly this:</p>
<p><a href="https://i.sstatic.net/sjyG5.png" rel="noreferrer"><img src="https://i.sstatic.net/sjyG5.png" alt="enter image description here" /></a></p>
<p>However, when I run the regression in the did package, I get this:</p>
<p><a href="https://i.sstatic.net/3KYav.png" rel="noreferrer"><img src="https://i.sstatic.net/3KYav.png" alt="enter image description here" /></a></p>
<p>where for some reasons the pre-trends are just filtered out. Does anyone have any idea what's happening here? I tried to figure it out from the <a href="https://www.sciencedirect.com/science/article/pii/S0304407620303948?via%3Dihub" rel="noreferrer">publication</a>, but I couldn't find anything that would apply to this situation. Here's the R code to reproduce the example:</p>
<pre><code>library(did)
library(ggplot2)

## Generate data
period        &lt;- rep(1:10, 200)
id            &lt;- rep(1:200, each = 10)
group         &lt;- rep(0:1, each = 1000)
values0       &lt;-  0 + rnorm(1000, mean = 0, sd = 1)
values1       &lt;-  period[1001:2000] - 5 + rnorm(1000, mean = 0, sd = 1)
values        &lt;- c(values0, values1)
first_treated &lt;- rep(c(0,6), each = 1000)
df            &lt;- data.frame(cbind(period, id, group, values, first_treated))

## Plot data
ggplot(df, aes(period, values, colour = group)) +
  geom_point(alpha = 0.3) +
  theme_classic()

## Run fixest estimation
iplot(feols(values ~ i(period, group, ref = c(5)), 
      data=df))

## Run did estimation
did_test &lt;- att_gt(yname = &quot;values&quot;,
                    idname = &quot;id&quot;,
                    tname = &quot;period&quot;,
                    gname = &quot;first_treated&quot;,
                    data = df)
did_test &lt;- aggte(did_test, type = &quot;dynamic&quot;, na.rm = TRUE)
ggdid(did_test)
</code></pre>

<econometrics><r>
Parallel pretrends in Callaway Sant'Anna "did" event study package
Oberberg
# Parallel pretrends in Callaway Sant'Anna "did" event study package

(Asked by: username_0 on 2023-01-11)

I have noticed that in some of my event study regressions, depending on which R package I use I get different results regarding the violation of parallel pretrends. Specifically, I ran an event study regression using the "fixest" package, which indicated that the treatment and control groups were not on parallel trends before treatment, whereas the "did" package by Callaway and Sant'Anna showed that both groups were on the same trend pre-treatment, i.e. the coefficients were around zero. All treated units were treated at the same time, so it couldn't be because of staggered treatment effects.
I then generated some other data to see whether this issue was limited to my dataset. I generated a dataset of "treated" and "untreated" observations over 10 periods, with 100 observations per group (2000 observations in total), where the observations of the untreated group are around zero in every period, but the observations of the treated group linearly grow from -5 to 5 over the 10 periods (see plot).

I would therefore expect the coefficients of the event study regression to also indicate a violation of parallel trends, with no change in trend at the time of treatment (5). Indeed, the fixest package shows exactly this:

However, when I run the regression in the did package, I get this:

where for some reasons the pre-trends are just filtered out. Does anyone have any idea what's happening here? I tried to figure it out from the publication, but I couldn't find anything that would apply to this situation. Here's the R code to reproduce the example:
library(did)
library(ggplot2)

## Generate data
period        <- rep(1:10, 200)
id            <- rep(1:200, each = 10)
group         <- rep(0:1, each = 1000)
values0       <-  0 + rnorm(1000, mean = 0, sd = 1)
values1       <-  period[1001:2000] - 5 + rnorm(1000, mean = 0, sd = 1)
values        <- c(values0, values1)
first_treated <- rep(c(0,6), each = 1000)
df            <- data.frame(cbind(period, id, group, values, first_treated))

## Plot data
ggplot(df, aes(period, values, colour = group)) +
  geom_point(alpha = 0.3) +
  theme_classic()

## Run fixest estimation
iplot(feols(values ~ i(period, group, ref = c(5)), 
      data=df))

## Run did estimation
did_test <- att_gt(yname = "values",
                    idname = "id",
                    tname = "period",
                    gname = "first_treated",
                    data = df)
did_test <- aggte(did_test, type = "dynamic", na.rm = TRUE)
ggdid(did_test)

**Tags:** econometrics, r

---

## 2 answers

### Answer by username_0 on 2023-01-16. Score: 2 | Accepted answer

As it turns out, the issue was resolved when setting the reference period as "universal" instead of "varying", which is a problem when you have long-running linear pretrends as in this example. Here is a [link](https://bcallaway11.github.io/posts/event-study-universal-v-varying-base-period) with more information.


---

### Answer by username_1 on 2023-02-07. Score: 1

As you answered already, this is related to the fact that you are using the a varying base period. You want to use the universal base period. By default, Stata uses a "short-gap-varying base". You can re-estimate using the long2 option in the csdid command.


---

