Dear,

I have some questions about the difference-in-differences (DID) model with fixed effects. I read many threads before posting this question but did not seem to get an answer to it. I have longitudinal data (workers in the UK labour market)

I am dealing with a quarterly panel dataset – from Jan 2019 to Des 2020 – for workers, and I want to study the effect of a covid_19 closure introduced on March 2019.



I want to run a Difference in difference (DiD) regression with fixed effects. However, I want to have robust and clustered standard errors at the individual level. I tried using the following:


Code:
xtset PERSID qtr
xtdidregress (SUMHRS AGES SEX) (afterCovid19), group (ZHC) time (qtr)

Where:
PERSID is the ID of each individual (panel variable)
qtr is the time variable (quarterly)
SUMHRS is the outcome variable which is the total hours worked
afterCovid19 is the dummy variable ( treatment intervention) indicate: 1= if period after covid_19. 0= if the period before covid
ZHC is a group of works which indicate 1 = if the workers treated 0 = not treated

However, when I run the regression, it provides the error " PERSID not nested within ZHC".
I’m not sure how to solve this matter. What I understand is that the reason is that the same id moves from 0 to 1 across subsequent -qtr-, so I tried to find a different (and time-invariant) variable to cluster on standard errors but I could not, I did not find that variables in my data.

See the sample of my data :

