Error (sometimes) when using tidysynth package (R) for synthetic control estimations

90 views Asked by At

I am having a bit of trouble with the aforementioned package. For clarity, I am trying to check the impact of South Africa's entrance into BRIC(S) in 2010 on several outcomes. The data I have is as follows (a small subset of the data is avaliable further below):

'data.frame':   1044 obs. of  16 variables:
 $ country_code             : chr  "AUS" "AUS" "AUS" "AUS" ...
 $ year                     : num  2002 2003 2004 2005 2006 ...
 $ gdp_per_capita           : num  47535 48453 49959 50911 51605 ...
 $ gdp_growth               : num  3.99 3.11 4.22 3.15 2.74 3.78 3.57 1.87 2.21 2.39 ...
 $ imports                  : num  117 132 150 169 183 ...
 $ exports                  : num  171 172 174 180 185 ...
 $ trade_openness           : num  40.3 37.1 39.3 41.6 42.1 ...
 $ population               : num  1.95e+08 1.97e+08 1.99e+08 2.02e+08 2.05e+08 ...
 $ mortality_rate           : num  6 5.9 5.8 5.7 5.6 5.4 5.2 5 4.8 4.5 ...
 $ life_expectancy          : num  79.9 80.2 80.5 80.8 81 81.3 81.4 81.5 81.7 81.9 ...
 $ inflation                : num  3 2.7 2.3 2.7 3.6 2.3 4.4 1.8 2.9 3.3 ...
 $ foreign_direct_investment: num  -7.68e+10 9.61e+10 -3.31e+11 -7.62e+10 -6.47e+10 ...
 $ gross_capital_formation  : num  24.4 25.9 27.1 27.5 27.5 27.5 28.6 27.4 26.8 26.5 ...
 $ country_name             : chr  "Australia" "Australia" "Australia" "Australia" ...
 $ imports_bric             : num  10.4 13.6 19 22.6 25.4 ...
 $ exports_bric             : num  6.78 9.08 13.33 19.24 22.99 ...

Subset of data with treated unit and 5 possible donors:

