Hi Everyone,

I have this data example below where I need to generate a Diff-outcome. The outcome is KW, treat is a dummy indicating that county is treated or not. year is the date of the outcome KW.
So I need a variable that indicates the KW for:

- a treated county before and after treatment
- a control (untreated) county before and after the treatment

But the treatment, as you would see, has been introduced in different periods.

Any help would be appreciated.

Thank you,
Ali









Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str17 county float(year treat) double KW
                 "sierra"    2012 0 1.7300000190734863
"mono"      2010 0  2.115000009536743
"mono"      2011 0  1047.594475159645
"mono"      2016 1  615.0648956298828
"mono"      2012 0  53.47581745147705
"mono"      2014 0 17.968571462631225
"mono"      2013 0  19.12836738586426
"inyo"      2009 0   332.690810918808
"mariposa"  2016 1  9.930999755859375
"mariposa"  2017 1 30.239999771118164
"mariposa"  2015 0  7.427000045776367
"mariposa"  2012 0 141.42100143432617
"mariposa"  2011 0  596.9810292720795
"mariposa"  2010 0   85.7300033569336
"inyo"      2016 0   538.287145614624
"inyo"      2015 0  7.857142925262451
"inyo"      2010 0                  6
"inyo"      2014 0             110.05
"inyo"      2011 0   172.864492893219
"inyo"      2012 0 130.51142597198486
"plumas"    2017 0 2.2899999618530273
"plumas"    2016 0 20.330999851226807
"plumas"    2014 0 14.689000129699707
"plumas"    2013 0 36.129999947547915
"plumas"    2012 0  5.629000186920166
"plumas"    2011 0   87.7210021018982
"plumas"    2010 0               3.36
"plumas"    2009 0               4.73
"colusa"    2009 0 2166.0669903564453
"colusa"    2010 0  2214.139026412964
"colusa"    2011 0 1735.3049488449096
"colusa"    2012 0  2447.334988412857
"colusa"    2016 1  5633.800985813141
"colusa"    2013 0  491.6379928588867
"colusa"    2015 1 2466.3309755325317
"colusa"    2014 0  4003.920999794006
"colusa"    2017 1 3710.9460051059723
"glenn"     2009 0  93.39200065612792
"glenn"     2010 0  65.02400117397309
"glenn"     2017 1 3352.4740171432495
"glenn"     2016 1 2882.8930139541626
"glenn"     2014 0 1505.9709854125977
"glenn"     2011 0  526.4140105819702
"glenn"     2015 1 2276.3009951114655
"glenn"     2013 0 1979.0520255088807
"glenn"     2012 0  981.4779928994179
"lassen"    2017 0 188.26600074768066
"lassen"    2016 0 1137.7200088500977
"lassen"    2015 0  138.7519989013672
"lassen"    2014 0  36.76900100708008
"lassen"    2011 0  77.89299774169922
"lassen"    2010 0             32.175
"amador"    2016 0  210.7160016298294
"amador"    2015 0 126.29799842834473
"amador"    2014 0 18.808000087738037
"amador"    2017 0 2059.2509994506836
"amador"    2013 0  186.4290008544922
"amador"    2012 0  252.5989990234375
"amador"    2009 0                  7
"amador"    2011 0 155.96100211143494
"amador"    2010 0  39.49600019454956
"calaveras" 2015 0  40.20900011062622
"calaveras" 2016 0 154.52699947357178
"calaveras" 2014 0  65.48999977111816
"calaveras" 2017 1  86.69000101089478
"calaveras" 2013 0   65.9020004272461
"calaveras" 2012 0 38.855000534057616
"calaveras" 2011 0 245.75099277496338
"calaveras" 2010 0 26.644999694824218
"calaveras" 2009 0 1.9600000381469727
"tuolumne"  2016 0 179.29499912261963
"tuolumne"  2017 0 148.83900141716003
"tuolumne"  2015 0  17.88599967956543
"tuolumne"  2014 0  64.86000061035156
"sanbenito" 2010 0 318.01400032043455
"tuolumne"  2013 0               70.5
"sanbenito" 2011 0  2410.385025024414
"tuolumne"  2012 0 198.72000122070312
"sanbenito" 2012 0 25.486000537872314
"tuolumne"  2011 0 11.892999649047852
"tuolumne"  2009 0  7.289999771118164
"tuolumne"  2010 0  7.474000205993653
"sanbenito" 2013 0 352.14100074768066
"sanbenito" 2014 0  59.91600036621094
"sanbenito" 2015 0  58.88300132751465
"sanbenito" 2016 0  771.6840028762817
"sanbenito" 2017 1  637.1600160598755
"tehama"    2009 0 30.239999771118164
"tehama"    2010 0 1408.9979998207093
"tehama"    2011 0  1119.916003227234
"tehama"    2016 0  2279.308996319771
"tehama"    2015 0 1661.4869998693466
"tehama"    2012 0 1752.4280173778534
"tehama"    2013 0 3259.2540171051023
"tehama"    2017 0 1602.0799750089645
"tehama"    2014 0  836.8469922542572
"lake"      2016 0 431.91299533843994
"lake"      2017 0 232.24800395965576
"lake"      2015 0 343.82999897003174
"lake"      2014 0 495.46099758148193
end