Clustered standard errors with panel data in survregbayes

87 Views Asked by At

I'm currently working with a panel dataset containing information on 7903 cities from 2012 to 2022. My focus is on studying the digitalization of city administrations using survival models. Specifically, I've defined t0 to mark the beginning of the period, and t2 for the end of the period corresponding to either the year of digitalization (if the event occurred) or the end of the panel. The binary variable treat_v indicates whether the event was realized. Additionally, the variable PRO_COM serves as a unique identifier for cities. My independent variables include total population, average income, and administration software expenditure.

My dataset looks like:

  PRO_COM  year treat_v    t0    t2 total_ln Avg_income_ln software_ln
     <dbl> <dbl>   <dbl> <dbl> <dbl>    <dbl>         <dbl>       <dbl>
 1    1001  2012       0     0     1     7.88          9.95        13.6
 2    1001  2013       0     1     2     7.91          9.96         0  
 3    1001  2014       0     2     3     7.92          9.98        14.6
 4    1001  2015       0     3     4     7.90         10.0         14.0
 5    1001  2016       0     4     5     7.88         10.0         12.0
 6    1001  2017       0     5     6     7.89         10.0          0  
 7    1001  2018       0     6     7     7.89         10.0          0  
 8    1001  2019       0     7     8     7.88         10.0          0  
 9    1001  2020       1     8     9     7.87         10.0          0  
10    1002  2012       0     0     1     8.26          9.87        14.0
11    1002  2013       0     1     2     8.26          9.88        13.4
12    1002  2014       0     2     3     8.24          9.88        12.8

I need to use an accelerated failure time model and a spatial accelerated failure time model. I'm employing the survregbayes function from the spBayesSurv package. Is there a way to implement robust standard errors clustered by city in this model with this function? Here's the code I've used:

install.packages('spBayesSurv')
library(spBayesSurv)
mcmc <- list(nburn = 5000, nsave = 10000, nskip = 5, ndisplay= 2000)
prior <- list(maxL = 15)

res_prova <- survregbayes(Surv(t0, t2, treat_v) ~ total_ln + Avg_income_ln + software_ln
                      , data=df_prova, 
                      survmodel="AFT", dist="lognormal",InitParamMCMC=T, mcmc=mcmc,prior=prior)
summary.survregbayes(res_prova)

Any guidance on implementing robust standard errors clustered by city in this model would be greatly appreciated. Thank you!

Here there is a reproducible example of my dataset:

df_prova <- structure(list(PRO_COM = c(1001, 1001, 1001, 1001, 1001, 1001, 
1001, 1001, 1001, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 1002, 
1002, 1004, 1004, 1004, 1004, 1004, 1004, 1004, 1004, 1004, 1006, 
1006, 1006, 1006, 1006, 1006, 1006, 1006, 1006, 1011, 1011, 1011, 
1011, 1011, 1011, 1011, 1011, 1020, 1020, 1020, 1020, 1020, 1020, 
1020, 1020, 1020, 1022, 1022, 1022, 1022, 1022, 1022, 1022, 1022, 
1024, 1024, 1024, 1024, 1024, 1024, 1024, 1028, 1028, 1028, 1028, 
1028, 1028, 1029, 1029, 1029, 1029, 1029, 1029, 1029, 1029, 1029, 
1029, 1030, 1030, 1030, 1030, 1030, 1030, 1030, 1030, 1030, 1030, 
1031, 1031, 1031, 1031, 1031, 1031, 1031, 1031, 1031, 1034, 1034, 
1034, 1034, 1034, 1034, 1034, 1038, 1038, 1038, 1038, 1038, 1038, 
1038, 1038, 1040, 1040, 1040, 1040, 1040, 1040, 1040, 1040, 1054, 
1054, 1054, 1054, 1054, 1054, 1054, 1054, 1054, 2049, 2049, 2049, 
2049, 2049, 2049, 2049, 2049, 2049, 1285, 1285, 1285, 1285, 1285, 
1285, 1285, 1285, 1285, 1285, 4056, 4056, 4056, 4056, 4056, 4056, 
4056, 4056, 4056, 4056, 6124, 6124, 6124, 6124, 6124, 6124, 6124, 
6124, 6124, 6124), year = c(2012, 2013, 2014, 2015, 2016, 2017, 
2018, 2019, 2020, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 
2020, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2012, 
2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2012, 2013, 2014, 
2015, 2016, 2017, 2018, 2019, 2012, 2013, 2014, 2015, 2016, 2017, 
2018, 2019, 2020, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 
2012, 2013, 2014, 2015, 2016, 2017, 2018, 2012, 2013, 2014, 2015, 
2016, 2017, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 
2021, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 
2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2012, 2013, 
2014, 2015, 2016, 2017, 2018, 2012, 2013, 2014, 2015, 2016, 2017, 
2018, 2019, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2012, 
2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2012, 2013, 2014, 
2015, 2016, 2017, 2018, 2019, 2020, 2012, 2013, 2014, 2015, 2016, 
2017, 2018, 2019, 2020, 2021, 2012, 2013, 2014, 2015, 2016, 2017, 
2018, 2019, 2020, 2021, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 
2019, 2020, 2021), treat_v = c(0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 
0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 
0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 
1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 
0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 
0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 
0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), t0 = c(0, 
1, 2, 3, 4, 5, 6, 7, 8, 0, 1, 2, 3, 4, 5, 6, 7, 8, 0, 1, 2, 3, 
4, 5, 6, 7, 8, 0, 1, 2, 3, 4, 5, 6, 7, 8, 0, 1,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87625888230323, 7.87131120332341, 
8.25790419346567, 8.25660734462616, 8.24038511551633, 8.24222989137223, 
8.23244015847034, 8.22309055116153, 8.20821938349683, 8.19229373114764, 
8.18813341451048, 7.49942329059223, 7.49831587076698, 7.49164547360513, 
7.46965417293213, 7.454719949364, 7.43897159239586, 7.42714413340862, 
7.40367029001237, 7.40488757561612, 8.75557997214314, 8.76092337633884, 
8.76295892076673, 8.76201995356159, 8.76201995356159, 8.76514642163902, 
8.76592651372944, 8.7649903301691, 8.7681075396758, 6.7719355558396, 
6.76734312526539, 6.78784498230958, 6.79234442747081, 6.78784498230958, 
6.78671695060508, 6.76272950693188, 6.75925527066369, 8.10167774745457, 
8.0925452638913, 8.09833884618906, 8.08548677210285, 8.0702808933939, 
8.07464907506665, 8.07837810362652, 8.07246736935477, 8.06808962627824, 
8.08733292647335, 8.07868822922987, 8.0805469658245, 8.07496035911586, 
8.07090608878782, 8.05737748855799, 8.0507033814703, 8.0519780789023, 
9.80604009037016, 9.80697665215529, 9.81022028456569, 9.80989090379854, 
9.80592984894132, 9.80388818731337, 9.79701530802561, 9.51811914612709, 
9.51826615090501, 9.50509735809993, 9.50479942870699, 9.50248746138712, 
9.35625724687634, 6.31716468674728, 6.33859407820318, 6.32256523992728, 
6.33327962813969, 6.3261494731551, 6.36647044773144, 6.37331978957701, 
6.36818718635049, 6.37672694789863, 6.38350663488401, 8.21878715560148, 
8.21256839823415, 8.21148291644507, 8.20985248130127, 8.21121136179302, 
8.21229713822977, 8.19918935907807, 8.19726337141434, 8.18757739559151, 
8.18590748148232, 6.73340189183736, 6.73221070646721, 6.71659477352098, 
6.69332366826995, 6.68710860786651, 6.66949808985788, 6.68710860786651, 
6.66185474054531, 6.67203294546107, 9.04168500594604, 9.05028898382796, 
9.05415428878685, 9.06056344665796, 9.05777177333158, 9.05800471067248, 
9.05963375455148, 9.05380351415596, 9.05450494041805, 9.05310159554969, 
9.05122740031911, 9.05648964715792, 9.05555615817532, 9.05286751315162, 
9.06508335931904, 7.35436233042148, 7.37086016653672, 7.35564110297425, 
7.34987370473834, 7.33236920592906, 7.33367639565768, 7.3356339819272, 
7.3304052118444, 6.33150184989369, 6.33505425149806, 6.34738920965601, 
6.32793678372919, 6.34035930372775, 6.35088571671474, 6.3456363608286, 
6.37331978957701, 6.38687931936265, 8.99044155082686, 8.98582087448204, 
8.97233695775495, 8.97233695775495, 8.962391701743, 8.96200720958831, 
8.95789673495042, 8.95260537589235, 8.95480275285097, 6.86797440897029, 
6.8596149036542, 6.87005341179813, 6.83947643822884, 6.80682936039218, 
6.8001700683022, 6.82762923450285, 6.81673588059497, 6.81892406527552, 
6.85329909318608, 6.77878489768518, 6.8001700683022, 6.79570577517351, 
6.8001700683022, 6.80461452006262, 6.78445706263764, 6.75460409948796, 
6.71417052990947, 6.7286286130847, 6.72383244082121, 5.4553211153577, 
5.45958551414416, 5.45958551414416, 5.48893772615669, 5.45958551414416, 
5.4380793089232, 5.37063802812766, 5.28826703069454, 5.29831736654804, 
5.31811999384422), Avg_income_ln = c(9.95100918119281, 9.95823055302686, 
9.98051362913682, 10.0147662587243, 10.0278481007699, 10.0207687542477, 
10.0270911612452, 10.0330884347624, 10.0182449760809, 9.87347148493794, 
9.87561183232373, 9.88441973683242, 9.92989801004952, 9.93404314940026, 
9.91981091852989, 9.95102684439529, 9.94812688711294, 9.93168066211429, 
9.86416456839784, 9.86945437321638, 9.8786032427481, 9.90554554577413, 
9.90538663594792, 9.92630779643173, 9.98743798079886, 9.95116613437205, 
9.92429761999365, 10.0791467276647, 10.0785916165192, 10.0979747153919, 
10.1093433768296, 10.1243592564318, 10.1313177524273, 10.1421991535854, 
10.1472236062147, 10.1449984323863, 9.69115927507824, 9.71567911722924, 
9.69160543576198, 9.71492718807839, 9.71905607124579, 9.71676743188018, 
9.73680470874232, 9.76639980510036, 9.92603914306631, 9.94982592757546, 
9.93604995592034, 9.94077330019114, 9.92289898150387, 9.9297250950782, 
9.95786635866039, 9.94516720091473, 9.94471127303208, 9.98806441661829, 
10.0060145152037, 10.0188792059974, 10.0196752619576, 10.0391642554939, 
10.0549671389672, 10.0628991405105, 10.0664813284644, 9.91360955401906, 
9.91351724905354, 9.92354149929004, 9.93975675111295, 9.94835886993867, 
9.94777943409724, 9.9610919946104, 9.94103238656982, 9.95398197956198, 
9.96272563160125, 9.99133830689192, 9.99197673221995, 9.98239900872108, 
9.79889084129117, 9.82357613323638, 9.81960720165952, 9.84084181716343, 
9.83157910177803, 9.81202650121668, 9.82928231359217, 9.86134156493655, 
9.88703823704679, 9.94910113054451, 9.87753724879351, 9.89724249523534, 
9.90607947398146, 9.90519143546865, 9.9142315765518, 9.91808978798171, 
9.9138858431683, 9.96099551419382, 9.92927613508482, 9.97428918701486, 
9.89007659776826, 9.86333699424153, 9.9545987455228, 9.9208273973496, 
9.90358301867181, 9.91834450300624, 9.94004379148733, 9.97890193608502, 
9.91343037983815, 9.87106393853391, 9.89693775599761, 9.90776930489766, 
9.92985290969328, 9.92667574440502, 9.94548806196369, 9.9558504170754, 
10.0045461815298, 10.0040571381268, 10.0066109610899, 10.0315316097753, 
10.0508425375385, 10.0548054946526, 10.0803418749731, 10.0722735726998, 
9.86344913382924, 9.8822058423329, 9.89932760886725, 9.9186194411311, 
9.92663355064925, 9.92785383788164, 9.93416174109291, 9.93626525965158, 
9.72949831819389, 9.74745110136822, 9.76147071758372, 9.78655316657569, 
9.78027885232349, 9.77175673570384, 9.80192727580378, 9.80966626378322, 
9.80361746543969, 9.78123384047072, 9.80427963489623, 9.81036162920114, 
9.83390170021683, 9.84115273424143, 9.83480731766295, 9.8625013159703, 
9.86389768912967, 9.85485403369568, 9.90384314301659, 9.87493826296659, 
9.93999420618657, 9.9363366111413, 9.88791732224616, 9.91241093108613, 
9.93564514067879, 9.95273053800706, 9.93609430730758, 9.98596216242694, 
9.38374741621789, 9.45184851358746, 9.41579133089942, 9.4335946863867, 
9.43041070002655, 9.47186127965726, 9.50965151262306, 9.52028053328393, 
9.61666016444978, 9.601794269207, 9.92272263716164, 9.92155595175208, 
9.97346959372429, 9.97717523796906, 9.98008692406993, 9.97383699840932, 
10.0434836632773, 10.0580276164739, 10.0472839821578, 10.1340064364994
), software_ln = c(13.6312715640622, 0, 14.5906381061831, 13.9808631189336, 
11.9511868474935, 0, 0, 0, 0, 13.9512740825277, 13.4135617603837, 
12.7855862943222, 14.0587139583923, 13.4916332709192, 11.5230440984914, 
0, 0, 8.86460536807578, 14.3240020597858, 14.2704684404963, 14.3539406483169, 
14.3590347100635, 14.4039570051622, 0, 0, 0, 0, 14.6899153962449, 
14.743230526571, 14.8680220129697, 14.867534606448, 14.7851149219686, 
0, 12.0118869877927, 13.0448320136652, 13.6447471477057, 12.041203898549, 
11.5870212941931, 11.8499047158951, 11.6818408931813, 11.8541506740155, 
0, 0, 0, 14.6084447007496, 14.8797266899012, 14.5808281562597, 
14.4534119062982, 14.5328790205436, 0, 0, 0, 12.4344862854999, 
15.5784594599531, 15.616244799835, 15.601877681259, 16.0261207030794, 
15.8415794079656, 13.2077554440183, 12.4772479782762, 14.1436712059748, 
16.0849414751002, 16.3584853095525, 16.3906017740141, 16.4729037534324, 
16.4527397890538, 0, 0, 15.7158535433994, 15.5645488345031, 15.7467622230442, 
16.181562254047, 15.8068244635054, 0, 13.5352952067061, 13.3630670434619, 
13.5382275605494, 13.2382690964485, 13.4455013928394, 0, 0, 0, 
0, 0, 14.4477457004077, 14.4011337731848, 14.6907330149937, 14.4478886375212, 
14.379121212925, 0, 0, 0, 0, 0, 13.3087765521015, 13.1040384977011, 
14.059750800873, 13.7113393348177, 13.8261547074755, 0, 0, 0, 
0, 13.3480828082904, 15.2490379191216, 14.9543888466163, 15.0572692003486, 
14.2424951194326, 11.8263995454557, 12.9520233545, 14.1082376329627, 
14.2414734765094, 14.2756488089983, 14.306957012763, 14.4418494433975, 
0, 0, 0, 14.5645043756946, 13.8370029333024, 13.9564031652447, 
14.1991805350585, 14.0526209177311, 0, 0, 13.7015599192844, 12.9618729772842, 
13.0202265489677, 12.9846242876825, 13.0867589974288, 13.6406868221277, 
0, 11.5492670373727, 11.6915819803642, 0, 14.9882920311983, 14.8396647106143, 
15.0073122944249, 15.1917174613295, 15.4025151137662, 0, 0, 0, 
0, 0, 11.2758477829995, 0, 11.2451244481116, 0, 0, 13.2746483178217, 
11.5374326945246, 0, 0, 13.2678687944066, 13.7453552253669, 12.2126807637444, 
13.5598386496419, 13.8382813249919, 0, 0, 0, 11.2009643610583, 
11.759621466942, 12.1209449478476, 13.3736869167548, 12.3430524605059, 
12.7509953018642, 13.2911690041448, 0, 0, 0, 0, 0)), row.names = c(NA, 
-174L), groups = structure(list(.rows = structure(list(1L, 2L, 
    3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 
    16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 
    28L, 29L, 30L, 31L, 32L, 33L, 34L, 35L, 36L, 37L, 38L, 39L, 
    40L, 41L, 42L, 43L, 44L, 45L, 46L, 47L, 48L, 49L, 50L, 51L, 
    52L, 53L, 54L, 55L, 56L, 57L, 58L, 59L, 60L, 61L, 62L, 63L, 
    64L, 65L, 66L, 67L, 68L, 69L, 70L, 71L, 72L, 73L, 74L, 75L, 
    76L, 77L, 78L, 79L, 80L, 81L, 82L, 83L, 84L, 85L, 86L, 87L, 
    88L, 89L, 90L, 91L, 92L, 93L, 94L, 95L, 96L, 97L, 98L, 99L, 
    100L, 101L, 102L, 103L, 104L, 105L, 106L, 107L, 108L, 109L, 
    110L, 111L, 112L, 113L, 114L, 115L, 116L, 117L, 118L, 119L, 
    120L, 121L, 122L, 123L, 124L, 125L, 126L, 127L, 128L, 129L, 
    130L, 131L, 132L, 133L, 134L, 135L, 136L, 137L, 138L, 139L, 
    140L, 141L, 142L, 143L, 144L), ptype = integer(0), class = c("vctrs_list_of", 
"vctrs_vctr", "list"))), row.names = c(NA, -144L), class = c("tbl_df", 
"tbl", "data.frame")), class = c("rowwise_df", "tbl_df", "tbl", 
"data.frame"))

0

There are 0 best solutions below