Code:
* Example generated by -dataex-. For more info, type help dataex
clear
input double(SUMHRS PERSID) long LGWT20 byte Inde07m int(SOC10M QUOTA) byte(QRTR HHLD SEX Indd07o2 SCHM12) int NETWK2 long NETWK byte(IOTCOME AGE AGES) float(ZHC Aftercovid)
 -9 10493040101  4488 -9   -9 1 3 1 2  . -9 -9  -9 1 68 14 0 0
 -9 10493040101  4488 -9   -9 1 3 1 2  . -9 -9  -9 1 68 14 0 0
 -9 10493040101  4488 -9   -9 1 3 1 2  . -9 -9  -9 1 68 14 0 1
 -9 10493040101  4488 -9   -9 1 3 1 2  . -9 -9  -9 1 69 14 0 1
 -9 10493040101  4488 -9   -9 1 3 1 2  . -9 -9  -9 1 69 14 0 1
 -9 10694020101  3966 -9   -9 1 4 1 2  . 66 -9  -9 1 59 12 0 0
 -9 10694020101  3966 -9   -9 1 4 1 2  . 66 -9  -9 1 59 12 0 1
 -9 10694020101  3966 -9   -9 1 4 1 2  . 66 -9  -9 1 60 13 0 1
 -9 10694020101  3966 -9   -9 1 4 1 2  . 66 -9  -9 1 60 13 0 1
 -9 10694020101  3966 -9   -9 1 4 1 2  . 66 -9  -9 1 60 13 0 1
 -9 10694020102  5357 -9   -9 1 4 1 1  . 66 -9  -9 1 62 13 0 0
 -9 10694020102  5357 -9   -9 1 4 1 1  . 66 -9  -9 2 62 13 0 1
 -9 10694020102  5357 -9   -9 1 4 1 1  . 66 -9  -9 2 62 13 0 1
 -9 10694020102  5357 -9   -9 1 4 1 1  . 66 -9  -9 2 63 13 0 1
 -9 10694020102  5357 -9   -9 1 4 1 1  . 66 -9  -9 2 63 13 0 1
 -9 10792030101  3423 -9   -9 1 2 1 2  . -9 -9  -9 1 69 14 0 0
 -9 10792030101  3423 -9   -9 1 2 1 2  . -9 -9  -9 1 69 14 0 0
 -9 10792030101  3423 -9   -9 1 2 1 2  . -9 -9  -9 1 69 14 0 0
 -9 10792030101  3423 -9   -9 1 2 1 2  . -9 -9  -9 1 69 14 0 1
 -9 10792030101  3423 -9   -9 1 2 1 2  . -9 -9  -9 7 70 15 0 1
 37 10793010101 14874  8 3315 1 3 1 2  . 66 -9 369 1 34  7 0 0
 26 10793010101 14874  8 3315 1 3 1 2  . 66 -9  -9 1 35  8 0 0
 30 10793010101 14874  8 3315 1 3 1 2  . 66 -9  -9 1 35  8 0 1
 40 10793010101 14874  8 3315 1 3 1 2  . 66 -9  -9 1 35  8 0 1
 35 10793010101 14874  8 3315 1 3 1 2  . 66 -9 383 1 35  8 0 1
 40 10794010101 14575  5 1223 1 4 1 1  . 66 -9 485 1 33  7 0 0
  0 10794010101 14575  5 1223 1 4 1 1  . 66 -9  -9 2 34  7 0 1
 10 10794010101 14575  5 1223 1 4 1 1  . 66 -9  -9 1 34  7 0 1
 38 10794010101 14575  5 1223 1 4 1 1  . 66 -9  -9 1 34  7 0 1
 38 10794010101 14575  5 1223 1 4 1 1  . 66 -9 454 1 34  7 0 1
 40 10794010102 16924  5 1223 1 4 1 2  . 66 -9 519 1 27  6 0 0
  0 10794010102 16924  5 1223 1 4 1 2  . 66 -9  -9 1 27  6 0 1
  0 10794010102 16924  5 1223 1 4 1 2  . 66 -9  -9 1 27  6 0 1
  0 10794010102 16924  5 1223 1 4 1 2  . 66 -9  -9 1 27  6 0 1
  0 10794010102 16924  5 1223 1 4 1 2  . 66 -9 219 1 28  6 0 1
  0 10993020101 13700  8 2316 1 3 1 2  . 66 -9 438 1 47 10 0 0
  0 10993020101 13700  8 2316 1 3 1 2  . 66 -9  -9 1 48 10 0 0
  0 10993020101 13700  8 2316 1 3 1 2  . 66 -9  -9 1 48 10 0 1
  0 10993020101 13700  8 2316 1 3 1 2  . 66 -9  -9 1 48 10 0 1
 -9 10993020101 13700 -9   -9 1 3 1 2  . 66 -9  -9 1 48 10 0 1
 50 10993020102 18284  8 4113 1 3 1 1  . 66 -9 923 1 47 10 0 0
 50 10993020102 18284  8 4113 1 3 1 1  . 66 -9  -9 1 47 10 0 0
 54 10993020102 18284  8 1139 1 3 1 1  . 66 -9  -9 2 48 10 0 1
 55 10993020102 18284  8 1139 1 3 1 1  . 66 -9  -9 2 48 10 0 1
 50 10993020102 18284  8 1135 1 3 1 1  . 66 -9 923 2 48 10 0 1
 40 11091010101  8946  8 6126 1 1 1 2 -8 66 -9 300 1 51 11 0 0
 37 11091010101  8946  8 6126 1 1 1 2 -8 66 -9  -9 1 51 11 0 0
 40 11091010101  8946  8 6126 1 1 1 2 -8 66 -9  -9 1 51 11 0 0
 37 11091010101  8946  8 6126 1 1 1 2 -8 66 -9  -9 1 51 11 0 0
 37 11091010101  8946  8 6126 1 1 1 2 -8 66 -9 312 1 52 11 0 1
 -9 11093030101  8199 -9   -9 1 3 1 2  . -9 -9  -9 1 65 14 0 0
 -9 11093030101  8199 -9   -9 1 3 1 2  . -9 -9  -9 1 65 14 0 0
 -9 11093030101  8199 -9   -9 1 3 1 2  . -9 -9  -9 1 65 14 0 1
 -9 11093030101  8199 -9   -9 1 3 1 2  . -9 -9  -9 1 65 14 0 1
 -9 11093030101  8199 -9   -9 1 3 1 2  . -9 -9  -9 1 66 14 0 1
 22 11094010101  9664  8 2419 1 4 1 1  . 66 -9 369 1 62 13 0 0
 -9 11094010101  9664 -9   -9 1 4 1 1  . 66 -9  -9 1 62 13 0 1
 -9 11094010101  9664 -9   -9 1 4 1 1  . 66 -9  -9 2 62 13 0 1
 -9 11094010101  9664 -9   -9 1 4 1 1  . 66 -9  -9 2 62 13 0 1
 -9 11094010101  9664 -9   -9 1 4 1 1  . 66 -9  -9 1 63 13 0 1
 22 11094010102  9234  8 3239 1 4 1 2  . 66 -9 392 1 45 10 0 0
  8 11094010102  9234  8 3239 1 4 1 2  . 66 -9  -9 2 45 10 0 1
 15 11094010102  9234  8 3239 1 4 1 2  . 66 -9  -9 1 45 10 0 1
 38 11094010102  9234  8 3239 1 4 1 2  . 66 -9  -9 1 45 10 0 1
 40 11094010102  9234  8 3239 1 4 1 2  . 66 -9 392 1 46 10 0 1
 -9 11291020101 11827 -9   -9 1 1 1 2 -9 -9 -9  -9 1 68 14 0 0
 -9 11291020101 11827 -9   -9 1 1 1 2 -9 -9 -9  -9 1 68 14 0 0
 -9 11291020101 11827 -9   -9 1 1 1 2 -9 -9 -9  -9 1 69 14 0 0
 -9 11291020101 11827 -9   -9 1 1 1 2 -9 -9 -9  -9 1 69 14 0 0
 -9 11291020101 11827 -9   -9 1 1 1 2 -9 -9 -9  -9 1 69 14 0 1
 47 11292020101 11325  5 5431 1 2 1 1  . 66 -9 308 1 48 10 0 0
 38 11292020101 11325  5 5431 1 2 1 1  . 66 -9  -9 1 49 10 0 0
 46 11292020101 11325  5 5431 1 2 1 1  . 66 -9  -9 1 49 10 0 0
 38 11292020101 11325  5 5431 1 2 1 1  . 50 -9  -9 1 49 10 0 1
 38 11292020101 11325  5 5431 1 2 1 1  . 66 -9 319 1 49 10 0 1
 38 11294030101 11119  8 3561 1 4 1 2  . 66 -9 300 1 56 12 0 0
 38 11294030101 11119  8 3561 1 4 1 2  . 66 -9  -9 2 56 12 0 1
 43 11294030101 11119  8 3562 1 4 1 2  . 66 -9  -9 2 56 12 0 1
 36 11294030101 11119  8 3562 1 4 1 2  . 66 -9  -9 2 56 12 0 1
  0 11294030101 11119  8 4216 1 4 1 2  . 66 -9 316 2 57 12 0 1
 -9 11294030102 11984 -9   -9 1 4 1 1  . 66 -9  -9 1 60 13 0 0
 -9 11294030102 11984 -9   -9 1 4 1 1  . 66 -9  -9 1 60 13 0 1
 -9 11294030102 11984 -9   -9 1 4 1 1  . 66 -9  -9 1 61 13 0 1
 -9 11294030102 11984 -9   -9 1 4 1 1  . 66 -9  -9 1 61 13 0 1
 -9 11294030102 11984 -9   -9 1 4 1 1  . 66 -9  -9 1 61 13 0 1
 50 20191020101 17972  8 2317 2 1 1 1 85 66 -9 842 1 38  8 0 0
 59 20191020101 17972  8 2317 2 1 1 1 85 66 -9  -9 1 38  8 0 0
 45 20191020101 17972  8 2317 2 1 1 1 85 66 -9  -9 1 38  8 0 0
 55 20191020101 17972  8 2317 2 1 1 1 85 66 -9  -9 1 39  8 0 0
  0 20191020101 17972  8 2317 2 1 1 1 85 66 -9 808 1 39  8 0 1
 42 20191020102 23504  5 3562 2 1 1 1 47 66 -9 554 1 30  7 0 0
 51 20191020102 23504  5 3562 2 1 1 1 47 66 -9  -9 1 30  7 0 0
 46 20191020102 23504  5 3562 2 1 1 1 47 66 -9  -9 1 31  7 0 0
 41 20191020102 23504  5 3562 2 1 1 1 47 66 -9  -9 1 31  7 0 0
 32 20191020102 23504  5 3562 2 1 1 1 47 66 -9 507 1 31  7 0 1
