HI Everyone,

I am using the new -xtdidreg- in Stata 17 to estimate the effects on GDP/capita by a policy treatment. Using these models is straightforward but the problem is I have a treatment time that varies when it happens between country (so not possible to run the granger test or do postestimation commands). Even more complicated is the fact that the treatment varies a lot within a country. It can occur in just one year or two followed by no treatments, or one year with and one year without, followed by a lull followed by a year with it etc. It also frequently occurs in consecutive years - sometimes for a long period of time (e.g. 10-12 years). This is vexing because I would expect these policies to have some short-term effects raising the issue of whether is worth counting "post-treatment" after a 12 year spell, for example. Indeed, it is difficult overall to determine exactly when the "post-treatment" effect technically begins. If it's one year followed by no policy years for many subsequent years, it's easy. But if the treatment lasts a long time or if it's on/off for a while, it's tricky. I don't know if anyone has thoughts on this. I understand it's a "theoretical" question relevant to the literature but thought I would raise it. I was thinking of defining "post-treatment" in several ways to account for this variation to run results to compare.

The more pressing issue is how I can run a granger test or graphically show pre/post treatment effects (i.e. parallel assumptions). Are there any substitutes or workarounds with this kind of data structure? I could define years leading up to treatment (negative values) and years after (positive values) and take the average. But this gets back to this issue of knowing when pre/post treatment even is.

Here is an example of my data. Note that in this case I define "post-treatment as the year after the first treatment ends until the rest of the period (imperfect though it is. I have other ideas here but just one example for simplicity).

