Dear statalist reader,
Currently I am merging 2 databases(compustat and execomp) on company ID (Cusip) and years (fyear).
Sequence of events:
1. The first problem was the difference in cusip digits between the databases. I sloved this by reducing the number of Cusip digits to 6.
2. The second problem is the merging.
The codes I use thus far:
The problem I encounter is that stata does not merge the new 6 digit cusips in a correct way.
The match is wrong.
I cannot find a mistake in the code above. Does anyone know how to solve this problem?
Kind Regards!
Currently I am merging 2 databases(compustat and execomp) on company ID (Cusip) and years (fyear).
Sequence of events:
1. The first problem was the difference in cusip digits between the databases. I sloved this by reducing the number of Cusip digits to 6.
2. The second problem is the merging.
The codes I use thus far:
Code:
use "$dir\CompustatFinancials_data", clear drop if missing(cusip) *Creating 6 digit cusip in stead of 9 gen cusip6=substr(cusip,1,6) rename cusip CUSIP9 rename cusip6 cusip *Deleting duplicates sort cusip fyear quietly by cusip fyear: gen dup = cond(_N==1, 0,_n) tab dup drop if dup>0 drop dup encode cusip, gen(Cusip) *Setting panel data xtset Cusip fyear *Format format Cusip %6.0f format fyear %4.0f *Save to file save CompustatFinancials_data_1.dta, replace use "$dir\Execcomp_data", clear drop if missing(cusip) rename year fyear *Creating 6 digit cusip in stead of 8 gen cusip6=substr(cusip,1,6) rename cusip CUSIP8 rename cusip6 cusip *Deleting duplicates sort cusip fyear quietly by cusip fyear: gen dup = cond(_N==1, 0,_n) tab dup drop if dup>0 drop dup encode cusip, gen(Cusip) *Setting panel data xtset Cusip fyear *Save to file save Execcomp_data_1.dta, replace *Merging 2 datasets use "$dir\CompustatFinancials_data_1" merge 1:1 Cusip fyear using Execcomp_data_1.dta
The problem I encounter is that stata does not merge the new 6 digit cusips in a correct way.
The match is wrong.
I cannot find a mistake in the code above. Does anyone know how to solve this problem?
Kind Regards!

Comment