Dear all,

I am currently working with Stata 16.1 on an event study analysis.
I am having troubles with the xline() option of the command coefplot. While the option yline() works properly, the xline is not displayed in the plot of coefficient.

I apologize for posting a dataset example with 48 observations. I try to reduce their number but when I do, I am not able to estimate model coefficients to be plotted with coefplot.

The metadata of the variables are the following:
cfips: id
treated: treatment dummy
dummy: dependent variable, dummy
state_time_fe: state*year fixed effects

Here is the code I am running:

*Example created with -dataex-
Code:
clear
input str4 cfips float(year treated dummy state_time_fe)
"0101" 1990 1 0  1
"0101" 1992 1 0  2
"0101" 1994 1 0  3
"0101" 1996 1 0  4
"0101" 1998 1 0  5
"0101" 2000 1 0  6
"0101" 2002 1 0  7
"0101" 2004 1 0  8
"0101" 2006 1 0  9
"0101" 2008 1 0 10
"0101" 2010 1 0 11
"0101" 2012 1 0 12
"0101" 2014 1 0 13
"0101" 2016 1 0 14
"0101" 2018 1 0 15
"0101" 2020 1 0 16
"0102" 1990 0 0  1
"0102" 1992 0 0  2
"0102" 1994 0 0  3
"0102" 1996 0 0  4
"0102" 1998 0 0  5
"0102" 2000 0 0  6
"0102" 2002 0 0  7
"0102" 2004 0 0  8
"0102" 2006 0 0  9
"0102" 2008 0 0 10
"0102" 2010 0 1 11
"0102" 2012 0 1 12
"0102" 2014 0 1 13
"0102" 2016 0 1 14
"0102" 2018 0 1 15
"0102" 2020 0 0 16
"0103" 1990 0 0  1
"0103" 1992 0 0  2
"0103" 1994 0 0  3
"0103" 1996 0 0  4
"0103" 1998 0 0  5
"0103" 2000 0 0  6
"0103" 2002 0 0  7
"0103" 2004 0 0  8
"0103" 2006 0 0  9
"0103" 2008 0 0 10
"0103" 2010 0 0 11
"0103" 2012 0 0 12
"0103" 2014 0 0 13
"0103" 2016 0 0 14
"0103" 2018 0 0 15
"0103" 2020 0 0 16
end

*Interaction between the treatment dummy and the year variable:
foreach y in 0 2 4 6 8 {
gen T_199`y'=0
replace T_199`y'=1 if year==199`y'
    
}

foreach y in 00 02 04 06 08 10 12 14 16 18 20{
gen T_20`y'=0
replace T_20`y'=1 if year==20`y'
    
}

*Creating leads and lags for the event study analysis:
local leads_lags_T "T_1990 T_1992 T_1994 T_1996 T_1998 T_2000 T_2002 T_2004 T_2006 T_2008 T_2010 T_2012 T_2014 T_2016 T_2018 T_2020"
foreach var of local leads_lags_T{
    
    gen inter_`var'= `var'*treated
}          

*Estimating the model with the user-written command reghdfe
*ssc install reghdfe
reghdfe dummy inter_T_2020 inter_T_2018 inter_T_2016 inter_T_2014 inter_T_2012 inter_T_2010 inter_T_2008 inter_T_2006 inter_T_2004 inter_T_2002 inter_T_2000 inter_T_1998 inter_T_1996 inter_T_1994 inter_T_1992 inter_T_1990, absorb(state_time_fe) cl(year cfips)

*Plotting coefficients with the user-written command coefplot:
*ssc install coefplot
coefplot, vertical ///
xline (2017, lcolor(magenta)) ///
yline(0, lcolor(blue)) ///
scale(0.8) ///
keep(inter_T_2020 inter_T_2018 inter_T_2016 inter_T_2014 inter_T_2012 inter_T_2010 inter_T_2008 inter_T_2006 inter_T_2004 inter_T_2002 inter_T_2000 inter_T_1998 inter_T_1996 inter_T_1994 inter_T_1992 inter_T_1990) ///
rename(inter_T_2020 = 2020 inter_T_2018 = 2018 inter_T_2016= 2016 inter_T_2014=2014 inter_T_2012=2012 inter_T_2010=2010 inter_T_2008=2008 inter_T_2006=2006 inter_T_2004=2004 inter_T_2002=2002 inter_T_2000=2000  inter_T_1998=1998 inter_T_1996=1996 inter_T_1994=1994 inter_T_1992=1992 inter_T_1990=1990) ///
order(1990 1992 1994 1996 1998 2000 2002 2004 2006 2008 2010 2012 2014 2016  2018 2020) ///
ytitle(Coefficients) ///
xtitle(Year) ///
title("The xline is missing!")


Note that the xline is not displayed even if I change the x value from 2017 to 2016.

Many thanks to anyone who will take a few minutes to help!

Best,
Alessandra Moresi