Dear Stata Users,
Please, help me to resolve the following issue. Below I have a dataset. I need to feel “short” with “zero” all missing observation (based of “fdate” – year/month), where there is a gap in “fdate”. For example, for firm gvkey = 001004 there in missing fdate = 1989m5. So, I need to create this missing row and fill “short” with “zero”. For gvkey - 002020 there is a missing date of 1994m8, 1994m9. As before, I need two extra rows with all the variables and short==0. So the only restriction is that short should equal to zero for firms with missing observations (based on missing “fdate”) that lie within minimum “fdate” and maximum “fdate” that is present in the data sample.
Please, help me with this issue.



Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str6 gvkey float(year month fdate short)
"001004" 1989  1 348  11428
"001004" 1989  2 349   9300
"001004" 1989  3 350  48789
"001004" 1989  4 351  15009
"001004" 1989  6 353  46188
"001004" 1989  7 354  56251
"001004" 1989  8 355 121489
"001004" 1989  9 356 136398
"001004" 1989 10 357 108341
"001004" 1989 11 358 119100
"001004" 1989 12 359  81300
"001004" 1990  1 360  35871
"001004" 1990  2 361  21070
"001004" 1990  3 362  71900
"001004" 1990  4 363  81941
"001004" 1990  5 364  68870
"001004" 1990  6 365  95258
"001004" 1990  7 366 100808
"001004" 1990  8 367 147758
"001004" 1990  9 368 124800
"001004" 1990 10 369 103875
"001004" 1990 11 370  86360
"001004" 1990 12 371 160050
"001004" 1991  1 372  82650
"001004" 1991  2 373 329988
"001004" 1991  3 374  87426
"001004" 1991  4 375  60990
"001004" 1991  5 376  27297
"001004" 1991  6 377  20640
"001004" 1991  7 378  17940
"001004" 1991  8 379  35498
"001004" 1991  9 380  76827
"001004" 1991 10 381  96424
"001004" 1991 11 382  44915
"001004" 1991 12 383 108947
"001004" 1992  1 384 106710
"001004" 1992  4 387   3005
"001004" 1992  5 388  35181
"001004" 1992  6 389  40041
"001004" 1992  7 390  11400
"001004" 1992  8 391  15497
"001004" 1992  9 392  13950
"001004" 1992 10 393  27204
"001004" 1992 11 394  19965
"001004" 1992 12 395   9452
"001004" 1993  1 396  41250
"001004" 1993  2 397   4538
"001004" 1993  3 398  58290
"002020" 1993  4 399  39700
"002020" 1993  5 400  60600
"002020" 1993  6 401    875
"002020" 1993  7 402  51410
"002020" 1993  8 403  47500
"002020" 1993  9 404  46900
"002020" 1993 10 405  59200
"002020" 1993 11 406  47800
"002020" 1993 12 407  39100
"002020" 1994  1 408  25309
"002020" 1994  2 409  39342
"002020" 1994  3 410  21600
"002020" 1994  4 411  26100
"002020" 1994  5 412  21900
"002020" 1994  6 413   6100
"002020" 1994  7 414   6600
"002020" 1994 10 417   6150
"002020" 1994 11 418  19450
"002020" 1994 12 419  42550
"002020" 1995  1 420  26722
"002020" 1995  2 421   3418
"002020" 1995  3 422   8177
"002020" 1995  4 423   3942
"002020" 1995  5 424  80142
"002020" 1995  6 425 103277
"002020" 1995  7 426  31650
"002020" 1995  8 427  14950
"002020" 1995  9 428  14050
"002020" 1995 10 429  38450
"002020" 1995 11 430  14270
"002020" 1995 12 431   4700
"002020" 1996  1 432   7300
"002020" 1996  2 433      0
"002020" 1996  3 434  18194
"002020" 1996  4 435  14785
"002020" 1996  5 436  40285
"002020" 1996  6 437  15685
"002020" 1996  7 438  15285
"002020" 1996  8 439  29085
"002020" 1996  9 440  69285
"002020" 1996 10 441 111685
"002020" 1996 11 442 158782
"002020" 1996 12 443 106562
"002020" 1997  1 444 161350
"002020" 1997  2 445  99460
"002020" 1997  3 446 249823
"002020" 1997  4 447 405050
"002020" 1997  5 448 451523
"002020" 1997  6 449 364347
"002020" 1997  7 450 325880
end
format %tm fdate