structure(list(country_code = c("DEU", "DEU", "DEU", "DEU", "DEU", 
"DEU", "DEU", "DEU", "DEU", "DEU", "DEU", "DEU", "DEU", "DEU", 
"DEU", "DEU", "DEU", "DEU", "HUN", "HUN", "HUN", "HUN", "HUN", 
"HUN", "HUN", "HUN", "HUN", "HUN", "HUN", "HUN", "HUN", "HUN", 
"HUN", "HUN", "HUN", "HUN", "KOR", "KOR", "KOR", "KOR", "KOR", 
"KOR", "KOR", "KOR", "KOR", "KOR", "KOR", "KOR", "KOR", "KOR", 
"KOR", "KOR", "KOR", "KOR", "MLT", "MLT", "MLT", "MLT", "MLT", 
"MLT", "MLT", "MLT", "MLT", "MLT", "MLT", "MLT", "MLT", "MLT", 
"MLT", "MLT", "MLT", "MLT", "MUS", "MUS", "MUS", "MUS", "MUS", 
"MUS", "MUS", "MUS", "MUS", "MUS", "MUS", "MUS", "MUS", "MUS", 
"MUS", "MUS", "MUS", "MUS", "ZAF", "ZAF", "ZAF", "ZAF", "ZAF", 
"ZAF", "ZAF", "ZAF", "ZAF", "ZAF", "ZAF", "ZAF", "ZAF", "ZAF", 
"ZAF", "ZAF", "ZAF", "ZAF"), year = c(2002, 2003, 2004, 2005, 
2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 
2017, 2018, 2019, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 
2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2002, 
2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 
2014, 2015, 2016, 2017, 2018, 2019, 2002, 2003, 2004, 2005, 2006, 
2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 
2018, 2019, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 
2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2002, 2003, 
2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 
2015, 2016, 2017, 2018, 2019), gdp_per_capita = c(34883.0580735445, 
34619.6640670185, 35034.0806086181, 35310.4704669272, 36699.446781036, 
37842.3577913563, 38278.3130082531, 36190.3928860698, 37760.9136283996, 
39977.3417095357, 40069.3539560742, 40135.0158319837, 40851.1617304855, 
41103.2564363768, 41682.0322433511, 42639.5544087286, 42928.7412368012, 
43284.6024553493, 9825.94319858403, 10255.6101131603, 10792.7374278506, 
11278.6160255559, 11741.9476769178, 11792.7712897392, 11932.0383995535, 
11162.0559722742, 11307.7161991209, 11551.4989289342, 11466.1419094704, 
11705.0092523564, 12233.299367172, 12717.038597002, 13035.3528590909, 
13628.4044885706, 14377.4241602939, 15083.5991718742, 18936.9516520974, 
19431.9711103534, 20361.0692543545, 21193.3575135298, 22192.1851207944, 
23360.9057353821, 23882.7304951493, 23948.4722438582, 25451.0041554666, 
26186.8975422978, 26675.4401708559, 27394.6503074507, 28094.9177029868, 
28732.2310762599, 29461.7840071118, 30307.395236491, 31053.6379289101, 
31640.2146297141, 17164.6115362329, 17746.8839106899, 17652.6988138032, 
18133.9806256833, 18521.6285342721, 19338.5387460039, 19948.1354169784, 
19573.9746792889, 20557.846540639, 20566.3476783023, 21221.71762833, 
22071.1191946794, 23286.1927928061, 24921.6778983872, 25181.3589164131, 
27177.9082338784, 27856.7644320024, 28660.0276642308, 5867.77362995049, 
6170.64876733851, 6397.59346169031, 6472.87388554741, 6756.22955969517, 
7110.69493851624, 7466.69465771689, 7693.76434353874, 8011.45517219702, 
8324.78328337964, 8591.96715947096, 8859.2121832294, 9181.61575362564, 
9507.87133656424, 9868.32716641952, 10247.6960577758, 10652.4836886859, 
10956.9450226163, 4953.7364473103, 5052.90993956202, 5233.86627685538, 
5458.23016635984, 5708.82308621003, 5954.16804814954, 6074.94267195276, 
5910.78824576381, 6018.23075370279, 6130.97136731323, 6194.99275876379, 
6263.10433363432, 6252.31797718806, 6204.92990145846, 6185.74604725477, 
6233.18710776586, 6250.99754447319, 6189.28924468567), gdp_growth = c(-0.2, 
-0.7, 1.18, 0.73, 3.82, 2.98, 0.96, -5.69, 4.18, 3.93, 0.42, 
0.44, 2.21, 1.49, 2.23, 2.68, 0.98, 1.06, 4.74, 4.07, 5, 4.29, 
3.95, 0.28, 1, -6.6, 1.08, 1.87, -1.25, 1.8, 4.23, 3.71, 2.2, 
4.27, 5.36, 4.86, 7.73, 3.15, 5.2, 4.31, 5.26, 5.8, 3.01, 0.79, 
6.8, 3.69, 2.4, 3.16, 3.2, 2.81, 2.95, 3.16, 2.91, 2.24, 2.57, 
4.07, 0.14, 3.38, 2.51, 4.78, 3.83, -1.13, 5.54, 0.47, 4.12, 
5.47, 7.63, 9.61, 3.38, 10.93, 6.17, 5.92, 1.61, 5.93, 4.33, 
1.78, 4.87, 5.73, 5.39, 3.32, 4.38, 4.08, 3.5, 3.36, 3.83, 3.69, 
3.86, 3.94, 4.01, 2.89, 3.7, 2.95, 4.55, 5.28, 5.6, 5.36, 3.19, 
-1.54, 3.04, 3.17, 2.4, 2.49, 1.41, 1.32, 0.66, 1.16, 1.52, 0.3
), imports = c(732.6827, 774.0108, 834.61656, 884.39515, 983.0281, 
1044.0299, 1068.06097, 964.54266, 1088.659, 1168.4104, 1169.5987, 
1200.8919, 1248.0297, 1320.387, 1379.6723, 1451.7654, 1509.7304, 
1552.9071, 44.426576, 48.61845, 57.368138, 61.980406, 71.348445, 
81.44157, 86.24079, 74.00599, 81.21756, 84.510425, 81.85619, 
85.22534, 94.51582, 99.88147, 103.348036, 112.02571, 119.82662, 
129.65964, 227.29177, 251.1103, 281.45497, 303.27528, 341.09945, 
379.9273, 392.3245, 365.2242, 429.1741, 491.45597, 504.07453, 
512.34095, 518.81273, 529.77343, 557.18733, 606.5373, 616.92654, 
605.14723, 7.1028516, 7.418507, 7.3459446, 7.9113503, 9.24265, 
9.975813, 11.725175, 11.59869, 12.551869, 13.027848, 13.519361, 
13.350938, 13.470876, 16.066127, 16.993454, 17.762454, 17.79574, 
19.209363, 4.410398, 4.1865439, 4.4216975, 4.865679, 5.478243, 
5.6243686, 5.7026954, 5.0797317, 5.548592, 5.8942106, 5.9755197, 
5.943988, 6.1552527, 6.6818324, 6.857493, 7.008538, 6.992912, 
7.1572756, 47.51152, 51.35274, 59.316457, 65.76965, 77.77992, 
85.06506, 87.45461, 72.01019, 79.78278, 89.22783, 92.67946, 96.42254, 
95.76008, 100.59104, 96.433365, 97.91114, 101.08898, 101.52815
), exports = c(854.18403, 870.41075, 970.7639, 1035.6706, 1162.9632, 
1266.3098, 1290.886, 1106.5638, 1265.9947, 1371.7043, 1411.562, 
1425.7407, 1494.1132, 1575.404, 1614.3164, 1693.4017, 1731.0539, 
1752.9521, 41.33083, 43.91384, 51.76887, 58.434277, 69.83976, 
81.08702, 86.513074, 77.235585, 85.82281, 91.322106, 89.766175, 
93.44927, 102.04454, 109.560504, 113.72839, 121.09281, 127.12876, 
134.02209, 214.44238, 243.56263, 294.72244, 318.00312, 356.30688, 
401.21555, 431.71663, 429.74465, 485.73104, 560.61716, 593.096, 
615.7537, 628.6572, 630.1295, 645.078, 661.07815, 687.3622, 689.0004, 
7.498391, 7.40841, 7.11317, 7.411073, 9.021524, 9.952513, 11.890381, 
11.841008, 12.812493, 13.488073, 14.225341, 14.360368, 14.855875, 
17.14934, 18.353932, 19.94985, 19.867525, 21.256407, 4.1619922, 
4.0909916, 3.994285, 4.53536, 4.752533, 4.822156, 4.968006, 4.8854697, 
5.572773, 5.8651003, 6.074673, 5.7144535, 6.041142, 6.183497, 
6.1802803, 6.239561, 6.3164114, 6.060885, 70.82761, 70.905, 72.914256, 
79.16098, 85.06858, 91.72801, 93.14964, 77.29201, 83.25742, 85.76217, 
86.71613, 89.95322, 93.23318, 96.0859, 96.477454, 96.21384, 98.85122, 
95.44558), trade_openness = c(60.93489, 61.84932, 66.2262, 70.91872, 
77.44973, 79.87442, 81.52481, 71.228714, 79.86863, 85.20612, 
86.51405, 85.07888, 84.620094, 86.24622, 84.769646, 87.4117, 
88.59638, 87.98913, 118.3201, 116.60616, 123.2677, 127.59309, 
148.8675, 155.34686, 158.19528, 144.76807, 157.26773, 166.28786, 
165.45467, 164.17406, 168.24283, 167.23996, 164.3144, 165.19518, 
163.38203, 161.25774, 58.353035, 61.174603, 70.01572, 68.324814, 
70.65188, 73.87453, 95.51636, 86.13361, 91.3996, 105.566315, 
105.45833, 97.9521, 90.61444, 79.1325, 73.603806, 77.12092, 78.98886, 
76.99643, 218.85155, 214.57481, 208.25983, 211.18791, 250.28499, 
258.50977, 297.2017, 296.97488, 307.42178, 318.39316, 325.72202, 
307.44165, 284.75757, 297.9527, 289.38638, 277.264, 267.40817, 
261.04706, 115.88254, 106.49775, 104.902306, 119.19403, 127.06286, 
120.87646, 115.48932, 104.42973, 113.45707, 117.53894, 119.50012, 
109.969734, 113.2928, 107.63687, 97.98558, 97.36549, 95.11128, 
92.80898, 59.667587, 51.401848, 51.078003, 53.149105, 60.27723, 
63.683117, 72.86539, 55.41826, 55.988987, 60.112633, 60.8997, 
64.24176, 64.4345, 61.61707, 60.638172, 57.973904, 59.470333, 
59.204536), population = c(824884950, 825341760, 825162600, 824694220, 
823764510, 822663720, 821100970, 819023070, 817769300, 802749830, 
804258230, 806456050, 809825000, 816866110, 823486690, 826570020, 
829057820, 830929620, 101586080, 101295520, 101071460, 100870650, 
100713700, 100557800, 100381880, 100226500, 100000230, 99717270, 
99203620, 98930820, 98664680, 98430280, 98140230, 97879660, 97755640, 
97711410, 476447360, 478923300, 480825190, 481845610, 484382920, 
486836380, 490547080, 493078350, 495541120, 499366380, 501998530, 
504288930, 507466590, 510149470, 512178030, 513619110, 515850580, 
517648220, 3959690, 3985820, 4012680, 4038340, 4053080, 4067240, 
4093790, 4124770, 4145080, 4162680, 4200280, 4259670, 4345580, 
4450530, 4553560, 4679990, 4846300, 5040620, 12046210, 12133700, 
12210030, 12282540, 12339960, 12396300, 12441210, 12474290, 12504000, 
12524040, 12558820, 12589270, 12612080, 12628790, 12637470, 12648870, 
12655770, 12659850, 476615140, 481040480, 485560710, 490171470, 
494917560, 499960940, 505658120, 511707790, 517849210, 524433250, 
531450330, 538736160, 547295510, 558765040, 564222740, 566412090, 
573396350, 580870550), mortality_rate = c(5.1, 5, 4.9, 4.7, 4.6, 
4.5, 4.4, 4.3, 4.2, 4.1, 4, 4, 4, 3.9, 3.9, 3.9, 3.8, 3.7, 9, 
8.4, 7.9, 7.6, 7.2, 6.8, 6.5, 6.2, 6, 5.9, 5.7, 5.6, 5.4, 5.1, 
4.7, 4.5, 4.2, 4.1, 6.8, 6.4, 6, 5.6, 5.2, 4.8, 4.5, 4.3, 4.1, 
4, 3.8, 3.7, 3.6, 3.5, 3.4, 3.3, 3.2, 3.1, 7.2, 7, 7, 6.9, 6.9, 
6.8, 6.8, 6.8, 6.8, 6.8, 6.8, 6.7, 6.7, 6.6, 6.5, 6.4, 6.3, 6.1, 
16.6, 16, 15.8, 15.6, 15.5, 15.2, 14.8, 14.6, 14.6, 14.8, 14.9, 
14.9, 14.8, 14.6, 14.6, 14.9, 15.4, 15.9, 75.2, 76.5, 77.8, 79.2, 
78.9, 74.6, 68.3, 59.9, 51.6, 45.5, 41.5, 39.6, 38.3, 37.3, 36.6, 
35.8, 35.1, 34.3), life_expectancy = c(78.2, 78.4, 78.7, 78.9, 
79.1, 79.5, 79.7, 79.8, 80, 80.4, 80.5, 80.5, 81.1, 80.6, 81, 
81, 80.9, 81.3, 72.3, 72.3, 72.6, 72.6, 73.1, 73.2, 73.7, 73.9, 
74.2, 74.9, 75.1, 75.6, 75.8, 75.6, 76.1, 75.8, 76.1, 76.3, 76.8, 
77.2, 77.7, 78.2, 78.7, 79.1, 79.5, 80, 80.1, 80.6, 80.8, 81.3, 
81.7, 82, 82.3, 82.6, 82.6, 83.2, 78.7, 78.5, 79.3, 79.3, 79.4, 
79.8, 79.6, 80.2, 81.4, 80.7, 80.7, 81.7, 82, 81.9, 82.5, 82.3, 
82.4, 82.9, 72, 72.1, 72.3, 72.4, 72.4, 72.6, 72.6, 72.9, 73, 
73.3, 73.9, 74, 74.2, 74.4, 74.4, 74.5, 74.4, 74.2, 55.7, 54.3, 
54, 54, 54.3, 55, 56, 57.4, 58.9, 60.7, 61.8, 62.5, 63.4, 64, 
64.7, 65.4, 65.7, 66.2), inflation = c(1.4, 1, 1.7, 1.5, 1.6, 
2.3, 2.6, 0.3, 1.1, 2.1, 2, 1.5, 0.9, 0.5, 0.5, 1.5, 1.7, 1.4, 
5.3, 4.7, 6.7, 3.6, 3.9, 8, 6, 4.2, 4.9, 3.9, 5.7, 1.7, -0.2, 
-0.1, 0.4, 2.3, 2.9, 3.3, 2.8, 3.5, 3.6, 2.8, 2.2, 2.5, 4.7, 
2.8, 2.9, 4, 2.2, 1.3, 1.3, 0.7, 1, 1.9, 1.5, 0.4, 2.2, 1.3, 
2.8, 3, 2.8, 1.2, 4.3, 2.1, 1.5, 3, 2.4, 1.2, 0.3, 1.1, 0.6, 
1.4, 1.2, 1.6, 6.4, 3.9, 4.7, 4.9, 8.9, 8.8, 9.7, 2.5, 2.9, 6.5, 
3.9, 3.5, 3.2, 1.3, 1, 3.7, 3.2, 0.4, 9.5, 5.7, -0.7, 2.1, 3.2, 
6.2, 10.1, 7.2, 4.1, 5, 5.7, 5.8, 6.1, 4.5, 6.6, 5.2, 4.5, 4.1
), foreign_direct_investment = c(-340673969915, -261006762872, 
294780977714, 290889569044, 605299189951, 898050584317, 670714950314, 
430373295871, 606055222853, 103731487584, 336391734741, 260936214545, 
879193718691, 683883933189, 471741924590, 361245714622, 290111017788, 
988127462800, -24705162433, -83159140, -28886009922, -74258622161, 
-3596971877, -23524950926, -14571505994, -9722858925, -39366975075, 
-19616267979, -28775318420, -2782319513, -38195510812, -28906192188, 
-29837272469, -23761702014, -35316342459, -2157966641, -2.0379e+10, 
-1.9912e+10, -6.0988e+10, -5.3132e+10, 3.4012e+10, 1.30041e+11, 
8.349e+10, 8.3786e+10, 1.87242e+11, 1.98747e+11, 2.11028e+11, 
1.55512e+11, 1.87249e+11, 1.9583e+11, 1.77852e+11, 1.61565e+11, 
2.60378e+11, 2.56047e+11, 4008865460, -4318354492, -21548167997, 
-108310350163, -101750180394, -209520090223, 13248267823, -75462421286, 
-59154617972, -121849488109, -115771886779, -92805627957, -88699262278, 
-102327032924, -94109118232, -108288699492, -116292849506, -108616328165, 
-233753435, -686483175, 178917920, 51873565, -971673780, -2811892786, 
-3252982185, -2188420815, -138432925532, 9887953036, -56701645388, 
-12038009514, -203689946914, -45069012823, -80856866559, -251051893939, 
-14559934477, -35452238018, -18820670099, -2305924600, 6040023186, 
-56126838026, 53055047710, -36046797687, -120045841379, -63131903345, 
-38545649524, -42926874243, -17271594924, -17126454581, 19004178690, 
39937889007, 22751711151, 53906435729, -15425008422, -19751604861
), gross_capital_formation = c(20.8, 20.4, 19.8, 19.5, 20.6, 
21.4, 21.4, 18.6, 20.1, 21.6, 19.7, 20.1, 20.4, 19.7, 20, 21, 
21.9, 21.9, 25.6, 24.6, 27.4, 26, 26.2, 24.8, 25.1, 21.1, 21.2, 
20.8, 20.2, 21.6, 24.1, 23.5, 21.5, 23.1, 26.8, 28.4, 31.1, 32.3, 
32.5, 32.5, 33, 33.1, 33.7, 29.4, 32.6, 33.3, 31.3, 29.9, 29.8, 
29.5, 30.1, 32.3, 31.5, 31.5, 17.4, 22.8, 24, 27.7, 23.6, 23.6, 
22.1, 20, 22.3, 17.7, 17.2, 16.2, 15.7, 24.1, 23.3, 20.6, 19.9, 
20.8, 22.1, 23.7, 24.4, 22.7, 25.6, 26, 25.3, 23.8, 27.1, 23.9, 
24.4, 21.5, 19.1, 17.5, 17.3, 17.7, 18.9, 19.4, 15, 15.7, 17, 
16.8, 18.5, 19.3, 21.3, 18.8, 17.6, 18.9, 18.6, 19.2, 18.5, 18.6, 
17, 16.6, 16.2, 15.8), country_name = c("Germany", "Germany", 
"Germany", "Germany", "Germany", "Germany", "Germany", "Germany", 
"Germany", "Germany", "Germany", "Germany", "Germany", "Germany", 
"Germany", "Germany", "Germany", "Germany", "Hungary", "Hungary", 
"Hungary", "Hungary", "Hungary", "Hungary", "Hungary", "Hungary", 
"Hungary", "Hungary", "Hungary", "Hungary", "Hungary", "Hungary", 
"Hungary", "Hungary", "Hungary", "Hungary", "Rep. of Korea", 
"Rep. of Korea", "Rep. of Korea", "Rep. of Korea", "Rep. of Korea", 
"Rep. of Korea", "Rep. of Korea", "Rep. of Korea", "Rep. of Korea", 
"Rep. of Korea", "Rep. of Korea", "Rep. of Korea", "Rep. of Korea", 
"Rep. of Korea", "Rep. of Korea", "Rep. of Korea", "Rep. of Korea", 
"Rep. of Korea", "Malta", "Malta", "Malta", "Malta", "Malta", 
"Malta", "Malta", "Malta", "Malta", "Malta", "Malta", "Malta", 
"Malta", "Malta", "Malta", "Malta", "Malta", "Malta", "Mauritius", 
"Mauritius", "Mauritius", "Mauritius", "Mauritius", "Mauritius", 
"Mauritius", "Mauritius", "Mauritius", "Mauritius", "Mauritius", 
"Mauritius", "Mauritius", "Mauritius", "Mauritius", "Mauritius", 
"Mauritius", "Mauritius", "South Africa", "South Africa", "South Africa", 
"South Africa", "South Africa", "South Africa", "South Africa", 
"South Africa", "South Africa", "South Africa", "South Africa", 
"South Africa", "South Africa", "South Africa", "South Africa", 
"South Africa", "South Africa", "South Africa"), imports_bric = c(44.909376872, 
57.871662571, 79.516271419, 98.838760163, 120.356493948, 137.485690042, 
166.747822218, 131.911157352, 169.652696791, 192.399224194, 173.935656269, 
165.606374853, 167.742817363, 144.488576375, 142.303504556, 155.257912157, 
167.620710265, 156.538928796, 5.955025523, 7.078920851, 8.016121685, 
10.37821915, 8.803610974, 13.481758939, 18.840399001, 12.244158284, 
14.573237602, 16.473509997, 14.875465439, 14.794775737, 13.096203052, 
8.986752032, 7.97725613, 9.212833355, 11.016522013, 11.430257618, 
28.69329204, 34.753596993, 46.269943823, 56.775969638, 69.446504829, 
88.002929984, 106.83809126, 74.827715313, 100.036399144, 118.883426531, 
109.972072004, 109.254460122, 117.031962126, 109.85557585, 102.091606511, 
115.035553562, 126.767535492, 122.579639711, 0.147522898, 0.179591988, 
0.153335131, 0.133296326, 0.190402728, 0.216034441, 0.270059758, 
0.265132575, 0.43350388, 0.810663257, 0.552122227, 0.714303906, 
0.666285323, 0.61586251, 0.551812016, 0.458851649, 0.572811618, 
0.754818468, 0.449440857, 0.522234678, 0.655623414, 0.652939944, 
0.956933535, 1.455956784, 1.866034772, 1.313304787, 1.731974482, 
2.11187398, 2.395452974, 2.186869594, 2.194265673, 1.680403946, 
1.634558571, 1.753931803, 1.889757103, 1.63530131, 2.855889302, 
4.30003767, 6.596707764, 8.969856029, 11.854483553, 14.280607229, 
15.697596606, 13.004523425, 17.234052312, 21.394998946, 22.049057853, 
23.995153116, 22.01574699, 21.776518796, 18.187888755, 20.475916349, 
21.722491958, 20.766549652), exports_bric = c(40.423130325, 52.424948505, 
66.609805022, 70.702280333, 91.089769485, 110.538200543, 137.902622548, 
113.89716343, 145.625647171, 182.099575605, 172.454907127, 170.006414453, 
166.450470449, 125.999908827, 128.0312754, 144.702041895, 159.146802568, 
152.405338856, 0.861267598, 1.167192048, 1.77605286, 2.044311257, 
3.446092625, 4.665115611, 5.834158996, 4.89815005, 5.901336536, 
6.407902808, 5.966143279, 6.157620989, 5.617926179, 3.989544165, 
4.168544251, 4.898005499, 4.485393112, 3.890946714, 35.617222543, 
51.920226286, 71.348307016, 87.559408031, 97.185984428, 113.850705411, 
128.833358055, 114.822296377, 156.584518897, 180.122349291, 175.32774885, 
183.032614667, 178.856755605, 159.334148991, 143.620749235, 164.560222831, 
179.973312564, 152.584590292, 0.006479023, 0.028247084, 0.033519267, 
0.047552409, 0.091657078, 0.059114679, 0.056417145, 0.057335014, 
0.111673992, 0.13953387, 0.16118937, 0.173715507, 0.091645502, 
0.078340214, 0.07038003, 0.059253683, 0.054768834, 0.068705779, 
0.017791126, 0.018712091, 0.031602774, 0.006579713, 0.023078613, 
0.019381872, 0.030695275, 0.021022007, 0.012959748, 0.01933456, 
0.026820156, 0.024508633, 0.020854069, 0.01945821, 0.017382464, 
0.043869431, 0.059781015, 0.054438388, 1.32481652, 1.938441276, 
2.438167368, 3.520955257, 3.970378583, 7.035847695, 8.317526254, 
9.113194252, 13.198875086, 18.107473618, 15.986331239, 16.554185747, 
13.650853932, 11.52650655, 10.724087109, 13.138066146, 13.14893576, 
13.402576058)), row.names = c(NA, -108L), class = "data.frame")