Code:
* Example generated by -dataex-. For more info, type help dataex
clear
input str55 country float country_ID str9 ISO int year double GDP_capita float(treat_policy ever_policy) byte(_seq _spell _end) float post_treatment
"Afghanistan" 1 "AFG" 1981                 . 0 1  0 0 0 0
"Afghanistan" 1 "AFG" 1982                 . 0 1  0 0 0 0
"Afghanistan" 1 "AFG" 1983                 . 0 1  0 0 0 0
"Afghanistan" 1 "AFG" 1984                 . 0 1  0 0 0 0
"Afghanistan" 1 "AFG" 1985                 . 0 1  0 0 0 0
"Afghanistan" 1 "AFG" 1986                 . 0 1  0 0 0 0
"Afghanistan" 1 "AFG" 1987                 . 0 1  0 0 0 0
"Afghanistan" 1 "AFG" 1988                 . 0 1  0 0 0 0
"Afghanistan" 1 "AFG" 1989                 . 0 1  0 0 0 0
"Afghanistan" 1 "AFG" 1990                 . 0 1  0 0 0 0
"Afghanistan" 1 "AFG" 1991                 . 0 1  0 0 0 0
"Afghanistan" 1 "AFG" 1992                 . 0 1  0 0 0 0
"Afghanistan" 1 "AFG" 1993                 . 0 1  0 0 0 0
"Afghanistan" 1 "AFG" 1994                 . 0 1  0 0 0 0
"Afghanistan" 1 "AFG" 1995                 . 0 1  0 0 0 0
"Afghanistan" 1 "AFG" 1996                 . 0 1  0 0 0 0
"Afghanistan" 1 "AFG" 1997                 . 0 1  0 0 0 0
"Afghanistan" 1 "AFG" 1998                 . 0 1  0 0 0 0
"Afghanistan" 1 "AFG" 1999                 . 0 1  0 0 0 0
"Afghanistan" 1 "AFG" 2000                 . 0 1  0 0 0 0
"Afghanistan" 1 "AFG" 2001                 . 0 1  0 0 0 0
"Afghanistan" 1 "AFG" 2002 1189.784667657181 0 1  0 0 0 0
"Afghanistan" 1 "AFG" 2003  1235.81006329565 0 1  0 0 0 0
"Afghanistan" 1 "AFG" 2004 1200.278013217345 0 1  0 0 0 0
"Afghanistan" 1 "AFG" 2005 1286.793658939272 0 1  0 0 0 0
"Afghanistan" 1 "AFG" 2006 1315.789117418347 1 1  1 1 0 0
"Afghanistan" 1 "AFG" 2007 1460.825751379395 1 1  2 1 0 0
"Afghanistan" 1 "AFG" 2008 1484.114461325385 1 1  3 1 0 0
"Afghanistan" 1 "AFG" 2009 1758.904476637649 1 1  4 1 0 0
"Afghanistan" 1 "AFG" 2010 1957.029069908116 1 1  5 1 1 0
"Afghanistan" 1 "AFG" 2011 1904.559925655938 0 1  0 0 0 1
"Afghanistan" 1 "AFG" 2012 2075.491614353309 1 1  1 2 0 1
"Afghanistan" 1 "AFG" 2013 2116.465257712514 1 1  2 2 0 1
"Afghanistan" 1 "AFG" 2014 2102.384603759743 1 1  3 2 1 1
"Afghanistan" 1 "AFG" 2015 2068.265904133638 0 1  0 0 0 1
"Afghanistan" 1 "AFG" 2016 2057.067977553294 1 1  1 3 0 1
"Afghanistan" 1 "AFG" 2017 2058.400221069795 1 1  2 3 0 1
"Afghanistan" 1 "AFG" 2018 2033.804388937174 1 1  3 3 1 1
"Albania"     2 "ALB" 1981                 . 0 1  0 0 0 0
"Albania"     2 "ALB" 1982                 . 0 1  0 0 0 0
"Albania"     2 "ALB" 1983                 . 0 1  0 0 0 0
"Albania"     2 "ALB" 1984                 . 0 1  0 0 0 0
"Albania"     2 "ALB" 1985                 . 0 1  0 0 0 0
"Albania"     2 "ALB" 1986                 . 0 1  0 0 0 0
"Albania"     2 "ALB" 1987                 . 0 1  0 0 0 0
"Albania"     2 "ALB" 1988                 . 0 1  0 0 0 0
"Albania"     2 "ALB" 1989                 . 0 1  0 0 0 0
"Albania"     2 "ALB" 1990 4827.318483754909 0 1  0 0 0 0
"Albania"     2 "ALB" 1991 3496.580246100285 0 1  0 0 0 0
"Albania"     2 "ALB" 1992  3265.01742857304 0 1  0 0 0 0
"Albania"     2 "ALB" 1993 3599.027058196382 1 1  1 1 0 0
"Albania"     2 "ALB" 1994 3921.851207130857 1 1  2 1 0 0
"Albania"     2 "ALB" 1995 4471.871069987153 1 1  3 1 0 0
"Albania"     2 "ALB" 1996 4909.228104923629 1 1  4 1 1 0
"Albania"     2 "ALB" 1997 4400.577827365508 0 1  0 0 0 1
"Albania"     2 "ALB" 1998 4819.387533604832 1 1  1 2 0 1
"Albania"     2 "ALB" 1999 5475.169135425933 1 1  2 2 0 1
"Albania"     2 "ALB" 2000 5893.136232563291 1 1  3 2 0 1
"Albania"     2 "ALB" 2001 6441.853452386757 1 1  4 2 0 1
"Albania"     2 "ALB" 2002 6754.536003013315 1 1  5 2 0 1
"Albania"     2 "ALB" 2003 7154.784825121795 1 1  6 2 0 1
"Albania"     2 "ALB" 2004 7580.629091086668 1 1  7 2 0 1
"Albania"     2 "ALB" 2005 8040.878716781119 1 1  8 2 0 1
"Albania"     2 "ALB" 2006  8569.19111251045 1 1  9 2 0 1
"Albania"     2 "ALB" 2007 9150.518747043685 1 1 10 2 0 1
"Albania"     2 "ALB" 2008 9912.577242429737 1 1 11 2 1 1
"Albania"     2 "ALB" 2009 10313.92644130402 0 1  0 0 0 1
"Albania"     2 "ALB" 2010 10749.48744816581 0 1  0 0 0 1
"Albania"     2 "ALB" 2011 11052.79046351362 0 1  0 0 0 1
"Albania"     2 "ALB" 2012 11227.99448719723 0 1  0 0 0 1
"Albania"     2 "ALB" 2013 11361.29367637877 0 1  0 0 0 1
"Albania"     2 "ALB" 2014  11586.8637666424 1 1  1 3 1 1
"Albania"     2 "ALB" 2015 11878.48809334456 0 1  0 0 0 1
"Albania"     2 "ALB" 2016 12291.87337739279 0 1  0 0 0 1
"Albania"     2 "ALB" 2017 12770.97503708106 0 1  0 0 0 1
"Albania"     2 "ALB" 2018  13323.7533559132 0 1  0 0 0 1
"Argentina"   3 "ARG" 1981                 . 0 1  0 0 0 0
"Argentina"   3 "ARG" 1982                 . 0 1  0 0 0 0
"Argentina"   3 "ARG" 1983                 . 1 1  1 1 1 0
"Argentina"   3 "ARG" 1984                 . 0 1  0 0 0 1
"Argentina"   3 "ARG" 1985                 . 1 1  1 2 0 1
"Argentina"   3 "ARG" 1986                 . 1 1  2 2 0 1
"Argentina"   3 "ARG" 1987                 . 1 1  3 2 0 1
"Argentina"   3 "ARG" 1988                 . 1 1  4 2 1 1
"Argentina"   3 "ARG" 1989                 . 0 1  0 0 0 1
"Argentina"   3 "ARG" 1990 14144.76367018504 1 1  1 3 1 1
"Argentina"   3 "ARG" 1991  15221.7921466357 0 1  0 0 0 1
"Argentina"   3 "ARG" 1992 16209.32597721907 1 1  1 4 0 1
"Argentina"   3 "ARG" 1993 17312.03457467553 1 1  2 4 0 1
"Argentina"   3 "ARG" 1994 18092.02081388348 1 1  3 4 0 1
"Argentina"   3 "ARG" 1995 17362.52180256983 1 1  4 4 0 1
"Argentina"   3 "ARG" 1996 18104.69780949586 1 1  5 4 0 1
"Argentina"   3 "ARG" 1997 19347.53704007929 1 1  6 4 0 1
"Argentina"   3 "ARG" 1998 19866.24505296556 1 1  7 4 0 1
"Argentina"   3 "ARG" 1999 18981.16838273078 1 1  8 4 0 1
"Argentina"   3 "ARG" 2000 18625.28355378113 1 1  9 4 0 1
"Argentina"   3 "ARG" 2001 17610.75538632018 1 1 10 4 0 1
"Argentina"   3 "ARG" 2002 15523.03877631015 1 1 11 4 0 1
"Argentina"   3 "ARG" 2003 16714.67013318461 1 1 12 4 0 1
"Argentina"   3 "ARG" 2004  18032.6114274365 1 1 13 4 0 1
end
format %ty year
This is the code I use to run my models (without any controls for simplicity)
Code:
xtdidreg (GDP_capita  i.post_treatment i.ever_policy) (treat_policy), group(country_ID) time(year) nogteffects