6.5 20191040101 13866  9 6231 2 1 1 2 96 66 18  29 1 63 13 0 0
  6 20191040101 13866  9 6231 2 1 1 2 96 66 -9  -9 1 64 13 0 0
 12 20191040101 13866  9 9233 2 1 1 2 96 66 -9  -9 1 64 13 0 0
 12 20191040101 13866  9 9233 2 1 1 2 96 66 -9  -9 1 64 13 0 0
 12 20191040101 13866  9 9233 2 1 1 2 96 66 -9  84 1 64 13 0 1
end
label values SUMHRS SUMHRS5
label def SUMHRS5 -9 "Does not apply", modify
label values Inde07m Inde07m5
label def Inde07m5 -9 "Does not apply", modify
label def Inde07m5 5 "G,I -Distribution, hotels and restaurants", modify
label def Inde07m5 8 "O,P,Q - Public admin, education and health", modify
label def Inde07m5 9 "R,S,T,U - Other services", modify
label values SOC10M SOC10M5
label def SOC10M5 -9 "Does not apply", modify
label def SOC10M5 1135 "Human resource managers and directors", modify
label def SOC10M5 1139 "Functional managers and directors n.e.c.", modify
label def SOC10M5 1223 "Restaurant and catering establishment managers and proprietors", modify
label def SOC10M5 2316 "Special needs education teaching professionals", modify
label def SOC10M5 2317 "Senior professionals of educational establishments", modify
label def SOC10M5 2419 "Legal professionals n.e.c.", modify
label def SOC10M5 3239 "Welfare and housing associate professionals n.e.c.", modify
label def SOC10M5 3315 "Police community support officers", modify
label def SOC10M5 3561 "Public services associate professionals", modify
label def SOC10M5 3562 "Human resources and industrial relations officers", modify
label def SOC10M5 4113 "Local government administrative occupations", modify
label def SOC10M5 4216 "Receptionists", modify
label def SOC10M5 5431 "Butchers", modify
label def SOC10M5 6126 "Educational support assistants", modify
label def SOC10M5 6231 "Housekeepers and related occupations", modify
label def SOC10M5 9233 "Cleaners and domestics", modify
label values QUOTA QUOTA
label values QRTR QRTR
label def QRTR 1 "JM (January to March)", modify
label def QRTR 2 "AJ (April to June)", modify
label def QRTR 3 "JS (July to September)", modify
label def QRTR 4 "OD (October to December)", modify
label values HHLD HHLD
label values SEX SEX
label def SEX 1 "Male", modify
label def SEX 2 "Female", modify
label values Indd07o2 Indd07o2
label def Indd07o2 -9 "Does not apply", modify
label def Indd07o2 -8 "No answer", modify
label def Indd07o2 47 "47  Retail trade, except vehicles", modify
label def Indd07o2 85 "85  Education", modify
label def Indd07o2 96 "96  Other personal service activities", modify
label values SCHM12 SCHM125
label def SCHM125 -9 "Does not apply", modify
label def SCHM125 50 "Any other training scheme", modify
label def SCHM125 66 "or none of these?", modify
label values NETWK2 NETWK25
label def NETWK25 -9 "Does not apply", modify
label values NETWK NETWK5
label def NETWK5 -9 "Does not apply", modify
label values IOTCOME IOTCOME5
label def IOTCOME5 1 "Personal response", modify
label def IOTCOME5 2 "Proxy response", modify
label def IOTCOME5 7 "Economically inactive 70+", modify
label values AGE AGE5
label values AGES AGES5
label def AGES5 6 "25-29yrs", modify
label def AGES5 7 "30-34yrs", modify
label def AGES5 8 "35-39yrs", modify
label def AGES5 10 "45-49yrs", modify
label def AGES5 11 "50-54yrs", modify
label def AGES5 12 "55-59yrs", modify
label def AGES5 13 "60-64yrs", modify
label def AGES5 14 "65-69yrs", modify
label def AGES5 15 "70 and over", modify


Any insights on what I could do and solve this problem?

Many thanks in advance!