When I run the code for the effects on exports and imports (below), it works normally:

library(tidyverse)
library(tidysynth)

# Import panel with complete data ---- 

df <- readRDS("data/cleaned_data/complete_data.rds") %>%
      as.data.frame()

# 1. Effect on exports ---- good evidence of a structural break in the series due to the 2008-2009 crisis

synthetic_out_exports <- df %>% 
    synthetic_control(
    outcome = exports,
    unit = country_name,
    time = year,
    i_unit = "South Africa",
    i_time = 2010,
    generate_placebos = TRUE) %>%
    generate_predictor( # Lagged dependent variable
        time_window = 2002:2009,
        exports = mean(exports, na.rm = TRUE)
    ) %>%
    generate_weights(optimization_window = 2002:2009, optimization_method = "All") %>%
    generate_control()

synthetic_out_exports %>% plot_trends()
synthetic_out_exports %>% plot_differences()
synthetic_out_exports %>% plot_weights()
synthetic_out_exports %>% plot_placebos()
synthetic_out_exports %>% plot_mspe_ratio()
synthetic_out_exports %>% grab_balance_table()
synthetic_out_exports %>% grab_significance()

# 2. Effect on imports ---- good evidence of a structural break in the series due to the 2008-2009 crisis

synthetic_out_imports <- df %>% 
    synthetic_control(
        outcome = imports,
        unit = country_name,
        time = year,
        i_unit = "South Africa",
        i_time = 2010,
        generate_placebos = TRUE) %>%
    generate_predictor( # Lagged dependent variable
        time_window = 2002:2009,
        imports = mean(imports, na.rm = TRUE)
    ) %>%
    generate_weights(optimization_window = 2002:2009, optimization_method = "All") %>%
    generate_control()

