I have the compustat segment data that looks as follows:
And I have the compustat annual fundamentals that looks as follows:
I want to merge them by datadate and gvkey. But the segment data also has sid. The way I want is that for a given datadate and gvkey in the first table, each entry regrardless of the segment id have the data from the second table corresponding to the same gvkey and datadate.
I tried merge m:1 gvkey datadate sid using "FirmLevelData09122022.dta" but that is not going to work since the second dataset doesnt have segment id.
gvkey | stype | sid | datadate | cogss | dps |
1004 | BUSSEG | 11 | 20000531 | 0 | 4.994 |
1004 | BUSSEG | 8 | 20000531 | 422.507 | 3.526 |
1004 | BUSSEG | 12 | 20000531 | 326.641 | 3.239 |
1004 | BUSSEG | 13 | 20000531 | 195.718 | 6.304 |
1004 | GEOSEG | 1 | 19990531 | 727.714 | 17.063 |
1004 | BUSSEG | 7 | 19990531 | 727.714 | 17.063 |
1004 | BUSSEG | 9 | 19990531 | 312.523 | 5.146 |
1004 | BUSSEG | 10 | 19990531 | 107.49 | 3.455 |
1004 | GEOSEG | 1 | 19990531 | 727.714 | 17.063 |
1004 | BUSSEG | 8 | 19990531 | 457.336 | 2.916 |
gvkey | datadate | fyear | cshpri | dlc |
1004 | 19990531 | 1998 | 27.549 | 0.42 |
1004 | 20000531 | 1999 | 27.103 | 26.314 |
1004 | 20010531 | 2000 | 26.913 | 13.652 |
1004 | 20020531 | 2001 | 28.282 | 42.525 |
1004 | 20030531 | 2002 | 31.852 | 92.256 |
1004 | 20040531 | 2003 | 32.111 | 3.392 |
1004 | 20050531 | 2004 | 32.297 | 3.745 |
1004 | 20060531 | 2005 | 33.53 | 2.289 |
1004 | 20070531 | 2006 | 36.389 | 74.245 |
I tried merge m:1 gvkey datadate sid using "FirmLevelData09122022.dta" but that is not going to work since the second dataset doesnt have segment id.
Comment