{smcl}
{com}{sf}{ul off}{txt}{.-}
      name:  {res}<unnamed>
       {txt}log:  {res}D:\Dropbox\_AJudge Research Project\x__Old_March2023\for_fuzzy_match\fuzzy_findisc_compustat.smcl
  {txt}log type:  {res}smcl
 {txt}opened on:  {res}25 Sep 2024, 22:09:14
{txt}
{com}. 
. ** The code below can only be run once, after downloading raw compustat data.
. /*
> use compustat_unique_firm_year, clear
> capture drop if indfmt == "FS"
> capture drop curcd popsrc costat consol datafmt indfmt 
> 
> rename conm company
> rename fyear year
> *** CLEAR UP SUFFIXES IN COMPUSTAT NAMES ***
>         * standardize crsp and refUSA company names 
>         * INC, CO, CORP, PLC, N V, L P, LP
>         qui gen company_last3 = substr(company, -3, .)
>         qui gen company_last4 = substr(company, -4, .)
>         qui gen company_last5 = substr(company, -5, .)
>         qui gen company_clean = company
>                 qui replace company_clean = substr(company,1,length(company)-3) if (company_last3 == " CO"| company_last3 == " LP"| company_last3 == " NV"| company_last3 == " IN"| company_last3 == " DE"| company_last3 == " NY")
>                 qui replace company_clean = substr(company,1,length(company)-4) if (company_last4 == " INC" | company_last4 == " PLC" | company_last4 == " LTD" | company_last4 == " N V" | company_last4 == " NEW"| company_last4 == " L P")
>                 qui replace company_clean = substr(company,1,length(company)-5) if (company_last5 == " CORP")
>         qui replace company_clean = subinstr(company_clean, " ", "",.)
>         qui replace company_clean = subinstr(company_clean, ".", "",.)
>         qui replace company_clean = subinstr(company_clean, "-", "",.)
>         qui replace company_clean = subinstr(company_clean, "'", "",.)
>         qui replace company_clean = subinstr(company_clean, "(", "",.)
>         qui replace company_clean = subinstr(company_clean, ")", "",.)
>         qui replace company_clean = subinstr(company_clean, `"""', "",.)
>         drop company_last*
>         * Note - we will ultimately match on company_clean
> duplicates drop gvkey year, force
> qui gen firmyear_index = _n // we need a unique id for each firm-year obs 
> 
> save compustat_unique_firm_year, replace
> */
. 
. *****************************************************************
. *** Now clean up the disclosure data and try to fuzzy match to Compustat 
. use financial_disclosure_nogvkey.dta, clear
{txt}
{com}.         keep index comp_name file_year 
{txt}
{com}.         rename file_year year
{res}{txt}
{com}. 
. 
. * generate clean version of company name
.         qui gen company_last3 = substr(comp_name, -3, .)
{txt}
{com}.         qui gen company_last4 = substr(comp_name, -4, .)
{txt}
{com}.         qui gen company_last5 = substr(comp_name, -5, .)
{txt}
{com}.         qui gen company_clean = comp_name
{txt}
{com}.                 qui replace company_clean = substr(comp_name,1,length(comp_name)-3) if (company_last3 == " CO"| company_last3 == " LP"| company_last3 == " NV"| company_last3 == " IN"| company_last3 == " DE"| company_last3 == " NY")
{txt}
{com}.                 qui replace company_clean = substr(comp_name,1,length(comp_name)-4) if (company_last4 == " INC" | company_last4 == " PLC" | company_last4 == " LTD" | company_last4 == " N V" | company_last4 == " NEW"| company_last4 == " L P")
{txt}
{com}.                 qui replace company_clean = substr(comp_name,1,length(comp_name)-5) if (company_last5 == " CORP")
{txt}
{com}.         qui replace company_clean = subinstr(company_clean, " ", "",.)
{txt}
{com}.         qui replace company_clean = subinstr(company_clean, ".", "",.)
{txt}
{com}.         qui replace company_clean = subinstr(company_clean, "-", "",.)
{txt}
{com}.         qui replace company_clean = subinstr(company_clean, "'", "",.)
{txt}
{com}.         qui replace company_clean = subinstr(company_clean, "(", "",.)
{txt}
{com}.         qui replace company_clean = subinstr(company_clean, ")", "",.)
{txt}
{com}.         qui replace company_clean = subinstr(company_clean, `"""', "",.)
{txt}
{com}.         drop company_last*
{txt}
{com}. 
. * Force matches within year
. foreach i of num 2003/2016 {c -(}
{txt}  2{com}.     preserve
{txt}  3{com}.         keep if year == `i'
{txt}  4{com}.         reclink company_clean year using "compustat_unique_firm_year.dta", require(year) gen(matchscore) idm(index ) idu(firmyear_index) wmatch(20 1)
{txt}  5{com}.                 keep if _merge == 3
{txt}  6{com}.                         drop _merge
{txt}  7{com}.                 rename company_clean company_clean_findisc
{txt}  8{com}.                 rename Ucompany_clean company_clean_compustat
{txt}  9{com}.                 
.                 
.         gsort -matchscore
{txt} 10{com}.         save potential_disclosure_compustat_matches_`i', replace
{txt} 11{com}.         restore
{txt} 12{com}. {c )-}               
{txt}(855,268 observations deleted)

{res}8 perfect matches found

{txt}Going through 62734 observation to assess fuzzy matches, each .=5% complete
....................
Added: firmyear_index= identifier from compustat_unique_firm_year.dta   matchscore = matching score
{res}Observations:  Master N = 62742    compustat_unique_firm_year.dta N= 236472 
  Unique Master Cases: matched = 2739 (exact = 8), unmatched = 60003
{txt}(60,003 observations deleted)
{res}{txt}{p 0 4 2}
file {bf}
potential_disclosure_compustat_matches_2003.dta{rm}
saved
{p_end}
(868,706 observations deleted)

{res}14 perfect matches found

{txt}Going through 49290 observation to assess fuzzy matches, each .=5% complete
....................
Added: firmyear_index= identifier from compustat_unique_firm_year.dta   matchscore = matching score
{res}Observations:  Master N = 49304    compustat_unique_firm_year.dta N= 236472 
  Unique Master Cases: matched = 2154 (exact = 14), unmatched = 47150
{txt}(47,150 observations deleted)
{res}{txt}{p 0 4 2}
file {bf}
potential_disclosure_compustat_matches_2004.dta{rm}
saved
{p_end}
(855,505 observations deleted)

{res}29 perfect matches found

{txt}Going through 62476 observation to assess fuzzy matches, each .=5% complete
....................
Added: firmyear_index= identifier from compustat_unique_firm_year.dta   matchscore = matching score
{res}Observations:  Master N = 62505    compustat_unique_firm_year.dta N= 236472 
  Unique Master Cases: matched = 3439 (exact = 29), unmatched = 59066
{txt}(59,066 observations deleted)
{res}{txt}{p 0 4 2}
file {bf}
potential_disclosure_compustat_matches_2005.dta{rm}
saved
{p_end}
(854,431 observations deleted)

{res}25 perfect matches found

{txt}Going through 63554 observation to assess fuzzy matches, each .=5% complete
....................
Added: firmyear_index= identifier from compustat_unique_firm_year.dta   matchscore = matching score
{res}Observations:  Master N = 63579    compustat_unique_firm_year.dta N= 236472 
  Unique Master Cases: matched = 2457 (exact = 25), unmatched = 61122
{txt}(61,122 observations deleted)
{res}{txt}{p 0 4 2}
file {bf}
potential_disclosure_compustat_matches_2006.dta{rm}
saved
{p_end}
(850,727 observations deleted)

{res}22 perfect matches found

{txt}Going through 67261 observation to assess fuzzy matches, each .=5% complete
....................
Added: firmyear_index= identifier from compustat_unique_firm_year.dta   matchscore = matching score
{res}Observations:  Master N = 67283    compustat_unique_firm_year.dta N= 236472 
  Unique Master Cases: matched = 2853 (exact = 22), unmatched = 64430
{txt}(64,430 observations deleted)
{res}{txt}{p 0 4 2}
file {bf}
potential_disclosure_compustat_matches_2007.dta{rm}
saved
{p_end}
(853,024 observations deleted)

{res}41 perfect matches found

{txt}Going through 64945 observation to assess fuzzy matches, each .=5% complete
....................
Added: firmyear_index= identifier from compustat_unique_firm_year.dta   matchscore = matching score
{res}Observations:  Master N = 64986    compustat_unique_firm_year.dta N= 236472 
  Unique Master Cases: matched = 3060 (exact = 41), unmatched = 61926
{txt}(61,926 observations deleted)
{res}{txt}{p 0 4 2}
file {bf}
potential_disclosure_compustat_matches_2008.dta{rm}
saved
{p_end}
(852,871 observations deleted)

{res}66 perfect matches found

{txt}Going through 65073 observation to assess fuzzy matches, each .=5% complete
....................
Added: firmyear_index= identifier from compustat_unique_firm_year.dta   matchscore = matching score
{res}Observations:  Master N = 65139    compustat_unique_firm_year.dta N= 236472 
  Unique Master Cases: matched = 2311 (exact = 66), unmatched = 62828
{txt}(62,828 observations deleted)
{res}{txt}{p 0 4 2}
file {bf}
potential_disclosure_compustat_matches_2009.dta{rm}
saved
{p_end}
(852,954 observations deleted)

{res}0 perfect matches found

{txt}Going through 65056 observation to assess fuzzy matches, each .=5% complete
....................
Added: firmyear_index= identifier from compustat_unique_firm_year.dta   matchscore = matching score
{res}Observations:  Master N = 65056    compustat_unique_firm_year.dta N= 236472 
  Unique Master Cases: matched = 2398 (exact = 0), unmatched = 62658
{txt}(62,658 observations deleted)
{res}{txt}{p 0 4 2}
file {bf}
potential_disclosure_compustat_matches_2010.dta{rm}
saved
{p_end}
(853,073 observations deleted)

{res}0 perfect matches found

{txt}Going through 64937 observation to assess fuzzy matches, each .=5% complete
....................
Added: firmyear_index= identifier from compustat_unique_firm_year.dta   matchscore = matching score
{res}Observations:  Master N = 64937    compustat_unique_firm_year.dta N= 236472 
  Unique Master Cases: matched = 2495 (exact = 0), unmatched = 62442
{txt}(62,442 observations deleted)
{res}{txt}{p 0 4 2}
file {bf}
potential_disclosure_compustat_matches_2011.dta{rm}
saved
{p_end}
(864,360 observations deleted)

{res}1 perfect matches found

{txt}Going through 53649 observation to assess fuzzy matches, each .=5% complete
....................
Added: firmyear_index= identifier from compustat_unique_firm_year.dta   matchscore = matching score
{res}Observations:  Master N = 53650    compustat_unique_firm_year.dta N= 236472 
  Unique Master Cases: matched = 1704 (exact = 1), unmatched = 51946
{txt}(51,946 observations deleted)
{res}{txt}{p 0 4 2}
file {bf}
potential_disclosure_compustat_matches_2012.dta{rm}
saved
{p_end}
(851,488 observations deleted)

{res}0 perfect matches found

{txt}Going through 66522 observation to assess fuzzy matches, each .=5% complete
....................
Added: firmyear_index= identifier from compustat_unique_firm_year.dta   matchscore = matching score
{res}Observations:  Master N = 66522    compustat_unique_firm_year.dta N= 236472 
  Unique Master Cases: matched = 2141 (exact = 0), unmatched = 64381
{txt}(64,381 observations deleted)
{res}{txt}{p 0 4 2}
file {bf}
potential_disclosure_compustat_matches_2013.dta{rm}
saved
{p_end}
(846,009 observations deleted)

{res}1 perfect matches found

{txt}Going through 72000 observation to assess fuzzy matches, each .=5% complete
....................
Added: firmyear_index= identifier from compustat_unique_firm_year.dta   matchscore = matching score
{res}Observations:  Master N = 72001    compustat_unique_firm_year.dta N= 236472 
  Unique Master Cases: matched = 3091 (exact = 1), unmatched = 68910
{txt}(68,910 observations deleted)
{res}{txt}{p 0 4 2}
file {bf}
potential_disclosure_compustat_matches_2014.dta{rm}
saved
{p_end}
(849,853 observations deleted)

{res}18 perfect matches found

{txt}Going through 68139 observation to assess fuzzy matches, each .=5% complete
....................
Added: firmyear_index= identifier from compustat_unique_firm_year.dta   matchscore = matching score
{res}Observations:  Master N = 68157    compustat_unique_firm_year.dta N= 236472 
  Unique Master Cases: matched = 2613 (exact = 18), unmatched = 65544
{txt}(65,544 observations deleted)
{res}{txt}{p 0 4 2}
file {bf}
potential_disclosure_compustat_matches_2015.dta{rm}
saved
{p_end}
(825,861 observations deleted)

{res}1 perfect matches found

{txt}Going through 92148 observation to assess fuzzy matches, each .=5% complete
....................
Added: firmyear_index= identifier from compustat_unique_firm_year.dta   matchscore = matching score
{res}Observations:  Master N = 92149    compustat_unique_firm_year.dta N= 236472 
  Unique Master Cases: matched = 1845 (exact = 1), unmatched = 90304
{txt}(90,304 observations deleted)
{res}{txt}{p 0 4 2}
file {bf}
potential_disclosure_compustat_matches_2016.dta{rm}
saved
{p_end}

{com}. 
. use potential_disclosure_compustat_matches_2003, clear
{txt}
{com}. foreach i of num 2004/2016 {c -(}
{txt}  2{com}.     append using potential_disclosure_compustat_matches_`i'
{txt}  3{com}. {c )-}
{txt}
{com}. 
. export delim "potential_disclosure_compustat_matches.csv", replace
{res}{txt}file {bf:potential_disclosure_compustat_matches.csv} saved

{com}. 
. log close
      {txt}name:  {res}<unnamed>
       {txt}log:  {res}D:\Dropbox\_AJudge Research Project\x__Old_March2023\for_fuzzy_match\fuzzy_findisc_compustat.smcl
  {txt}log type:  {res}smcl
 {txt}closed on:  {res}26 Sep 2024, 17:53:36
{txt}{.-}
{smcl}
{txt}{sf}{ul off}