Hi All
I am trying to generate the event study style output graph based on the SDID command. I have a balanced panel data of GDP variables at county level between 2000 and 2021 that data looks like this:
The variable treated=1 for treated counties after the treatment begin in 2016 (pre-treat period: 2000-2015, treatment year 2016 and post-treatment period: 2017-2021) and the main dependent variable I am using is lnGDP
I follows the code as listed on Clarke et al(2023, pp. 25-29) (link: https://docs.iza.org/dp15907.pdf) and the code are as follows:

The graph I generated is very weird as shown above with the point estimates all below zero which is unlikely given there should not be any treatment before the treatment year, and after the treatment the effect should be positive but insignificant as generated from the sdid command. Furthermore, the confidence interval seems to be very off. I am wondering if I made any mistakes when using the command. Any advice would be most appreciated!
Best regards!
Juncheng Lyu
I am trying to generate the event study style output graph based on the SDID command. I have a balanced panel data of GDP variables at county level between 2000 and 2021 that data looks like this:
Code:
* Example generated by -dataex-. For more info, type help dataex clear input int year double(GDP GDP_1 GDP_2 GDP_3) long countyid double(lnGDP lnGDP_1 lnGDP_2 lnGDP_3) float treated 2000 57330 9992 26791 20553 130001 10.956579208374023 9.209540367126465 10.195821762084961 9.93076229095459 0 2000 108156 19591 55215 33799 130004 11.591329574584961 9.88282585144043 10.918990135192871 10.428186416625977 0 2000 159932 45962 66251 47719 130006 11.982503890991211 10.735569953918457 11.101205825805664 10.77308464050293 0 2000 262494 86493 80428 95573 130009 12.477983474731445 11.367818832397461 11.295117378234863 11.467645645141602 0 2000 171580 29340 97228 45012 130016 12.052804946899414 10.286706924438477 11.484813690185547 10.71468448638916 0 2000 304941 70857 128411 105673 130018 12.627873420715332 11.168418884277344 11.762990951538086 11.56810474395752 0 2000 95507 32254 38270 26240 130020 11.466955184936523 10.381397247314453 10.552421569824219 10.175040245056152 0 2000 63893 19752 24899 19242 130024 11.06496524810791 9.891010284423828 10.122583389282227 9.864850997924805 0 2000 117247 18516 72988 25743 130031 11.672038078308105 9.826390266418457 11.198050498962402 10.15591812133789 0 2000 166000 43911 81459 40630 130032 12.019742965698242 10.689920425415039 11.307854652404785 10.612261772155762 0 2000 81309 17045 41414 22850 130034 11.306012153625488 9.743612289428711 10.63137435913086 10.03670597076416 0 2000 179829 45968 84613 54568 130040 12.099761962890625 10.735700607299805 11.345843315124512 10.90720272064209 0 2000 167623 36450 67037 64136 130042 12.029472351074219 10.50369644165039 11.11299991607666 11.068760871887207 0 2000 199966 39599 69586 90781 130043 12.205903053283691 10.586559295654297 11.15031909942627 11.416205406188965 0 2000 116080 37346 40230 38504 130045 11.66203498840332 10.52798080444336 10.602368354797363 10.558517456054688 0 2000 98757 17754 42633 38370 130049 11.500417709350586 9.7843656539917 10.660384178161621 10.555030822753906 0 2000 136315 37031 49181 51046 130051 11.822723388671875 10.519510269165039 10.803262710571289 10.840482711791992 0 2000 270101 82085 71955 116061 130054 12.506550788879395 11.315510749816895 11.183795928955078 11.661870956420898 0 2000 382241 35383 174169 173384 420001 12.853806495666504 10.473986625671387 12.067781448364258 12.063263893127441 0 2000 271000 78388 106892 85720 420007 12.50987434387207 11.269426345825195 11.579574584960938 11.358841896057129 0 2000 226500 81756 73744 71000 420008 12.330500602722168 11.311494827270508 11.208354949951172 11.170434951782227 0 2000 102335.99999999999 43758 24672 33906 420013 11.536016464233398 10.686429977416992 10.113424301147461 10.431346893310547 0 2000 166072 38556 60327 67189 420016 12.020176887512207 10.559866905212402 11.007534980773926 11.115264892578125 0 2000 82124 38054 22987 21803 420017 11.315985679626465 10.546761512756348 10.042684555053711 9.989803314208984 0 2000 65598 36938 12291 16369 420018 11.091300010681152 10.516996383666992 9.416622161865234 9.703145027160645 0 2000 322031 67913 159189 94929 420019 12.682403564453125 11.125982284545898 11.9778470993042 11.460884094238281 0 2000 224130 65621 99637 58873 420020 12.319981575012207 11.09165096282959 11.509288787841797 10.983138084411621 0 2000 178947 72233 73250 33465 420021 12.094844818115234 11.187652587890625 11.20163345336914 10.418255805969238 0 2000 409323 97913 138170 118443 420022 12.922260284423828 11.49183464050293 11.8362398147583 11.6821870803833 0 2000 83482 44221 13288 25973 420023 11.332386016845703 10.696954727172852 9.494616508483887 10.164813041687012 0 2000 141161 47326 44572 49263 420024 11.857656478881836 10.764815330505371 10.70486068725586 10.80492877960205 0 2000 237592 54028 129532 54032 420025 12.378310203552246 10.897257804870605 11.771683692932129 10.897332191467285 0 2000 420985 80977 179999 153436 420026 12.950352668762207 11.301920890808105 12.100706100463867 11.941039085388184 0 2000 529224 147454 208186 173584 420028 13.179166793823242 11.90127182006836 12.246187210083008 12.064416885375977 0 2000 62454 24666 16645 21143 430006 11.04218578338623 10.113181114196777 9.719864845275879 9.959064483642578 0 2000 288132 84482 113386 90264 430008 12.571173667907715 11.344293594360352 11.638553619384766 11.410493850708008 0 2000 284060 110105 80709 93246 430010 12.556941032409668 11.609189987182617 11.298604965209961 11.44299602508545 0 2000 263175 115473 51443 96259 430012 12.480574607849121 11.656791687011719 10.84822940826416 11.474798202514648 0 2000 106067 47296 30828 27943 430015 11.571825981140137 10.764181137084961 10.33617877960205 10.237921714782715 0 2000 42850 15795 10976 16079 430017 10.665460586547852 9.667448997497559 9.303466796875 9.685269355773926 0 2000 74155 33275 12807 28073 430018 11.213912963867188 10.412561416625977 9.457747459411621 10.242563247680664 0 2000 137071 47686 42673 46712 430021 11.828254699707031 10.772393226623535 10.661321640014648 10.75175666809082 0 2000 128861 62369 35046 31446 430022 11.76648998260498 11.040823936462402 10.46441650390625 10.356026649475098 0 2000 264034 61648 147758 54628 430023 12.483833312988281 11.029195785522461 11.90333080291748 10.908302307128906 0 2000 57254 23987 17163 16104 430035 10.955252647399902 10.085267066955566 9.750511169433594 9.686822891235352 0 2000 209053 82421 62482 64150 430036 12.250343322753906 11.319595336914063 11.042634010314941 11.068979263305664 0 2000 277986 86041 99561 92384 430037 12.53532600402832 11.362579345703125 11.508525848388672 11.433709144592285 0 2000 142452 40705 47491 54256 130003 11.86676025390625 10.614106178283691 10.768295288085938 10.901469230651855 0 2000 147764 53030 50560 44174 130007 11.903371810913086 10.878613471984863 10.830916404724121 10.695891380310059 0 2000 176547 45318 52081 79148 130008 12.081342697143555 10.72145938873291 10.860555648803711 11.279074668884277 0 2000 36369 15603 6010 15092 130014 10.501472473144531 9.655218124389648 8.701180458068848 9.621919631958008 0 2000 44447 7659 23251 13555 130015 10.70205307006836 8.943636894226074 10.05410385131836 9.514511108398438 0 2000 136540 28218 47631 60691 130019 11.824373245239258 10.24771499633789 10.771239280700684 11.013550758361816 0 2000 63355 19248 18056 26051 130022 11.056509017944336 9.86516284942627 9.801233291625977 10.167811393737793 0 2000 83842 33935 22517 27390 130023 11.336688995361328 10.432202339172363 10.022026062011719 10.217933654785156 0 2000 46609 19152 10097 17360 130033 10.74954891204834 9.860162734985352 9.219993591308594 9.761923789978027 0 2000 99890 12859 43222 42401 130037 11.511824607849121 9.461799621582031 10.674104690551758 10.654927253723145 0 2000 125905 25716 37196 62993 130039 11.74328327178955 10.154869079589844 10.523956298828125 11.050779342651367 0 2000 88085 28691 29345 30049 130046 11.38605785369873 10.264338493347168 10.286877632141113 10.310585021972656 0 2000 73348 23267 18735 31346 130048 11.202970504760742 10.054791450500488 9.838149070739746 10.352842330932617 0 2000 125210 35238 29264 60708 130050 11.737747192382813 10.469880104064941 10.284112930297852 11.01383113861084 0 2000 141386 47451 56487 37448 130052 11.859249114990234 10.76745319366455 10.941765785217285 10.530708312988281 0 2000 195550 99944 52015 43591 420004 12.183571815490723 11.512365341186523 10.85928726196289 10.682605743408203 0 2000 126173 60870 35420 29883 420005 11.74540901184082 11.016495704650879 10.475031852722168 10.305045127868652 0 2000 101186 47540 23676 29970 420009 11.524715423583984 10.769327163696289 10.072216987609863 10.307951927185059 0 2000 156765 67089 39444 50232 420010 11.962503433227539 11.113775253295898 10.582636833190918 10.824407577514648 0 2000 163009.99999999997 72348 49682 40980 420011 12.001566886901855 11.18924331665039 10.813398361206055 10.62083911895752 0 2000 282725 96866 88058 97801 420012 12.552229881286621 11.481083869934082 11.385750770568848 11.490690231323242 0 2000 105954 42461 34277 29216 420014 11.570760726928711 10.656341552734375 10.442230224609375 10.282471656799316 0 2000 78239 34768 26195 17276 420027 11.267523765563965 10.456452369689941 10.173323631286621 9.757073402404785 0 2000 55750 20981 20252 14518 430003 10.928632736206055 9.951372146606445 9.916008949279785 9.583144187927246 0 2000 76233 24689 20628 30905 430004 11.241549491882324 10.114112854003906 9.934404373168945 10.33867359161377 0 2000 26139 11627 4717 9795 430005 10.171183586120605 9.361084938049316 8.458928108215332 9.189627647399902 0 2000 87711 42154 19317 26240 430020 11.381802558898926 10.64908504486084 9.868741035461426 10.175040245056152 0 2000 57881 26623 13246 18012 430024 10.966144561767578 10.189530372619629 9.491451263427734 9.79879379272461 0 2000 59598 22728 21586 15284 430031 10.995377540588379 10.031352996826172 9.9798002243042 9.634561538696289 0 2000 121223 46485 43386 31352 430040 11.705387115478516 10.746885299682617 10.677891731262207 10.353033065795898 0 2001 55536 8426 25700 21410 130001 10.924786567687988 9.039077758789063 10.15424633026123 9.971612930297852 0 2001 116275 20292 60779 35204 130004 11.663713455200195 9.91798210144043 11.014999389648438 10.468914985656738 0 2001 174533 52388 69491 52654 130006 12.069869041442871 10.866433143615723 11.14895248413086 10.87149715423584 0 2001 283670 88499 90840 104331 130009 12.555566787719727 11.390746116638184 11.416854858398438 11.555323600769043 0 2001 169632 29601 94352 45679 130016 12.041386604309082 10.295563697814941 11.454788208007813 10.72939395904541 0 2001 336004 74237 143033 118734 130018 12.724878311157227 11.215018272399902 11.870830535888672 11.684640884399414 0 2001 81538 29179 29901 22458 130020 11.30882453918457 10.281204223632813 10.305646896362305 10.019402503967285 0 2001 54857 12582 21908 20367 130024 10.912485122680664 9.440022468566895 9.994606971740723 9.921670913696289 0 2001 127638 20321 78892 28425 130031 11.756953239440918 9.91940975189209 11.275835037231445 10.255023956298828 0 2001 176578 48995 83733 43850 130032 12.081518173217773 10.799473762512207 11.33538818359375 10.688529968261719 0 2001 81057 17032 38722 25303 130034 11.302907943725586 9.742849349975586 10.564163208007813 10.138678550720215 0 2001 190817 41827 88664 60326 130040 12.159070014953613 10.641297340393066 11.392609596252441 11.007518768310547 0 2001 179500 37623 72232 69645 130042 12.097930908203125 10.535370826721191 11.187638282775879 11.151165962219238 0 2001 182805 19699 68468 94638 130043 12.116175651550293 9.888322830200195 11.134121894836426 11.45781421661377 0 2001 125788 39007 44071 42710 130045 11.742353439331055 10.57149600982666 10.693556785583496 10.662188529968262 0 2001 102044 15421 43911 42712 130049 11.533159255981445 9.643485069274902 10.689920425415039 10.662235260009766 0 2001 151249 42298 54084 54867 130051 11.926682472229004 10.652495384216309 10.898293495178223 10.912667274475098 0 2001 298888 85544 78120 135224 130054 12.607824325561523 11.356785774230957 11.26600170135498 11.814687728881836 0 2001 389015 39294 171576 178145 420001 12.871373176574707 10.578826904296875 12.05278205871582 12.090353012084961 0 2001 291757 73470 121775 96512 420007 12.5836763381958 11.204632759094238 11.709930419921875 11.477422714233398 0 2001 232841.99999999997 76048 79915 76879 420008 12.358115196228027 11.239119529724121 11.288719177246094 11.249987602233887 0 2001 108573 45967 26250 36356 420013 11.59517765045166 10.735678672790527 10.175421714782715 10.501114845275879 0 2001 182041 39910 68667 73464 420016 12.111987113952637 10.594382286071777 11.13702392578125 11.204550743103027 0 end
I follows the code as listed on Clarke et al(2023, pp. 25-29) (link: https://docs.iza.org/dp15907.pdf) and the code are as follows:
Code:
qui: sdid lnGDP county year treated, vce(noinference) graph matrix lambda = e(lambda)[1..16,1] matrix yco = e(series)[1..16,2] matrix ytr = e(series)[1..16,3] matrix aux = lambda'*(ytr - yco) scalar meanpre_o = aux[1,1] matrix difference = e(difference)[1..22,1..2] svmat difference ren (difference1 difference2) (time d) replace d = d - meanpre_o local b = 1 local B = 100 while `b'<=`B' { preserve bsample, cluster(county) idcluster(c2) qui count if treated == 0 local r1 = r(N) qui count if treated != 0 local r2 = r(N) if (`r1 '!=0 & `r2 '!=0){ qui: sdid lnGDP c2 year treated, vce(noinference) graph matrix lambda_b = e(lambda)[1..16,1] matrix yco_b = e(series)[1..16,2] matrix ytr_b = e(series)[1..16,3] matrix aux_b = lambda_b'*(ytr_b - yco_b) matrix meanpre_b = J(22,1,aux_b[1,1]) matrix d`b'=e(difference)[1..22,2] - meanpre_b local ++b } restore } preserve keep time d keep if time!=. forval b=1/`B' { svmat d`b' } egen rsd = rowsd(d11 - d`B '1) gen LCI = d + invnormal(0.025)*rsd gen UCI = d + invnormal(0.975)*rsd *generate plot tw rarea UCI LCI time, color(gray%40) || scatter d time, color(blue) m(d) xtitle("") ytitle("GDP") xlab(2000(1)2021, angle(45)) legend(order(2 "Point Estimate" 1 "95% CI") pos(12) col(2)) xline(2016, lc(black) lp(solid)) yline(0, lc(red) lp(shortdash)) scheme(sj) graph export "event_sdid.pdf", replace restore
The graph I generated is very weird as shown above with the point estimates all below zero which is unlikely given there should not be any treatment before the treatment year, and after the treatment the effect should be positive but insignificant as generated from the sdid command. Furthermore, the confidence interval seems to be very off. I am wondering if I made any mistakes when using the command. Any advice would be most appreciated!
Best regards!
Juncheng Lyu
Comment