synthetic_out_imports %>% plot_trends()
synthetic_out_imports %>% plot_differences()
synthetic_out_imports %>% plot_weights()
synthetic_out_imports %>% plot_placebos()
synthetic_out_imports %>% plot_mspe_ratio()
synthetic_out_imports %>% grab_balance_table()
synthetic_out_imports %>% grab_significance()

As I mentioned, this code works just fine. However, once I move on to any of the other variables, such as gdp_per_capita, using the same code:

# 3. Effect on gdp per capita ---- 

synthetic_out_gdp_per_capita <- df %>% 
    synthetic_control(
        outcome = gdp_per_capita,
        unit = country_code,
        time = year,
        i_unit = "South Africa",
        i_time = 2010,
        generate_placebos = TRUE) %>%
    generate_predictor( # Lagged dependent variable
        time_window = 2002:2009,
        gdp_per_capita = mean(gdp_per_capita, na.rm = TRUE)
    ) %>%
    generate_weights(optimization_window = 2002:2009, optimization_method = "All") %>%
    generate_control()
    
synthetic_out_gdp_per_capita %>% plot_trends()
synthetic_out_gdp_per_capita %>% plot_differences()
synthetic_out_gdp_per_capita %>% plot_weights()
synthetic_out_gdp_per_capita %>% plot_placebos()
synthetic_out_gdp_per_capita %>% plot_mspe_ratio()
synthetic_out_gdp_per_capita %>% grab_balance_table()
synthetic_out_gdp_per_capita %>% grab_significance()

