I have 1200 companies that are identified by CIQ_IDs. I also have an id variable within each CIQ_ID, which are numbered 1 through approximately 507 (this is called each_co_id) and I have approximately 507 trading dates that correspond to the years 2020 & 2021. However, some AdjClose prices may be missing. Here is a sample of the data:

Code:
* Example generated by -dataex-. For more info, type help dataex
clear
input str12 CIQ_ID int(each_co_id date) double AdjClose
"IQ100231"      1 21916         .
"IQ100231"      2 21917         .
"IQ100231"      3 21920  24.69812
"IQ100231"      4 21921  24.82523
"IQ100231"      5 21922  24.85066
"IQ100231"      6 21923  24.94599
"IQ100231"      7 21924  25.02226
"IQ100231"      8 21927  24.99006
"IQ100231"      9 21928  24.84192
"IQ100231"     10 21929   24.5392
"IQ100231"     11 21930  24.53276
"IQ100231"     12 21931  24.39107
"IQ100231"     13 21934  24.49412
"IQ100231"     14 21935  24.71954
"IQ100231"     15 21936  24.80972
"IQ100231"     16 21937  25.14463
"IQ100231"     17 21938  24.88056
"IQ100231"     18 21941  24.79683
"IQ100231"     19 21942  24.63582
"IQ100231"     20 21943  24.84836
"IQ100231"     21 21944  23.86293
"IQ100231"     22 21945  24.10767
"IQ100231"     23 21948  24.23005
"IQ100231"     24 21949  23.80496
"IQ100231"     25 21950  24.23649
"IQ100231"     26 21951  24.35242
"IQ100231"     27 21952  24.75819
"IQ100231"     28 21955  24.76463
"IQ100231"     29 21956  24.69378
"IQ100231"     30 21957  24.58429
"IQ100231"     31 21958  24.50056
"IQ100231"     32 21959  24.67446
"IQ100231"     33 21962  24.63582
"IQ100231"     34 21963  24.64226
"IQ100231"     35 21964  24.75819
"IQ100231"     36 21965  24.86768
"IQ100231"     37 21966  24.82904
"IQ100231"     38 21969    24.507
"IQ100231"     39 21970  24.05615
"IQ100231"     40 21971  23.89513
"IQ100231"     41 21972  23.01275
"IQ100231"     42 21973  22.68427
"IQ100231"     43 21976  23.94666
"IQ100231"     44 21977  23.37987
"IQ100231"     45 21978  24.59073
"IQ100231"     46 21979  23.94666
"IQ100231"     47 21980  23.85005
"IQ100231"     48 21983  22.34291
"IQ100231"     49 21984  23.09004
"IQ100231"     50 21985  22.23342
"IQ100231"     51 21986  20.17883
"IQ100231"     52 21987  22.20122
"IQ100231"     53 21990  20.48798
"IQ100231"     54 21991  21.73104
"IQ100231"     55 21992  21.15782
"IQ100231"     56 21993  20.06289
"IQ100231"     57 21994  18.32389
"IQ100231"     58 21997  17.24185
"IQ100231"     59 21998  18.09203
"IQ100231"     60 21999  18.29169
"IQ100231"     61 22000  19.70865
"IQ100231"     62 22001  19.21916
"IQ100231"     63 22004  19.47035
"IQ100231"     64 22005  18.77475
"IQ100231"     65 22006  18.06626
"IQ100231"     66 22007  18.52356
"IQ100231"     67 22008  17.68626
"IQ100231"     68 22011  18.96153
"IQ100231"     69 22012  19.37373
"IQ100231"     70 22013  19.59002
"IQ100231"     71 22014  20.14056
"IQ100231"     72 22019  19.78664
"IQ100231"     73 22020  20.40272
"IQ100231"     74 22021   19.7211
"IQ100231"     75 22022  19.76698
"IQ100231"     76 22025  20.46826
"IQ100231"     77 22026  20.30441
"IQ100231"     78 22027  19.57691
"IQ100231"     79 22028  19.31475
"IQ100231"     80 22029  19.33441
"IQ100231"     81 22032  19.47204
"IQ100231"     82 22033  20.01603
"IQ100231"     83 22034  20.08812
"IQ100231"     84 22035  20.59934
"IQ100231"     85 22036  19.97015
"IQ100231"     86 22039  19.59657
"IQ100231"     87 22040  19.39995
"IQ100231"     88 22041  19.49171
"IQ100231"     89 22042  18.86907
"IQ100231"     90 22046  18.93461
"IQ100231"     91 22047  19.52448
"IQ100231"     92 22048  19.25576
"IQ100231"     93 22049  18.93461
"IQ100231"     94 22050  18.41029
"IQ100231"     95 22053  18.73144
"IQ100231"     96 22054  18.55448
"IQ100231"     97 22055  19.30164
"IQ100231"     98 22056  18.98049
"IQ100231"     99 22057   19.3934
"IQ100231"    100 22061  19.51137
"IQ100231"    101 22062  19.58346
"IQ100231"    102 22063  20.19954
"IQ100231"    103 22064  20.87461
"IQ100231"    104 22067  20.35684
"IQ100231"    105 22068  20.22576
"IQ100231"    106 22069  20.27164
"IQ100231"    107 22070  20.31096
"IQ100231"    108 22071  20.65177
"IQ100231"    109 22074  20.84184
"IQ100231"    110 22075  21.47758
"IQ100231"    111 22076  21.77907
"IQ100231"    112 22077  21.37927
"IQ100231"    113 22078  21.06468
"IQ100231"    114 22081  19.77353
"IQ100231"    115 22082  19.98981
"IQ100231"    116 22083  19.98981
"IQ100231"    117 22084  20.17333
"IQ100231"    118 22085  19.83252
"IQ100231"    119 22088   19.8915
"IQ100231"    120 22089  19.86529
"IQ100231"    121 22090  19.73421
"IQ100231"    122 22091  19.82596
"IQ100231"    123 22092  19.28198
"IQ100231"    124 22095   19.4786
"IQ100231"    125 22096  19.05914
"IQ100231"    126 22097  19.60313
"IQ100231"    127 22098  19.81285
"IQ100231"    128 22099  19.59657
"IQ100231"    129 22102  19.71454
"IQ100231"    130 22103  19.98326
"IQ100231"    131 22104  19.87184
"IQ100231"    132 22105   19.9636
"IQ100231"    133 22106  19.69688
"IQ100231"    134 22109  20.09029
"IQ100231"    135 22110  19.84358
"IQ100231"    136 22111  19.97693
"IQ100231"    137 22112  20.01027
"IQ100231"    138 22113  20.26365
"IQ100231"    139 22116   20.1703
"IQ100231"    140 22117  19.90359
"IQ100231"    141 22118   20.1703
"IQ100231"    142 22119  20.11029
"IQ100231"    143 22120  19.93693
"IQ100231"    144 22123  19.71689
"IQ100231"    145 22124  19.53019
"IQ100231"    146 22125   19.7969
"IQ100231"    147 22126  19.71022
"IQ100231"    148 22127  19.71689
"IQ100231"    149 22130  19.72355
"IQ100231"    150 22131  19.75023
"IQ100231"    151 22132  20.01027
"IQ100231"    152 22133  19.90359
"IQ100231"    153 22134  19.89692
"IQ100231"    154 22137  20.01694
"IQ100231"    155 22138  20.13696
"IQ100231"    156 22139  20.13696
"IQ100231"    157 22140  20.12363
"IQ100231"    158 22141  19.94359
"IQ100231"    159 22144  20.01027
"IQ100231"    160 22145  19.90359
"IQ100231"    161 22146  19.86358
"IQ100231"    162 22147  19.82357
"IQ100231"    163 22148  19.78356
"IQ100231"    164 22151   19.7969
"IQ100231"    165 22152  20.02361
"IQ100231"    166 22153  19.93693
"IQ100231"    167 22154  19.99694
"IQ100231"    168 22155  19.93693
"IQ100231"    169 22159  20.03028
"IQ100231"    170 22160  19.87692
"IQ100231"    171 22161  19.65021
"IQ100231"    172 22162  19.80357
"IQ100231"    173 22165  19.73022
"IQ100231"    174 22166  19.61687
"IQ100231"    175 22167  19.67688
"IQ100231"    176 22168  19.58353
"IQ100231"    177 22169  19.27681
"IQ100231"    178 22172  19.33682
"IQ100231"    179 22173  19.43017
"IQ100231"    180 22174  19.41683
"IQ100231"    181 22175  19.49685
"IQ100231"    182 22176  19.38349
"IQ100231"    183 22179  19.29014
"IQ100231"    184 22180  19.09011
"IQ100231"    185 22181  19.01009
"IQ100231"    186 22182  18.58335
"IQ100231"    187 22183   18.6967
"IQ100231"    188 22186   18.6967
"IQ100231"    189 22187  18.92341
"IQ100231"    190 22188  18.87007
"IQ100231"    191 22189  19.01009
"IQ100231"    192 22190  18.99676
"IQ100231"    193 22193  19.12345
"IQ100231"    194 22194  19.11678
"IQ100231"    195 22195  19.14345
"IQ100231"    196 22196  19.20346
"IQ100231"    197 22197  19.42755
"IQ100231"    198 22200  19.23062
"IQ100231"    199 22201   19.1016
"IQ100231"    200 22202  18.84357
"IQ100231"    201 22203  18.66701
"IQ100231"    202 22204  18.63985
"IQ100231"    203 22207  18.55837
"IQ100231"    204 22208  18.25279
"IQ100231"    205 22209  18.17131
"IQ100231"    206 22210  18.14415
"IQ100231"    207 22211  19.20346
"IQ100231"    208 22214   18.8911
"IQ100231"    209 22215  18.59232
"IQ100231"    210 22216  18.27996
"IQ100231"    211 22217  17.99476
"IQ100231"    212 22218  18.17131
"IQ100231"    213 22221  18.34786
"IQ100231"    214 22222  18.56516
"IQ100231"    215 22223  18.64664
"IQ100231"    216 22224  18.36144
"IQ100231"    217 22225  18.68059
"IQ100231"    218 22228  18.63306
"IQ100231"    219 22229  19.21704
"IQ100231"    220 22230  19.59052
"IQ100231"    221 22231  19.50903
"IQ100231"    222 22232  19.31211
"IQ100231"    223 22235  19.63126
"IQ100231"    224 22236    19.672
"IQ100231"    225 22237  19.71275
"IQ100231"    226 22238  19.43434
"IQ100231"    227 22239  19.20346
"IQ100231"    228 22242  19.23062
"IQ100231"    229 22243  19.43434
"IQ100231"    230 22244  19.84856
"IQ100231"    231 22245  19.68558
"IQ100231"    232 22246  19.71275
"IQ100231"    233 22249  19.52261
"IQ100231"    234 22250   19.6041
"IQ100231"    235 22251  19.75349
"IQ100231"    236 22252  19.84856
"IQ100231"    237 22253  20.05906
"IQ100231"    238 22256  20.12696
"IQ100231"    239 22257  20.92145
"IQ100231"    240 22258  21.36283
"IQ100231"    241 22259  20.83996
"IQ100231"    242 22260  21.05726
"IQ100231"    243 22263   20.7449
"IQ100231"    244 22264  20.76527
"IQ100231"    245 22265  20.56835
"IQ100231"    246 22266  20.11338
"IQ100231"    247 22267  19.96399
"IQ100231"    248 22270  19.69917
"IQ100231"    249 22271  19.28495
"IQ100231"    250 22272  19.52261
"IQ100231"    251 22273  19.48187
"IQ100231"    252 22278   19.3868
"IQ100231"    253 22279  19.38001
"IQ100231"    254 22280  19.34606
"IQ100231"    255 22284   19.5294
"IQ100231"    256 22285  19.99116
"IQ100231"    257 22286  19.86893
"IQ100231"    258 22287  20.25598
"IQ100231"    259 22288  20.31031
"IQ100231"    260 22291  20.05461
"IQ100231"    261 22292  19.95096
"IQ100231"    262 22293  19.86803
"IQ100231"    263 22294  19.77128
"IQ100231"    264 22295   20.2412
"IQ100231"    265 22298  20.15827
"IQ100231"    266 22299  20.00624
"IQ100231"    267 22300  20.01315
"IQ100231"    268 22301  19.92331
"IQ100231"    269 22302  19.99242
"IQ100231"    270 22305  20.11681
"IQ100231"    271 22306  20.55909
"IQ100231"    272 22307  20.13754
"IQ100231"    273 22308  19.90258
"IQ100231"    274 22309   19.7851
"IQ100231"    275 22312  19.79892
"IQ100231"    276 22313  19.72291
"IQ100231"    277 22314  19.70217
"IQ100231"    278 22315  19.96478
"IQ100231"    279 22316  19.99242
"IQ100231"    280 22319  19.88185
"IQ100231"    281 22320  19.77819
"IQ100231"    282 22321  19.72982
"IQ100231"    283 22322  19.82656
"IQ100231"    284 22323  19.90258
"IQ100231"    285 22326  20.02006
"IQ100231"    286 22327   20.4347
"IQ100231"    287 22328  20.19974
"IQ100231"    288 22329  20.04079
"IQ100231"    289 22330  20.26193
"IQ100231"    290 22333  20.16518
"IQ100231"    291 22334   20.3034
"IQ100231"    292 22335   19.7851
"IQ100231"    293 22336  19.27371
"IQ100231"    294 22337  19.41193
"IQ100231"    295 22340  19.50177
"IQ100231"    296 22341   19.8473
"IQ100231"    297 22342  19.98551
"IQ100231"    298 22343  20.46925
"IQ100231"    299 22344  20.72494
"IQ100231"    300 22347  20.48307
"IQ100231"    301 22348  20.72494
"IQ100231"    302 22349  20.41397
"IQ100231"    303 22350  20.60055
"IQ100231"    304 22351  20.68348
"IQ100231"    305 22354  20.72494
"IQ100231"    306 22355  20.83551
"IQ100231"    307 22356  20.73877
"IQ100231"    308 22357    20.566
"IQ100231"    309 22358  20.72494
"IQ100231"    310 22361  20.73186
"IQ100231"    311 22362  20.72494
"IQ100231"    312 22363  20.78714
"IQ100231"    313 22364  20.94608
"IQ100231"    314 22365  21.11885
"IQ100231"    315 22368  21.23633
"IQ100231"    316 22369  20.91844
"IQ100231"    317 22370  21.05665
"IQ100231"    318 22371  21.22251
"IQ100231"    319 22376   21.4091
"IQ100231"    320 22377  21.37454
"IQ100231"    321 22378  21.08636
"IQ100231"    322 22379  21.11448
"IQ100231"    323 22382  21.05825
"IQ100231"    324 22383   20.8263
"IQ100231"    325 22384  20.89659
"IQ100231"    326 22385  20.91064
"IQ100231"    327 22386  21.05122
"IQ100231"    328 22389  21.07933
"IQ100231"    329 22390  21.00905
"IQ100231"    330 22391  21.16368
"IQ100231"    331 22392  22.04228
"IQ100231"    332 22393  22.07039
"IQ100231"    333 22396  21.72598
"IQ100231"    334 22397  21.62758
"IQ100231"    335 22398  21.76113
"IQ100231"    336 22399  22.02822
"IQ100231"    337 22400  22.07742
"IQ100231"    338 22404  22.14068
"IQ100231"    339 22405  22.50618
"IQ100231"    340 22406  22.51321
"IQ100231"    341 22407   22.7803
"IQ100231"    342 22410  22.60458
"IQ100231"    343 22411  22.93493
"IQ100231"    344 22412  22.67487
"IQ100231"    345 22413  22.47103
"IQ100231"    346 22414  22.63972
"IQ100231"    347 22417  22.66081
"IQ100231"    348 22418  22.04931
"IQ100231"    349 22419  20.77007
"IQ100231"    350 22420  20.35537
"IQ100231"    351 22421  20.83333
"IQ100231"    352 22424  21.09339
"IQ100231"    353 22425  20.91064
"IQ100231"    354 22426  20.74898
"IQ100231"    355 22427  20.77007
"IQ100231"    356 22428  20.88253
"IQ100231"    357 22432  20.68572
"IQ100231"    358 22433  20.60841
"IQ100231"    359 22434  20.81224
"IQ100231"    360 22435  20.54515
"IQ100231"    361 22438  20.57326
"IQ100231"    362 22439  20.43971
"IQ100231"    363 22440  20.36943
"IQ100231"    364 22441  20.39051
"IQ100231"    365 22442     20.51
"IQ100231"    366 22445  20.60841
"IQ100231"    367 22446  20.44674
"IQ100231"    368 22447  20.58029
"IQ100231"    369 22448  20.42566
"IQ100231"    370 22449  20.20074
"IQ100231"    371 22452  20.13748
"IQ100231"    372 22453  20.33428
"IQ100231"    373 22454  20.22885
"IQ100231"    374 22455  20.13748
"IQ100231"    375 22456  20.23588
"IQ100231"    376 22459  20.30617
"IQ100231"    377 22460  20.22885
"IQ100231"    378 22461  20.14451
"IQ100231"    379 22462  20.22885
"IQ100231"    380 22463   20.4608
"IQ100231"    381 22466  20.54515
"IQ100231"    382 22467  20.39754
"IQ100231"    383 22468  20.33428
"IQ100231"    384 22469  20.16966
"IQ100231"    385 22470  20.36291
"IQ100231"    386 22473  20.38438
"IQ100231"    387 22474  20.23408
"IQ100231"    388 22475  20.22692
"IQ100231"    389 22476   20.3486
"IQ100231"    390 22477  20.28418
"IQ100231"    391 22480  19.89052
"IQ100231"    392 22481  19.97641
"IQ100231"    393 22482  19.96925
"IQ100231"    394 22483  20.04798
"IQ100231"    395 22484  20.14819
"IQ100231"    396 22487  20.16966
"IQ100231"    397 22488  20.18398
"IQ100231"    398 22489  20.04798
"IQ100231"    399 22490  20.24839
"IQ100231"    400 22491  20.07661
"IQ100231"    401 22494  20.11956
"IQ100231"    402 22495  20.17682
"IQ100231"    403 22496  19.93347
"IQ100231"    404 22497  19.99788
"IQ100231"    405 22498   20.0122
"IQ100231"    406 22501  19.93347
"IQ100231"    407 22502  20.10524
"IQ100231"    408 22503  20.15535
"IQ100231"    409 22504  20.05514
"IQ100231"    410 22505  20.17682
"IQ100231"    411 22508  20.18398
"IQ100231"    412 22509  20.17682
"IQ100231"    413 22510  19.91915
"IQ100231"    414 22511  19.70443
"IQ100231"    415 22512  19.73306
"IQ100231"    416 22515  19.69727
"IQ100231"    417 22516  19.64717
"IQ100231"    418 22517  19.63285
"IQ100231"    419 22518   19.3394
"IQ100231"    420 22519  19.41813
"IQ100231"    421 22523   19.4897
"IQ100231"    422 22524   19.6257
"IQ100231"    423 22525  19.46107
"IQ100231"    424 22526  19.78316
"IQ100231"    425 22529   19.7259
"IQ100231"    426 22530   19.6257
"IQ100231"    427 22531  19.75453
"IQ100231"    428 22532   19.6257
"IQ100231"    429 22533  19.45392
"IQ100231"    430 22536  19.69727
"IQ100231"    431 22537  19.56128
"IQ100231"    432 22538  19.73306
"IQ100231"    433 22539  19.75453
"IQ100231"    434 22540  19.70443
"IQ100231"    435 22543  19.47539
"IQ100231"    436 22544  19.29645
"IQ100231"    437 22545  19.33224
"IQ100231"    438 22546  19.46107
"IQ100231"    439 22547  19.41813
"IQ100231"    440 22550  19.61138
"IQ100231"    441 22551  19.49686
"IQ100231"    442 22552  19.61138
"IQ100231"    443 22553  19.33224
"IQ100231"    444 22554   19.4396
"IQ100231"    445 22557  19.50402
"IQ100231"    446 22558  19.57559
"IQ100231"    447 22559  19.54696
"IQ100231"    448 22560  19.76586
"IQ100231"    449 22561  19.53237
"IQ100231"    450 22564  18.99244
"IQ100231"    451 22565  18.55466
"IQ100231"    452 22566  18.45981
"IQ100231"    453 22567  18.69329
"IQ100231"    454 22568  18.75166
"IQ100231"    455 22571  18.48169
"IQ100231"    456 22572   18.6714
"IQ100231"    457 22573  18.90488
"IQ100231"    458 22574  18.79544
"IQ100231"    459 22575  18.59844
"IQ100231"    460 22578  18.70788
"IQ100231"    461 22579  18.51088
"IQ100231"    462 22580  18.28469
"IQ100231"    463 22581  18.64221
"IQ100231"    464 22582  18.43062
"IQ100231"    465 22585  18.51088
"IQ100231"    466 22586  18.40873
"IQ100231"    467 22587  18.37225
"IQ100231"    468 22588  18.09499
"IQ100231"    469 22589  18.31388
"IQ100231"    470 22592  18.15336
"IQ100231"    471 22593  18.02932
"IQ100231"    472 22594  18.20443
"IQ100231"    473 22595  18.18254
"IQ100231"    474 22596  18.19714
"IQ100231"    475 22599  18.09499
"IQ100231"    476 22600  17.99284
"IQ100231"    477 22601  17.99284
"IQ100231"    478 22602  17.79584
"IQ100231"    479 22603  17.60613
"IQ100231"    480 22606  18.02202
"IQ100231"    481 22607   18.0658
"IQ100231"    482 22608  17.85421
"IQ100231"    483 22609   17.6718
"IQ100231"    484 22610  17.43102
"IQ100231"    485 22613   16.6576
"IQ100231"    486 22614  16.21982
"IQ100231"    487 22615  16.81812
"IQ100231"    488 22616  17.11727
"IQ100231"    489 22617  16.98594
"IQ100231"    490 22620  16.84001
"IQ100231"    491 22621  16.90568
"IQ100231"    492 22622  16.73786
"IQ100231"    493 22623   16.6649
"IQ100231"    494 22624  16.37305
"IQ100231"    495 22627   16.2636
"IQ100231"    496 22628  16.17604
"IQ100231"    497 22629  17.29968
"IQ100231"    498 22630  17.35076
"IQ100231"    499 22631  17.64991
"IQ100231"    500 22634  17.85421
"IQ100231"    501 22635  18.08039
"IQ100231"    502 22636  18.14606
"IQ100231"    503 22637  18.08039
"IQ100231"    504 22638  18.10958
"IQ100231"    505 22643  17.97825
"IQ100231"    506 22644  18.08039
"IQ100231"    507 22645  17.94906
"IQ10081196"    1 21916         .
"IQ10081196"    2 21917         .
"IQ10081196"    3 21920 135.54602
"IQ10081196"    4 21921 134.69341
"IQ10081196"    5 21922 135.98202
"IQ10081196"    6 21923 133.88924
"IQ10081196"    7 21924 135.85607
"IQ10081196"    8 21927 138.47204
"IQ10081196"    9 21928 137.52254
"IQ10081196"   10 21929 138.28795


end
format %td date

I want to identify the following and use it in generating other variables :
1. The last available i.e. non-missing AdjClose price for 2020
2. The first available i.e. non-missing AdjClose price for 2020

3. The last available i.e. non-missing AdjClose price for 2021
4. The first available i.e. non-missing AdjClose price for 2021

I would be very grateful for some help.