Hello everyone, I have an unbalanced panel, and I want to create a variable that identifies all observations that have 4 observations in the panel, specifically the last 4 quarters, it does not matter for example if there are 5 observations, 4 in the last 4 quarters and the other in the first one as long as there are data for the last 4 quarters
I tried something this but it didn´t work
Code:
. xtdescribe, p(20) cid: 1, 2, ..., 115365 n = 71046 trimestre: 6985q2, 6985q3, ..., 6991q1 T = 12 Delta(trimestre) = 1 quarter Span(trimestre) = 24 periods (cid*trimestre uniquely identifies each observation) Distribution of T_i: min 5% 25% 50% 75% 95% max 1 1 2 3 5 5 12 Freq. Percent Cum. | Pattern ---------------------------+-------------------------- 4858 6.84 6.84 | 1....................... 4401 6.19 13.03 | .......................1 4056 5.71 18.74 | 11...................... 3833 5.40 24.14 | ......................11 3538 4.98 29.12 | .....................111 3532 4.97 34.09 | 111..................... 3228 4.54 38.63 | 1111.................... 3105 4.37 43.00 | ....................1111 2730 3.84 46.84 | ..........1111......1... 2711 3.82 50.66 | .............1......1111 2704 3.81 54.47 | ...........111......11.. 2692 3.79 58.26 | 1111......1............. 2667 3.75 62.01 | ..11......111........... 2632 3.70 65.71 | ...1......1111.......... 2582 3.63 69.35 | ............11......111. 2482 3.49 72.84 | .111......11............ 727 1.02 73.86 | .1...................... 591 0.83 74.70 | .....................1.. 549 0.77 75.47 | ..........1............. 547 0.77 76.24 | ....................1... 16881 23.76 100.00 | (other patterns) ---------------------------+-------------------------- 71046 100.00 | XXXX......XXXX......XXXX .
Code:
tab trimestre, gen (tri) . egen tag=tag(cid) . egen trimestre1=count( tri9), by (cid) . egen trimestre2=count( tri9), by (cid) . egen trimestre3=count( tri9), by (cid) . drop trimestre2 . drop trimestre3 . egen trimestre2=count( tri10), by (cid) . egen trimestre3=count( tri11), by (cid) . egen trimestre4=count( tri12), by (cid) . gen panel_2012=1 if tag==1 & trimestre1==1 & trimestre2==1 & trimestre3==1 & trimestre4==1 (216,769 missing values generated)