I get the errors:

> synthetic_out_gdp_per_capita %>% plot_trends()
Error in `dplyr::filter()`:
ℹ In argument: `time_unit %in% time_window`.
Caused by error in `time_unit %in% time_window`:
! object 'time_unit' not found
Run `rlang::last_trace()` to see where the error occurred.

> synthetic_out_gdp_per_capita %>% plot_differences()
Error in `dplyr::mutate()`:
ℹ In argument: `diff = real_y - synth_y`.
Caused by error:
! object 'real_y' not found
Run `rlang::last_trace()` to see where the error occurred.

> synthetic_out_gdp_per_capita %>% plot_weights()
Error in `dplyr::rename()`:
! Can't rename columns that don't exist.
✖ Column `variable` doesn't exist.
Run `rlang::last_trace()` to see where the error occurred.

> synthetic_out_gdp_per_capita %>% plot_placebos()
Error in `dplyr::filter()`:
ℹ In argument: `sqrt(pre_mspe) <= thres * 2`.
Caused by error:
! `..1` must be of size 19 or 1, not size 0.
Run `rlang::last_trace()` to see where the error occurred.

> synthetic_out_gdp_per_capita %>% plot_mspe_ratio()
(works, but outputs a figure with only "Donor" category, also uploaded as file in the question)

>  synthetic_out_gdp_per_capita %>% grab_balance_table()
Error in `tidyr::gather()`:
! Can't subset columns that don't exist.
✖ Column `variable` doesn't exist.
Run `rlang::last_trace()` to see where the error occurred.

> synthetic_out_gdp_per_capita %>% grab_significance()
(works, but I can see on the table that South Africa is being treated as donor and there are no treated)

Problematic plot

The errors seem to be related to the masking of dplyr functions and some other problem that's keeping South Africa from being properly recognized as treated.

What do you think? I'd appreciate some help here.

Thank you very much.

I tried replicating the working code for the remainder of the outcome variables, but as I mentioned, there seems to be some error keeping the code from working. I have tried changing the donor pool, changing the order of operations (see if by running the synthetic control estimation first for gdp_per_capita, for instance, would work; it didn't), disabling the placebo option and loading/reloading/updating both the tidysynth and dplyr packages.

0

There are 0 answers