Hi, I have an unbalanced panel data set with dbtr_crdtr as the panel variable and DT_INCPTNM the monthly time variable (with gaps). I want to create a unique id, by dbtr_crdtr, for observations in the six months following a "switch" which is indicated by the variable SWITCH_DUMMY == 1. All observations not in this six months window following the switch or dbtr_crdtr ids without a "switch" can be attributed the same id (0 in the example below). I gave an example of the variable to be created. As the dataset is very large ( ~ 4 million observations) and contains close to a million dbtr_crdtr ids I cannot use a reshape.
Does anybody have an idea how I could produce this "UniqueID" or can at least give me a hint on how this could be realised?
KR,
Bob
dbtr_crdtr DT_INCPTNM SWITCH_DUMMY UniqueID(var to be created)
1472 2021m2 0 0
1472 2021m10 0 0
1472 2021m11 0 0
1472 2021m12 0 0
1472 2022m3 0 0
1472 2022m4 0 0
1268 2022m3 1 1
1268 2022m4 0 1
1268 2022m5 0 1
1268 2022m6 0 1
1268 2022m8 0 1
1273 2022m4 1 2
1273 2022m8 0 2
1274 2023m6 0 0
1275 2021m8 0 0
1477 2023m8 1 3
1477 2023m9 0 3
1477 2024m4 0 0
Does anybody have an idea how I could produce this "UniqueID" or can at least give me a hint on how this could be realised?
KR,
Bob
dbtr_crdtr DT_INCPTNM SWITCH_DUMMY UniqueID(var to be created)
1472 2021m2 0 0
1472 2021m10 0 0
1472 2021m11 0 0
1472 2021m12 0 0
1472 2022m3 0 0
1472 2022m4 0 0
1268 2022m3 1 1
1268 2022m4 0 1
1268 2022m5 0 1
1268 2022m6 0 1
1268 2022m8 0 1
1273 2022m4 1 2
1273 2022m8 0 2
1274 2023m6 0 0
1275 2021m8 0 0
1477 2023m8 1 3
1477 2023m9 0 3
1477 2024m4 0 0
Comment