Skip to content

brycewang-stanford/Auto-Empirical-Research-Skills / skills/18-jusi-aalto-stata-accounting-research

stata-accounting-research

Unverified

STATA code pattern library for empirical archival accounting research. Provides tested syntax from 126 peer-reviewed JAR (Journal of Accounting Research) replication files (2017-2025). Use when the user asks procedural questions like "How do I implement [method]?" or "Show me code for [technique]" — including: entropy balancing, propensity score matching (PSM), difference-in-differences (DiD), regression discontinuity (RDD), instrumental variables (IV), event studies (CAR/BHAR), survival analysis, Fama-MacBeth regressions, bootstrap, quantile regression, reghdfe/xtreg/areg, clustering standard errors, fixed effects, esttab/outreg2 table formatting, winsorization, leads/lags. Users can specify their variables (e.g., treatment, outcomes, controls) and receive adapted syntax. NOTE: This skill provides code patterns from published papers, not research design advice.

FileKindSize
README-original.mdmarkdown2.9 KB
SKILL.mdskill md4.8 KB
references/JAR_55_bbcl.doother59.1 KB
references/JAR_55_chaplinksy-hanley-moon.doother46.3 KB
references/JAR_55_clm.doother95.1 KB
references/JAR_55_elw.doother58.0 KB
references/JAR_55_hlsw.doother104.1 KB
references/JAR_55_kks.doother365.5 KB
references/JAR_55_lzz.doother25.5 KB
references/JAR_55_madsen.doother307.5 KB
references/JAR_55_mr.doother41.5 KB
references/JAR_56_al.doother75.3 KB
references/JAR_56_bch.doother13.5 KB
references/JAR_56_blv.doother24.6 KB
references/JAR_56_csmw.doother27.6 KB
references/JAR_56_en.doother21.2 KB
references/JAR_56_granja.doother107.9 KB
references/JAR_56_htw.doother18.6 KB
references/JAR_56_kmt.doother5.6 KB
references/JAR_56_ksvw.doother8.0 KB
references/JAR_56_llz.doother3.1 KB
references/JAR_56_ls.doother147.5 KB
references/JAR_56_lv2018.doother123.7 KB
references/JAR_57_bht.doother24.4 KB
references/JAR_57_bl.doother22.6 KB
references/JAR_57_bw.doother263.2 KB
references/JAR_57_cct.doother347.1 KB
references/JAR_57_cgw.doother195.8 KB
references/JAR_57_hcp.doother38.0 KB
references/JAR_57_honigsberg.doother99.5 KB
references/JAR_57_lehmann.doother112.8 KB
references/JAR_57_lm.doother85.5 KB
references/JAR_58_bsz.doother36.9 KB
references/JAR_58_ckm.doother52.3 KB
references/JAR_58_eyring.doother58.1 KB
references/JAR_58_gj.doother187.5 KB
references/JAR_58_gsz.doother121.6 KB
references/JAR_58_htyz.doother30.9 KB
references/JAR_58_jansen.doother99.5 KB
references/JAR_58_joshi.doother43.0 KB
references/JAR_58_kvy.doother19.5 KB
references/JAR_58_msz.doother35.0 KB
references/JAR_58_rauter.doother433.2 KB
references/JAR_58_wy.doother64.5 KB
references/JAR_58_zz.doother125.5 KB
references/JAR_59_breuer.doother826.9 KB
references/JAR_59_ctv.doother383.7 KB
references/JAR_59_dess.doother78.4 KB
references/JAR_59_hmo.doother351.6 KB
references/JAR_60_abkp.doother129.9 KB
references/JAR_60_alv.doother35.4 KB
references/JAR_60_at.doother38.5 KB
references/JAR_60_barrios.doother119.6 KB
references/JAR_60_bbin.doother72.9 KB
references/JAR_60_bdem.doother11.6 KB
references/JAR_60_bl.doother43.5 KB
references/JAR_60_bmsw.doother7.7 KB
references/JAR_60_cc.doother20.1 KB
references/JAR_60_cpss.doother15.4 KB
references/JAR_60_cstv.doother175.3 KB
references/JAR_60_dg.doother19.9 KB
references/JAR_60_duguay.doother8.0 KB
references/JAR_60_fhl.doother71.3 KB
references/JAR_60_gls.doother37.0 KB
references/JAR_60_hmryz.doother28.6 KB
references/JAR_60_hst.doother18.3 KB
references/JAR_60_kt.doother10.4 KB
references/JAR_60_mliu.doother28.3 KB
references/JAR_60_nrwx.doother14.6 KB
references/JAR_60_ptwy.doother26.6 KB
references/JAR_60_skim.doother14.7 KB
references/JAR_61_bcdr.doother524.9 KB
references/JAR_61_bkr.doother51.6 KB
references/JAR_61_bls.doother79.2 KB
references/JAR_61_bo.doother29.7 KB
references/JAR_61_ccm.doother48.7 KB
references/JAR_61_cdss.doother3.9 KB
references/JAR_61_cfhll.doother47.1 KB
references/JAR_61_cfmp.doother12.7 KB
references/JAR_61_ckor.doother77.5 KB
references/JAR_61_cllw.doother11.2 KB
references/JAR_61_clm.doother11.0 KB
references/JAR_61_deller.doother368.9 KB
references/JAR_61_dlrtw.doother30.6 KB
references/JAR_61_dlz.doother13.6 KB
references/JAR_61_drs.doother15.8 KB
references/JAR_61_ds.doother197.5 KB
references/JAR_61_glt.doother1.9 KB
references/JAR_61_gyz.doother7.5 KB
references/JAR_61_ll.doother89.3 KB
references/JAR_61_lszz.doother15.9 KB
references/JAR_61_os.doother128.9 KB
references/JAR_61_zureich.doother22.2 KB
references/JAR_62_1_bdsy_banerjee_etal.doother6.6 KB
references/JAR_62_1_bhs_bouwens_etal.doother59.7 KB
references/JAR_62_1_gsz_gu_sun_zhou.doother46.6 KB
references/JAR_62_2_dgzz_defranco_etal.doother1.8 KB
references/JAR_62_2_gmp_grewal_etal.doother37.2 KB
references/JAR_62_2_xyz_xin_etal.doother25.3 KB
references/JAR_62_3_bht_bloomfield_etal.doother16.0 KB
references/JAR_62_3_ccz_cheynel_etal.doother23.3 KB
references/JAR_62_3_kim.doother2.6 KB
references/JAR_62_3_rr_raghunandan_ruchti.doother15.5 KB
references/JAR_62_4_bd_breuer_dehaan.doother15.3 KB
references/JAR_62_4_cc_cadman_carrizosa.doother20.1 KB
references/JAR_62_4_kmsv_kohler_etal.doother91.5 KB
references/JAR_62_4_mps_marra_etal.doother68.0 KB
references/JAR_62_4_raghunandan.doother50.0 KB
references/JAR_62_4_stv_sran_etal.doother41.1 KB
references/JAR_62_4_xu.doother49.4 KB
references/JAR_62_5_aov_abraham_etal.doother418.9 KB
references/JAR_62_5_gibbons.doother80.1 KB
references/JAR_62_5_jiang.doother114.3 KB
references/JAR_62_5_kstz_krueger_etal.doother26.7 KB
references/JAR_62_5_llz_li_lou_zhang.doother6.2 KB
references/JAR_62_5_lrst_lins_etal.doother66.2 KB
references/JAR_62_5_lswy_lin_etal.doother85.2 KB
references/JAR_62_5_lw_li_wang.doother16.6 KB
references/JAR_63_1_blmv_bastiaansen_etal.doother18.5 KB
references/JAR_63_1_cvw_chen_etal.doother61.2 KB
references/JAR_63_1_fgr_frankel_etal.doother30.3 KB
references/JAR_63_1_hrsx_huang_etal.doother35.5 KB
references/JAR_63_1_jia.doother12.0 KB
references/JAR_63_2_bcrw_bakke_etal.doother271.3 KB
references/JAR_63_2_dlr_desimone_etal.doother83.5 KB
references/JAR_63_2_mqtz_mao_etal.doother94.2 KB
references/JAR_63_2_npstv_nessa_etal.doother7.0 KB
references/JAR_63_3_breuer.doother51.4 KB
references/REFERENCES.mdmarkdown30.7 KB

references/JAR_57_lehmann.do

View on GitHub
****************************************************************************************************************************************************************
****************************************************************************************************************************************************************
****************************************************************************************************************************************************************
*
*	Do corporate governance analysts matter? Evidence from the expansion of governance analyst coverage (2018)
*
*	Nico Lehmann (Georg-August University of Goettingen, nico.lehmann@wiwi.uni-goettingen.de)
*
*	The Stata do-file uses all nine datasets (see "NL_data description") as inputs and provides a detailed step-by-step description that enables other researchers to arrive at the same dataset used in my study. 
*	In addition, it shows the Stata code for the main empirical analysis presented in Table 2 of the paper.
*	The analysis is based on three different data source types:
*		(1) commercially available data (i.e., Datastream, Worldscope, IBES, TRAA),
*		(2) proprietary data (ISS coverage data, FTSE/ISS index membership data),
*		(3) publically available data (handcolleted governance data from annual reports). 
*	Please read the data description ("NL_data description") accompanying this do-file beforehand for more details on the different data sources. 
*
****************************************************************************************************************************************************************
****************************************************************************************************************************************************************
****************************************************************************************************************************************************************


*///////////////////////////////////////////////////////////////////////////////
*///////////////////////////////////////////////////////////////////////////////
*///////////////////////////////////////////////////////////////////////////////
*
*  I. Data preparation
* 
*///////////////////////////////////////////////////////////////////////////////
*///////////////////////////////////////////////////////////////////////////////
*///////////////////////////////////////////////////////////////////////////////


********************************************************************************
********************************************************************************
*  Step 1: Read and clean datasets
********************************************************************************
********************************************************************************


*-------------------------------------------------------------------------------
*  (1.1): Read and clean Datastream, Worldscope, Asset4 raw data  
*-------------------------------------------------------------------------------

set more off
use TR_data, clear // Thomson Reuters dataset contains UK panel data for the years between 2001 and 2009

***Labelling variables

*COMPANY INFO 
label var wc05350 "Date Of Fiscal Year End (Key Item)"
label var wc06001 "Company Name (Key Item)"
label var wc06008 "Isin Number "
label var wc07536 "Accounting Standards Followed"
label var wc07021 "Sic Code 1 "
label var wc05661 "Stock Index Information "

*BALANCE 
label var wc03251 "Long Term Debt (WS) (Key Item) "
label var wc02501 "Property, Plant And Equipment - Net (Key Item) "
label var wc02999 "Total Assets (WS) (Key Item) "
label var dwta "Total Assets (Datastream)"
label var dwse "Book Value of Equity (Datastream)"
label var wc03501 "Common Equity (Key Item) "  
    
*INCOME 
label var wc01001 "Net Sales Or Revenues (Key Item)"
label var wc04001 "Net Income before extraordinary items"

*CFS
label var wc04860 "Net Cash Flow - Operating Activities (Key Item) "

*DIVIDENDS, SHARES & MARKET PRICES  
label var wc05101 "Dividends Per Share (WS) (Key Item) "
label var wc05001 "Market Price - Year End "
label var mv "Market Capitalisation (Datastream)"
label var nosh "Number of shares " 
  
*OWNERSHIP 
label var noshff "Free Float Number Of Shares "

*ASSET4 Info
label var cgvscore "Corporate Governance Score (ESG - ASSET4)"  


***Clean dataset to save estimation power: Delete observations where main variables are missing (total assets [numerical] and isin [string var])
drop if wc02999==.
drop if wc06008==""

***Creating variables***
***Creating fiscal year-end information (split the wc05350 - the month/day/year string var)
split wc05350, p(.)
destring wc053501, gen(day)
destring wc053502, gen(month)
destring wc053503, gen(year)
drop wc053501 wc053502 wc053503

***Duplicates
egen i=group(wc06008)
drop if i==.
drop if year==.
drop if year==2010
duplicates report i year
duplicates drop i year, force

***Identifying pooled data structure
tsset i year

***Creating Year-Dummies (one dummy for each year)
tab year, gen(year_)

***Save data
save Master1, replace


*-------------------------------------------------------------------------------
*  (1.2): Read and clean ISS data  
*-------------------------------------------------------------------------------

set more off
insheet using ISScoverage_data.txt, clear

*Labeling key variables
label var countrycgq	"ISS Country CGQ rating" 

***Identifier and country selection
capture drop wc06008
gen wc06008=isinmanuallycompleted
drop if wc06008==""
drop if indexcgq==.
keep if country=="United Kingdom"
sort wc06008 year

***Duplicates
duplicates report wc06008 year
duplicates drop wc06008 year, force

***Save data
capture drop _merge
save Data2, replace


*-------------------------------------------------------------------------------
*  (1.3): Read and clean IBES & stock data 
*-------------------------------------------------------------------------------

set more off
use IBES_data, clear

*Labelling key variables (all variables are averaged across a period of 60 days prior to the respective fiscal year-end)
label var RECNOmedian_m60FY		"Number of issued recommendations per firm " 
label var F1NEmedian_m60FY 		"Number of issued EPS forecasts per firm "
label var MVmedian_m60FY 		"Average fiscal year’s market value of equity "
label var RV_m60FY		 		"Standard deviation of daily share returns "
label var BASmedian_m60FY 		"Bid-ask spreads based on daily closing bid and ask prices "
label var ZTDmean_m60FY 		"Proportion of zero share return days "
label var TOmedian_m60FY	 	"Stock trading volume "

***Identifier
drop if isin==""
sort isin year
gen wc06008=isin

***Duplicates
duplicates report wc06008 year
duplicates drop wc06008 year, force

***Save data
capture drop _merge
save Data3, replace


*-------------------------------------------------------------------------------
*  (1.4): Read and clean TRAA data
*-------------------------------------------------------------------------------

set more off
use TRAA_data, clear

*Labelling key variables
label var IB_InvManNonIndex			"Number of institutional investors per firm scaled by the number of all institutional investors in the market" 
label var OTCountInvMan_nonIndex 	"Number of institutional investors per firm"

***Identifier
drop if isin==""
sort isin year
gen wc06008=isin

***Duplicates
duplicates report wc06008 year
duplicates drop wc06008 year, force

***Save data
capture drop _merge
save Data4, replace


*-------------------------------------------------------------------------------
*  (1.5): Read and clean FTSE/ISS data  
*-------------------------------------------------------------------------------

set more off
import excel ISSFTSE_data.xlsx, clear sheet(Handcollected_Feb2018) first

*Labelling key variables
capture drop FTSEISScoverage
gen FTSEISScoverage=1
label var FTSEISScoverage	"FTSEISS index inclusion dummy" 
label var WtCGI 			"FTSEISS index weights"

***Year 
split Date, p(/)
destring Date1, gen(month)
destring Date2, gen(day)
destring Date3, gen(year)
drop Date1 Date2 Date3

***Sample and identifier 
drop if year==.
drop if isin==""
capture drop wc06008
gen wc06008=isin
sort wc06008 year

***Duplicates
duplicates report wc06008 year
duplicates drop wc06008 year, force

***Save data
capture drop _merge
save Data5, replace


********************************************************************************
********************************************************************************
*  Step 2: Merge datasets  
********************************************************************************
********************************************************************************


set more off
use Master1, clear
sort wc06008 year
 forvalues i = 2(1)5 {
		merge 1:1 wc06008 year using Data`i', force
		drop if _merge==2 
		drop _merge 
}
*
sort i year
***
save Master2, replace
***
use Master2, clear



********************************************************************************
********************************************************************************
*  Step 3: Compute key variables
********************************************************************************
********************************************************************************



*-------------------------------------------------------------------------------
*  (3.1): ISS & ISS/FTSE variables  
*-------------------------------------------------------------------------------

***Treatment 
gen ISScoverage=.
replace ISScoverage=0 if countrycgq==.
replace ISScoverage=1 if ISScoverage==.

***FTSEISS Index Inclusion as Treatment reason  
replace FTSEISScoverage=0 if FTSEISScoverage==.
label var FTSEISScoverage "FTSEISS index inlusion dummy"
replace WtCGI=0 if WtCGI==.
label var WtCGI "FTSEISS index weights"


*-------------------------------------------------------------------------------
*  (3.2): Dependent variables  
*-------------------------------------------------------------------------------

***Financial Analyst Following
sum F1NEmean_CY - RECNOmax_m60FY 

*Key variables  
foreach x of varlist F1NEmean_CY - RECNOmax_m60FY {
	replace `x'=0 if `x'==.
	gen ln`x'=ln(`x'+1)
	winsor `x', generate (`x'win99) p(0.01)
	winsor ln`x', generate (ln`x'win99) p(0.01)
 }
*Sample Identifier (AF_sample) 
pca F1NEmean_CY - RECNOmax_m60FY
predict AF_sample, score


***Stock Liquidity
sum BASmean_CY- MVmedian_m60FY

*Key variables 
foreach x of varlist BASmean_CY- MVmedian_m60FY {
	gen ln`x'=ln(`x'+1)
	winsor `x', generate (`x'win99) p(0.01)
	winsor ln`x', generate (ln`x'win99) p(0.01)
 }
*Sample Identifier (ML_sample)  
pca BASmean_CY- ZTDmean_m60FY  TVmean_CY- MVmedian_m60FY   
predict ML_sample, score


	
***Institutional Ownership (IO measures multiplied by 1000 for the sake of interpretation ease)
sum OwnTypCount_ALL - IB_OthersNonIndex

*Key variables 
foreach x of varlist IB_ALL - IB_OthersNonIndex  {
	replace `x'=0 if `x'==.
	replace `x'=`x'*1000
 }
*
foreach x of varlist OwnTypCount_ALL - IB_OthersNonIndex  {
	*replace `x'=0 if `x'==.
	gen ln`x'=ln(`x'+1)
	winsor `x', generate (`x'win99) p(0.01)
	winsor ln`x', generate (ln`x'win99) p(0.01)
 }
*Sample Identifier (IO_sample)  
pca OwnTypCount_ALL - IB_OthersNonIndex 
predict IO_sample, score
		
		
***Tobin's Q

*Key variables
gen lnQ = ln((dwta+(mv*1000)-dwse) / (dwta))
label var lnQ "Ln of Tobin's Q based on Datastream data"

***
foreach x of varlist lnQ {
	winsor `x', generate (`x'win99) p(0.01)
 }
*Sample Identifier (Q_sample)
pca lnQ lnQwin99  
predict Q_sample, score


*-------------------------------------------------------------------------------
*  (3.3): Control variables  
*-------------------------------------------------------------------------------

*Firm Size in Total Assets
gen lnsize=ln(dwta *1000)
label var lnsize "Ln of total assets (dwta)"

*Market Capitalization
gen lnMaCap1=ln(mv)
label var lnMaCap1 "Ln of market value (mv)"

gen lnMaCap2=ln(nosh*wc05001)
label var lnMaCap2 "Ln of market value (mv)"

*Return on assets
gen ROA=wc04001/wc02999
label var ROA "Net Income before extraordinary items (wc04001) scaled by TA (wc02999)"

* Growth in sales
gen growth=(wc01001-l.wc01001)/l.wc01001
label var growth "Percentage change in sales (wc01001)"

*Leverage
gen lev=wc03251  /wc02999
label var lev"Accounting leverage long-term debt (wc03251) to ta (wc02999)"

*Dividend per Share
gen dps= wc05101
label var dps "dividends per share (wc05101)"

*PPE to TA
gen PPE_TA=wc02501/wc02999
label var PPE_TA "Net PPE (wc02501) to total assets (wc02999)"

*Cash from operations
gen cfo=wc04860/wc02999
label var cfo "Cash flow from operations (direct) deflated by ta"

*Inverse Stock Price
gen inv_stockprice=(-1)*wc05001
label var inv_stockprice "Inverse Stock price based on (wc05001)"

*IFRS Dummy
gen IFRS=.
replace IFRS=1 if wc07536=="IFRS"
replace IFRS=0 if IFRS==.
label var IFRS "IFRS reporting (wc07536)"

*Asset4 Coverage
gen asset4=.
replace asset4=0 if cgvscore == .
replace asset4=1 if asset4 == .
label var asset4 "Asset4 coverage (based on cgvscore)"

*Creating index information (split the wc05661)
gen stockindex=wc05661
split stockindex, p(,)
sort i year
gen FTSE100=.
foreach x of varlist stockindex*  {
		replace FTSE100=1 if `x'=="FTSE 100"
		replace FTSE100=1 if `x'==" FTSE 100"
}
*
replace FTSE100=0 if FTSE100==.
label var FTSE100 "FTSE100 - 100 largest firms at the London Stock Exchange (based on wc05661)"

***
gen FTSE250=.
foreach x of varlist stockindex*  {
		replace FTSE250=1 if `x'=="FT-SE 250"
		replace FTSE250=1 if `x'==" FT-SE 250"
}
*
replace FTSE250=0 if FTSE250==.
label var FTSE250 "FTSE 250 - 250 largest firms at the London Stock Exchange (based on wc05661)"
***
gen FTSEall=.
foreach x of varlist stockindex*  {
		replace FTSEall=1 if `x'=="FTSE ALL"
		replace FTSEall=1 if `x'==" FTSE ALL"
}
*
replace FTSEall=0 if FTSEall==.
label var FTSEall "FTSE ALL - ca. 500 largest firms at the London Stock Exchange (based on wc05661)"
***
drop stockindex*


*SIC industry classification
tostring wc07021, replace
gen nul="0"
gen nul2="00"
gen nul3="000"
egen hulp=concat(nul wc07021) if length(wc07021)==3
replace wc07021=hulp if length(wc07021)==3
drop hulp
egen hulp=concat(nul wc07021) if length(wc07021)==2
replace wc07021=hulp if length(wc07021)==2
drop hulp
egen hulp=concat(nul wc07021) if length(wc07021)==1
replace wc07021=hulp if length(wc07021)==1
drop hulp
drop nul*

*First-digit SIC groups (depends on your sample size)
gen ind1=substr(wc07021,1,1)
label var ind1 "First-digit sic group"
destring ind1, replace
tab ind1, gen(ind1_)


*-------------------------------------------------------------------------------
*  (3.4): Winsorize all control variables  
*-------------------------------------------------------------------------------

set more off
foreach x of varlist lnsize- inv_stockprice noshff {
	gen ln`x'=ln(`x'+1)
	winsor `x', generate (`x'win99) p(0.01)
	winsor ln`x', generate (ln`x'win99) p(0.01)
 }
*Sample Identifier (CONTROL_sample)
pca lnsize lnMaCap1 lnMaCap2 ROA growth lev dps PPE_TA cfo inv_stockprice noshff
predict CONTROL_sample, score

*-------------------------------------------------------------------------------
*  (3.5): Define subsamples w.r.t. individual data availability   
*-------------------------------------------------------------------------------

***Overall Sample
gen sample1 = .
replace sample1=1 if (AF_sample!=. & ML_sample!=. & IO_sample!=. & Q_sample!=.)

gen sample2 = .
replace sample2=1 if (AF_sample!=. & ML_sample!=. & IO_sample!=. & Q_sample!=. & CONTROL_sample!=.)

***

save Master3, replace
***
use Master3, clear


********************************************************************************
********************************************************************************
*  Step 4: Impose balanced sample restrictions & define DiD structure
********************************************************************************
********************************************************************************


*-------------------------------------------------------------------------------
*  (4.1): Define balanced DiD samples for each subsample 
*-------------------------------------------------------------------------------


set more off
	forvalues i = 1(1)2 {
	
		use Master3, replace
		drop if  sample`i' ==. 
		
		***PANEL Structure: 5-YEARS Structure (2003-2007) 
		gen company5y_id=i 
		replace company5y_id=0 if year_1==1
		replace company5y_id=0 if year_2==1
		replace company5y_id=0 if year_8==1
		replace company5y_id=0 if year_9==1
		sort company5y_id 
		by  company5y_id : gen eventcount5y1=_N 
		replace eventcount5y1=0 if company5y_id==0
		***
		gen CompleteSample5y=.
		replace CompleteSample5y=1 if eventcount5y1==5
		replace CompleteSample5y=0 if CompleteSample5y==.

		***CONTROL2: firms with constant ISS ratings
		gen ISS_id=ISScoverage
		sort  ISS_id  company5y_id
		by  ISS_id  company5y_id : gen eventcount5y2=_N 
		replace eventcount5y2=0 if company5y_id==0
		replace eventcount5y2=0 if ISScoverage==0
		***
		gen control5y2=.
		replace control5y2=1 if eventcount5y2==5
		replace control5y2=0 if control5y2==.

		***CONTROL1: firms with constant NON-ISS ratings
		gen nonISS_id=.
		replace nonISS_id=0 if ISScoverage ==1
		replace nonISS_id=1 if nonISS_id==.
		sort  nonISS_id  company5y_id
		by  nonISS_id  company5y_id: gen eventcount5y3=_N 
		replace eventcount5y3=0 if company5y_id==0
		replace eventcount5y3=0 if ISScoverage==1
		replace eventcount5y3=0 if control5y2==1
		***
		gen control5y1=.
		replace control5y1=1 if eventcount5y3==5
		replace control5y1=0 if control5y1==.

		***RESIDUAL: firms with and without ISS ratings (nonsystematic)
		gen ResidualGroup5y=.
		replace ResidualGroup5y=1 if CompleteSample5y==1
		replace ResidualGroup5y=0 if control5y2==1
		replace ResidualGroup5y=0 if control5y1==1
		replace ResidualGroup5y=0 if ResidualGroup5y==.

		***TREATMENT: firms with constant NON-ISS ratings prior to 2005 and constant ISS ratings afterwards
		sort isin
		by isin: egen ISScov0304y=sum(ISScoverage) if (year_3==1 | year_4==1)
		by isin: egen ISScov0507y=sum(ISScoverage) if (year_5==1 | year_6==1| year_7==1)
		replace ISScov0304y=0 if ResidualGroup5y==0
		replace ISScov0507y=0 if ResidualGroup5y==0
		replace ISScov0304y=0 if ISScov0304y==.
		replace ISScov0507y=0 if ISScov0507y==.
		sort isin
		by isin: egen MaxISScov0304y= max(ISScov0304y)
		by isin: egen MaxISScov0507y= max(ISScov0507y)
		***
		gen TreatmentGroup5y=.
		replace TreatmentGroup5y=1 if  MaxISScov0304y==0 & MaxISScov0507y==3  & ResidualGroup5y==1
		replace TreatmentGroup5y=0 if  TreatmentGroup5y==.

		***SUMMARY (control) REPORTS on each individual panel subsample
		tabstat ISScoverage if CompleteSample5y , stat (n sum mean) by(year)
		tabstat CompleteSample5y , stat (n sum mean) by(year)
		tabstat ISScoverage if control5y2 , stat (n sum mean) by(year)
		tabstat control5y2 , stat (n sum mean) by(year)
		tabstat ISScoverage if control5y1 , stat (n sum mean) by(year)
		tabstat control5y1 , stat (n sum mean) by(year)
		tabstat ISScoverage if ResidualGroup5y , stat (n sum mean) by(year)
		tabstat ResidualGroup5y , stat (n sum mean) by(year)
		tabstat ISScoverage if TreatmentGroup5y , stat (n sum mean) by(year)
		tabstat TreatmentGroup5y , stat (n sum mean) by(year)

		***TIME structure
		gen Post= year_5 + year_6 + year_7 
		gen Ante= year_3 + year_4
		gen Post_Treatment=TreatmentGroup5y*Post
		gen Ante_Treatment=TreatmentGroup5y*Ante
		gen Post_control5y1=control5y1*Post
		gen Ante_control5y1=control5y1*Ante
		gen Post_control5y2=control5y2*Post
		gen Ante_control5y2=control5y2*Ante


		***Subsample specific labelling
		rename control5y2 control5y2_s`i'
		rename control5y1 control5y1_s`i'
		rename TreatmentGroup5y TreatmentGroup5y_s`i'
		rename Post_Treatment Post_Treatment5y_s`i'
		rename Post Post5y_s`i'
		rename Ante Ante5y_s`i'

		***Clean and save
		keep wc06008 year control5y2_s`i' control5y1_s`i' TreatmentGroup5y_s`i' Post_Treatment5y_s`i' Post5y_s`i' Ante5y_s`i'
		save EM2data4_s`i', replace
}
*

*-------------------------------------------------------------------------------
*  (4.2): Merge Subsamples and Sample Selection variables with Masterfile 
*-------------------------------------------------------------------------------

set more off
use EM2data4_s1, replace	
sort wc06008 year
	forvalues i = 2(1)2 {
		merge 1:1 wc06008  year using EM2data4_s`i'
		drop if _merge ==2
		drop _merge
		save EM2data4_sALL, replace
}
*
use Master3, replace
sort wc06008 year
set more off
merge 1:1 wc06008 year using EM2data4_sALL
drop if _merge ==2
drop _merge
	
	
*-------------------------------------------------------------------------------
*  (4.3): Adjust Selection Variables for Masterfile
*-------------------------------------------------------------------------------
	
set more off
	forvalues i = 1(1)2 {
		replace  control5y2_s`i'=0 if control5y2_s`i'==.
		replace  control5y1_s`i'=0 if control5y1_s`i'==.
		replace  TreatmentGroup5y_s`i'=0 if TreatmentGroup5y_s`i'==.
		replace  Post_Treatment5y_s`i'=0 if Post_Treatment5y_s`i'==.
		replace  Post5y_s`i'=0 if Post5y_s`i'==.
		replace  Ante5y_s`i'=0 if Ante5y_s`i'==.
		
}
*
capture drop sample1-sample2


*-------------------------------------------------------------------------------
*  (4.4): PCA for COMPLETE sample with Controls (sample2)
*-------------------------------------------------------------------------------

*VARIABLE MANAGEMENT
set more off
macro dir
macro drop CG1 CG2 PERIOD TREATMENT
global CG1 			"control5y1_s2"
global CG2  		"control5y2_s2"
global PERIOD		"year_3|year_4|year_5|year_6|year_7"
global TREATMENT  	"TreatmentGroup5y_s2"

***MARKET LIQUIDITY measures based on PCA
pca lnBASmedian_m60FYwin99  ZTDmean_m60FY lnTOmedian_m60FYwin99   if   ($CG1 | $CG2 | $TREATMENT) & ($PERIOD)
predict help1  if   ($CG1 | $CG2 | $TREATMENT) & ($PERIOD), score
gen MLpc_ALLm60FY_raw = help1  
gen MLpc_ALLm60FY = MLpc_ALLm60FY_raw*(-1)  
drop help1

*** DROP Melrose Resource (MRS, Melrose Resources, GB0009354589) as it is included in FTSEISS Index but NOT in CGQ dataset - I thus correct dataset for data inconsistency in ISS files (Revision Feb 2018, location of drop command does not affect my findings)  
drop if isin=="GB0009354589"

***
save Master4, replace


*-------------------------------------------------------------------------------
*  (4.5): Handcollected governance data based on COMPLETE sample 
*-------------------------------------------------------------------------------

set more off
import excel using GOV_data.xlsx, first  sheet(data_new1) clear

*Define key variables
foreach x of varlist Board1all Board2all  Comp1all Audit1all  {
	gen `x'_d=`x'=="YES"
	replace `x'_d=. if `x'==""
}
gen GOVscore= (Board1all_d+Board2all_d+Comp1all_d+Audit1all_d)/4

*Labelling key variables
label var GOVscore 		"Composite governance index"
label var Board1all_d 	"CEO/chairman duality" 
label var Board2all_d 	"Board Independence " 
label var Comp1all_d 	"Compensation committee independence " 
label var Audit1all_d 	"Audit committee independence " 


*Sample & duplicates
egen count =count(GOVscore), by(isin)
drop if count!=3
gen HandcollectedGOV=1
capture drop wc06008
gen wc06008=isin
duplicates report wc06008 year
sort wc06008 year
keep HandcollectedGOV wc06008 year CGQdata  annualreport Board1all Board2all Comp1all Audit1all BoardSize Board1all_d Board2all_d Comp1all_d Audit1all_d GOVscore  proxyreport

*Save handcolleted data
save Handcollected_ISSGOV6, replace

*Merge handcollected data back to main file 
set more off
use Master4, clear
merge 1:1 wc06008 year using Handcollected_ISSGOV6, force
drop if _merge==2  


*Adjust handcollected dummy variables 0 for Masterfile (do not adjust numerical variables, such as BoardSize and GOVscore)
foreach x of varlist HandcollectedGOV Board1all_d Board2all_d Comp1all_d Audit1all_d  {
	replace `x'=0 if `x'==.
}
*

*Adjust treatment and control dummies (_sample2) in Masterfile for coverage of handcollected data
foreach x of varlist control5y1_s2 control5y2_s2 TreatmentGroup5y_s2 Post5y_s2 Post_Treatment5y_s2  {
	replace `x'=0 if HandcollectedGOV==0
}
*
***

save Master5, replace
***
use Master5, clear

*///////////////////////////////////////////////////////////////////////////////
*///////////////////////////////////////////////////////////////////////////////
*///////////////////////////////////////////////////////////////////////////////
*
*///////////////////////////////////////////////////////////////////////////////
*///////////////////////////////////////////////////////////////////////////////
*///////////////////////////////////////////////////////////////////////////////


*///////////////////////////////////////////////////////////////////////////////
*///////////////////////////////////////////////////////////////////////////////
*///////////////////////////////////////////////////////////////////////////////
*
*		II. RESULTS (as of November 2018)
*
*///////////////////////////////////////////////////////////////////////////////
*///////////////////////////////////////////////////////////////////////////////
*///////////////////////////////////////////////////////////////////////////////


********************************************************************************
********************************************************************************
********************************************************************************
*
*	TABLE 1: Sample Description
*
********************************************************************************
********************************************************************************
********************************************************************************

set more off
use Master3, clear

*Variable Management
macro drop CG1_all CG2_all TREATMENT_all   
global CG1_all 			"control5y1_s2"
global CG2_all  		"control5y2_s2"
global TREATMENT_all  	"TreatmentGroup5y_s2"

*-------------------------------------------------------------------------------
* Panel A (Table 1). Sample Selection
*-------------------------------------------------------------------------------

* (0) Start: Woldscope Firm universe (ISIN available)
tab year if (year_4|year_5|year_6)

* (1) Worldscope Data unavailable
drop if Q_sample ==.
drop if CONTROL_sample ==.
tab year if (year_4|year_5|year_6)

* (2) Datastream Data unavailable
drop if ML_sample ==.
tab year if (year_4|year_5|year_6)

* (3) IBES Data unavailable
drop if  AF_sample ==.
tab year if (year_4|year_5|year_6)

* (4) TRAA Data unavailable
drop if  IO_sample ==.
tab year if (year_4|year_5|year_6)

* (5) Balanced Sample Structure
use Master4, clear
*Variable Management
macro drop CG1_all CG2_all TREATMENT_all   
global CG1_all 			"control5y1_s2"
global CG2_all  		"control5y2_s2"
global TREATMENT_all  	"TreatmentGroup5y_s2"
***
tab year if (year_4|year_5|year_6)& ($TREATMENT_all | $CG1_all |$CG2_all)
tabstat ISScoverage if ($TREATMENT_all | $CG1_all|$CG2_all) & (year_4|year_5|year_6) , stat (n sum mean) 

* (6) Balanced Sample Structure with handcollected GOV data available: GOV
use Master5, clear
*Variable Management
macro drop CG1_all CG2_all TREATMENT_all   
global CG1_all 			"control5y1_s2"
global CG2_all  		"control5y2_s2"
global TREATMENT_all  	"TreatmentGroup5y_s2"
***
tab year if (year_4|year_5|year_6) & ($TREATMENT_all | $CG1_all |$CG2_all)
tabstat ISScoverage if ($TREATMENT_all | $CG1_all|$CG2_all) & (year_4|year_5|year_6) , stat (n sum mean) 


*-------------------------------------------------------------------------------
* Panel B (Table 1). Sample Distribution
*-------------------------------------------------------------------------------

tabstat ISScoverage if ($TREATMENT_all | $CG1_all |$CG2_all) & (year_4|year_5|year_6) , stat (n sum mean) by(year)
tabstat ISScoverage if $TREATMENT_all  & (year_4|year_5|year_6), stat (n sum mean) by(year)
tabstat ISScoverage if $CG1_all & (year_4|year_5|year_6), stat (n sum mean) by(year)
tabstat ISScoverage if $CG2_all & (year_4|year_5|year_6) , stat (n sum mean) by(year)

********************************************************************************
********************************************************************************
********************************************************************************
*
* TABLE 2: Baseline Results: Average Treatment Effect
*
********************************************************************************
********************************************************************************
********************************************************************************

set more off
use Master5, clear

*-------------------------------------------------------------------------------
* Panel A (Table 2): Mean comparisons 
*-------------------------------------------------------------------------------

qui estpost tabstat ISScoverage, stat(n) 
esttab using Platzhalter.rtf, replace cells("count(fmt(0))")  noobs nonumbers  title  (START)
	
foreach x of varlist GOVscore MLpc_ALLm60FY  lnRECNOmedian_m60FY IB_InvManNonIndex  {
	
set more off
use Master5, clear

*VARIABLE MANAGEMENT
set more off
macro dir  
macro drop CG1 CG2 TREATMENT POST DV PREPERIOD POSTPERIOD
global CG1 			"control5y1_s2"
global CG2  		"control5y2_s2"
global TREATMENT  	"TreatmentGroup5y_s2" 
global POST			"Post5y_s2"
global DV 			"`x'" 
global PREPERIOD 	"year_4"
global POSTPERIOD 	"year_5|year_6"

						
*** PANEL A: Main Descriptive Analysis and Univariate DiD

qui estpost tabstat $DV if ($TREATMENT ) & ($PREPERIOD) , stat(mean min max n) 
	esttab using Platzhalter.rtf, append cells("mean(fmt(2))    count(fmt(0))")  noobs nonumbers  title  ((1) TREATMENT & PREPERIOD: `x' ) compress order ($DV) keep ($DV )
qui estpost tabstat $DV if ($TREATMENT ) & ($POSTPERIOD) , stat(mean min max n) 
	esttab using Platzhalter.rtf, append cells("mean(fmt(2))    count(fmt(0))")  noobs nonumbers  title  ((2) TREATMENT & POSTPERIOD: `x') compress order ($DV)  keep ($DV)
qui estpost ttest $DV  if  ($TREATMENT) & ($PREPERIOD|$POSTPERIOD), by($PREPERIOD) 
	esttab using Platzhalter.rtf, append cells("b(fmt(2))  t(fmt(2))  p(fmt(2))  count(fmt(0))")  noobs nonumbers coeflabels(`x') title  ((1) TREATMENT & PREPERIOD vs.POSTPERIOD: `x') compress order ($DV) keep ($DV)
***
qui estpost tabstat $DV if ($CG1|$CG2 ) & ($PREPERIOD) , stat(mean min max n) 
	esttab using Platzhalter.rtf, append cells("mean(fmt(2))     count(fmt(0))")  noobs nonumbers  title  ((3) CG1CG2 & PREPERIOD: `x') compress order ($DV) keep ($DV)
qui estpost tabstat $DV if ($CG1|$CG2 ) & ($POSTPERIOD) , stat(mean min max n) 
	esttab using Platzhalter.rtf, append cells("mean(fmt(2))   count(fmt(0))")  noobs nonumbers  title  ((4) CG1CG2 & POSTPERIOD: `x') compress order ($DV) keep ($DV)
qui estpost ttest $DV  if  ($CG1|$CG2) & ($PREPERIOD|$POSTPERIOD), by($PREPERIOD) 
	esttab using Platzhalter.rtf, append cells("b(fmt(2))  t(fmt(2))  p(fmt(2))  count(fmt(0))")  noobs nonumbers coeflabels(`x') title  ((1) TREATMENT & PREPERIOD vs.POSTPERIOD: `x') compress order ($DV)  keep ($DV)
***
set more off
sort i year
gen var1 = $TREATMENT
gen var2 = ($CG1|$CG2)
***
	forvalues i = 1(1)2 {
		
		gen help1 = $DV if (var`i') & ($PREPERIOD)
		egen meanhelp1=mean(help1) if (var`i') & ($PREPERIOD), by(i)
		egen maxhelp1=max(meanhelp1)  if (var`i'), by(i)

		gen help2 = $DV if (var`i') & ($POSTPERIOD)
		egen meanhelp2=mean(help2) if (var`i') & ($POSTPERIOD), by(i)
		egen maxhelp2=max(meanhelp2)  if (var`i'), by(i)

		gen DV_var`i'diff=maxhelp2-maxhelp1
		drop help1-maxhelp2

}
***
drop var1 - var2
ttest DV_var1diff==0 if  ($PREPERIOD)
ttest DV_var2diff==0 if  ($PREPERIOD)
ttest DV_var1diff == DV_var2diff if  ($PREPERIOD), unpaired
}
*

********************************************************************************
********************************************************************************

set more off
use Master5, clear

*VARIABLE MANAGEMENT:
set more off
macro dir 
macro drop CG1  CG2 TREATMENT POST POST_TREAT DV1 CONTROLVAR1 DV2 CONTROLVAR2 PREPERIOD POSTPERIOD
global CG1 			"control5y1_s2"
global CG2  		"control5y2_s2"
global TREATMENT  	"TreatmentGroup5y_s2" 
global POST			"Post5y_s2"
global POST_TREAT   "Post_Treatment5y_s2"
global DV1 			"GOVscore" 
global CONTROLVAR1 	"lnsizewin99 levwin99 ROAwin99  growthwin99  noshffwin99 BoardSize asset4"
global DV2 			"MLpc_ALLm60FY" 
global CONTROLVAR2 	"lnMVmedian_m60FYwin99 lnRV_m60FYwin99 levwin99 ROAwin99 PPE_TAwin99 inv_stockpricewin99  IFRS noshffwin99 asset4"
global PREPERIOD 	"year_4"
global POSTPERIOD 	"year_5|year_6"

*-------------------------------------------------------------------------------
* Panel B (Table 2): Difference-in-differences regressions: CorpGov & Liquidity
*-------------------------------------------------------------------------------
						
estimates clear
quietly reg $DV1 i.$TREATMENT##i.$POST 	  	if  ($CG1|$CG2|$TREATMENT)  & ($PREPERIOD|$POSTPERIOD), vce(cluster i)
eststo
quietly areg $DV1 i.$TREATMENT##i.$POST   i.year	  	if  ($CG1|$CG2|$TREATMENT)  & ($PREPERIOD|$POSTPERIOD), a(i) cluster(i)
eststo
quietly areg $DV1 i.$TREATMENT##i.$POST  $CONTROLVAR1 i.year	  	if  ($CG1|$CG2|$TREATMENT)  & ($PREPERIOD|$POSTPERIOD), a(i) cluster(i)
eststo
quietly reg $DV2 i.$TREATMENT##i.$POST 	  	if  ($CG1|$CG2|$TREATMENT)  & ($PREPERIOD|$POSTPERIOD), vce(cluster i)
eststo
quietly areg $DV2 i.$TREATMENT##i.$POST   i.year	  	if  ($CG1|$CG2|$TREATMENT)  & ($PREPERIOD|$POSTPERIOD), a(i) cluster(i)
eststo
quietly areg $DV2 i.$TREATMENT##i.$POST  $CONTROLVAR2 i.year	  	if  ($CG1|$CG2|$TREATMENT)  & ($PREPERIOD|$POSTPERIOD), a(i) cluster(i)
eststo
esttab,  	star(* 0.10 ** 0.05 *** 0.01) b(3) stats(F N r2_a p_diff)   title (Panel B (Table 2): Difference-in-differences regressions: CorpGov & Liquidity) ///
				nonumbers mtitles("Model 1" "Model 2" "Model 3" "Model 4" "Model 5" "Model 6"   ) compress ///
				keep (1.$POST  1.$TREATMENT  1.$TREATMENT#1.$POST  $CONTROLVAR1 $CONTROLVAR2) ///
				order (1.$POST  1.$TREATMENT  1.$TREATMENT#1.$POST  $CONTROLVAR1 $CONTROLVAR2)
esttab using Platzhalter.rtf, replace ///
				star(* 0.10 ** 0.05 *** 0.01) b(3) stats(F N r2_a p_diff)  label title (Panel B (Table 2): Difference-in-differences regressions: CorpGov & Liquidity) ///
				nonumbers mtitles ("Model 1" "Model 2" "Model 3" "Model 4" "Model 5" "Model 6" ) compress varwidth(12)  modelwidth(6) ///
				keep (1.$POST  1.$TREATMENT  1.$TREATMENT#1.$POST  $CONTROLVAR1 $CONTROLVAR2) ///
				order (1.$POST  1.$TREATMENT  1.$TREATMENT#1.$POST  $CONTROLVAR1 $CONTROLVAR2)
estimates clear


********************************************************************************
********************************************************************************

set more off
use Master5, clear

*VARIABLE MANAGEMENT:
set more off
macro dir 
macro drop CG1  CG2 TREATMENT POST POST_TREAT DV1 CONTROLVAR1 DV2 CONTROLVAR2 PREPERIOD POSTPERIOD
global CG1 			"control5y1_s2"
global CG2  		"control5y2_s2"
global TREATMENT  	"TreatmentGroup5y_s2" 
global POST			"Post5y_s2"
global POST_TREAT   "Post_Treatment5y_s2"
global DV1 			"lnRECNOmedian_m60FY" 
global CONTROLVAR1 	"lnsizewin99 levwin99 ROAwin99 PPE_TAwin99 noshffwin99 IFRS inv_stockpricewin99 asset4"
global DV2 			"IB_InvManNonIndex" 
global CONTROLVAR2 	"lnsizewin99 levwin99 ROAwin99  cfowin99 dpswin99 PPE_TAwin99 IFRS inv_stockpricewin99 asset4 "
global PREPERIOD 	"year_4"
global POSTPERIOD 	"year_5|year_6"

*-------------------------------------------------------------------------------
* Panel C (Table 2): Difference-in-differences regressions: Ln(AF) & InvBreadth
*-------------------------------------------------------------------------------
						
estimates clear
quietly reg $DV1 i.$TREATMENT##i.$POST 	  	if  ($CG1|$CG2|$TREATMENT)  & ($PREPERIOD|$POSTPERIOD), vce(cluster i)
eststo
quietly areg $DV1 i.$TREATMENT##i.$POST   i.year	  	if  ($CG1|$CG2|$TREATMENT)  & ($PREPERIOD|$POSTPERIOD), a(i) cluster(i)
eststo
quietly areg $DV1 i.$TREATMENT##i.$POST  $CONTROLVAR1 i.year	  	if  ($CG1|$CG2|$TREATMENT)  & ($PREPERIOD|$POSTPERIOD), a(i) cluster(i)
eststo
quietly reg $DV2 i.$TREATMENT##i.$POST 	  	if  ($CG1|$CG2|$TREATMENT)  & ($PREPERIOD|$POSTPERIOD), vce(cluster i)
eststo
quietly areg $DV2 i.$TREATMENT##i.$POST   i.year	  	if  ($CG1|$CG2|$TREATMENT)  & ($PREPERIOD|$POSTPERIOD), a(i) cluster(i)
eststo
quietly areg $DV2 i.$TREATMENT##i.$POST  $CONTROLVAR2 i.year	  	if  ($CG1|$CG2|$TREATMENT)  & ($PREPERIOD|$POSTPERIOD), a(i) cluster(i)
eststo
esttab,  	star(* 0.10 ** 0.05 *** 0.01) b(3) stats(F N r2_a p_diff)   title (Panel C (Table 2): Difference-in-differences regressions: Ln(AF) & InvBreadth) ///
				nonumbers mtitles("Model 1" "Model 2" "Model 3" "Model 4" "Model 5" "Model 6"   ) compress ///
				keep (1.$POST  1.$TREATMENT  1.$TREATMENT#1.$POST  $CONTROLVAR1 $CONTROLVAR2) ///
				order (1.$POST  1.$TREATMENT  1.$TREATMENT#1.$POST  $CONTROLVAR1 $CONTROLVAR2)
esttab using Platzhalter.rtf, replace ///
				star(* 0.10 ** 0.05 *** 0.01) b(3) stats(F N r2_a p_diff)  label title (Panel C (Table 2): Difference-in-differences regressions: Ln(AF) & InvBreadth) ///
				nonumbers mtitles ("Model 1" "Model 2" "Model 3" "Model 4" "Model 5" "Model 6" ) compress varwidth(12)  modelwidth(6) ///
				keep (1.$POST  1.$TREATMENT  1.$TREATMENT#1.$POST  $CONTROLVAR1 $CONTROLVAR2) ///
				order (1.$POST  1.$TREATMENT  1.$TREATMENT#1.$POST  $CONTROLVAR1 $CONTROLVAR2)
estimates clear



*///////////////////////////////////////////////////////////////////////////////
*///////////////////////////////////////////////////////////////////////////////
*///////////////////////////////////////////////////////////////////////////////

*///////////////////////////////////////////////////////////////////////////////
*///////////////////////////////////////////////////////////////////////////////
*///////////////////////////////////////////////////////////////////////////////
*
*		THE END
*
*///////////////////////////////////////////////////////////////////////////////
*///////////////////////////////////////////////////////////////////////////////
*///////////////////////////////////////////////////////////////////////////////

*///////////////////////////////////////////////////////////////////////////////
*///////////////////////////////////////////////////////////////////////////////
*///////////////////////////////////////////////////////////////////////////////

****************************************************************************************************************************************************************
****************************************************************************************************************************************************************
****************************************************************************************************************************************************************
*
*	Do corporate governance analysts matter? Evidence from the expansion of governance analyst coverage (2018)
*
*	Nico Lehmann (Georg-August University of Goettingen, nico.lehmann@wiwi.uni-goettingen.de)
*
*	The Stata do-file uses all nine datasets (see "NL_data description") as inputs and provides a detailed step-by-step description that enables other researchers to arrive at the same dataset used in my study. 
*	In addition, it shows the Stata code for the main empirical analysis presented in Table 2 of the paper.
*	The analysis is based on three different data source types:
*		(1) commercially available data (i.e., Datastream, Worldscope, IBES, TRAA),
*		(2) proprietary data (ISS coverage data, FTSE/ISS index membership data),
*		(3) publically available data (handcolleted governance data from annual reports). 
*	Please read the data description ("NL_data description") accompanying this do-file beforehand for more details on the different data sources. 
*
****************************************************************************************************************************************************************
****************************************************************************************************************************************************************
****************************************************************************************************************************************************************


*///////////////////////////////////////////////////////////////////////////////
*///////////////////////////////////////////////////////////////////////////////
*///////////////////////////////////////////////////////////////////////////////
*
*  I. Data preparation
* 
*///////////////////////////////////////////////////////////////////////////////
*///////////////////////////////////////////////////////////////////////////////
*///////////////////////////////////////////////////////////////////////////////


********************************************************************************
********************************************************************************
*  Step 1: Read and clean datasets
********************************************************************************
********************************************************************************


*-------------------------------------------------------------------------------
*  (1.1): Read and clean Datastream, Worldscope, Asset4 raw data  
*-------------------------------------------------------------------------------

set more off
use TR_data, clear // Thomson Reuters dataset contains UK panel data for the years between 2001 and 2009

***Labelling variables

*COMPANY INFO 
label var wc05350 "Date Of Fiscal Year End (Key Item)"
label var wc06001 "Company Name (Key Item)"
label var wc06008 "Isin Number "
label var wc07536 "Accounting Standards Followed"
label var wc07021 "Sic Code 1 "
label var wc05661 "Stock Index Information "

*BALANCE 
label var wc03251 "Long Term Debt (WS) (Key Item) "
label var wc02501 "Property, Plant And Equipment - Net (Key Item) "
label var wc02999 "Total Assets (WS) (Key Item) "
label var dwta "Total Assets (Datastream)"
label var dwse "Book Value of Equity (Datastream)"
label var wc03501 "Common Equity (Key Item) "  
    
*INCOME 
label var wc01001 "Net Sales Or Revenues (Key Item)"
label var wc04001 "Net Income before extraordinary items"

*CFS
label var wc04860 "Net Cash Flow - Operating Activities (Key Item) "

*DIVIDENDS, SHARES & MARKET PRICES  
label var wc05101 "Dividends Per Share (WS) (Key Item) "
label var wc05001 "Market Price - Year End "
label var mv "Market Capitalisation (Datastream)"
label var nosh "Number of shares " 
  
*OWNERSHIP 
label var noshff "Free Float Number Of Shares "

*ASSET4 Info
label var cgvscore "Corporate Governance Score (ESG - ASSET4)"  


***Clean dataset to save estimation power: Delete observations where main variables are missing (total assets [numerical] and isin [string var])
drop if wc02999==.
drop if wc06008==""

***Creating variables***
***Creating fiscal year-end information (split the wc05350 - the month/day/year string var)
split wc05350, p(.)
destring wc053501, gen(day)
destring wc053502, gen(month)
destring wc053503, gen(year)
drop wc053501 wc053502 wc053503

***Duplicates
egen i=group(wc06008)
drop if i==.
drop if year==.
drop if year==2010
duplicates report i year
duplicates drop i year, force

***Identifying pooled data structure
tsset i year

***Creating Year-Dummies (one dummy for each year)
tab year, gen(year_)

***Save data
save Master1, replace


*-------------------------------------------------------------------------------
*  (1.2): Read and clean ISS data  
*-------------------------------------------------------------------------------

set more off
insheet using ISScoverage_data.txt, clear

*Labeling key variables
label var countrycgq	"ISS Country CGQ rating" 

***Identifier and country selection
capture drop wc06008
gen wc06008=isinmanuallycompleted
drop if wc06008==""
drop if indexcgq==.
keep if country=="United Kingdom"
sort wc06008 year

***Duplicates
duplicates report wc06008 year
duplicates drop wc06008 year, force

***Save data
capture drop _merge
save Data2, replace


*-------------------------------------------------------------------------------
*  (1.3): Read and clean IBES & stock data 
*-------------------------------------------------------------------------------

set more off
use IBES_data, clear

*Labelling key variables (all variables are averaged across a period of 60 days prior to the respective fiscal year-end)
label var RECNOmedian_m60FY		"Number of issued recommendations per firm " 
label var F1NEmedian_m60FY 		"Number of issued EPS forecasts per firm "
label var MVmedian_m60FY 		"Average fiscal year’s market value of equity "
label var RV_m60FY		 		"Standard deviation of daily share returns "
label var BASmedian_m60FY 		"Bid-ask spreads based on daily closing bid and ask prices "
label var ZTDmean_m60FY 		"Proportion of zero share return days "
label var TOmedian_m60FY	 	"Stock trading volume "

***Identifier
drop if isin==""
sort isin year
gen wc06008=isin

***Duplicates
duplicates report wc06008 year
duplicates drop wc06008 year, force

***Save data
capture drop _merge
save Data3, replace


*-------------------------------------------------------------------------------
*  (1.4): Read and clean TRAA data
*-------------------------------------------------------------------------------

set more off
use TRAA_data, clear

*Labelling key variables
label var IB_InvManNonIndex			"Number of institutional investors per firm scaled by the number of all institutional investors in the market" 
label var OTCountInvMan_nonIndex 	"Number of institutional investors per firm"

***Identifier
drop if isin==""
sort isin year
gen wc06008=isin

***Duplicates
duplicates report wc06008 year
duplicates drop wc06008 year, force

***Save data
capture drop _merge
save Data4, replace


*-------------------------------------------------------------------------------
*  (1.5): Read and clean FTSE/ISS data  
*-------------------------------------------------------------------------------

set more off
import excel ISSFTSE_data.xlsx, clear sheet(Handcollected_Feb2018) first

*Labelling key variables
capture drop FTSEISScoverage
gen FTSEISScoverage=1
label var FTSEISScoverage	"FTSEISS index inclusion dummy" 
label var WtCGI 			"FTSEISS index weights"

***Year 
split Date, p(/)
destring Date1, gen(month)
destring Date2, gen(day)
destring Date3, gen(year)
drop Date1 Date2 Date3

***Sample and identifier 
drop if year==.
drop if isin==""
capture drop wc06008
gen wc06008=isin
sort wc06008 year

***Duplicates
duplicates report wc06008 year
duplicates drop wc06008 year, force

***Save data
capture drop _merge
save Data5, replace


********************************************************************************
********************************************************************************
*  Step 2: Merge datasets  
********************************************************************************
********************************************************************************


set more off
use Master1, clear
sort wc06008 year
 forvalues i = 2(1)5 {
		merge 1:1 wc06008 year using Data`i', force
		drop if _merge==2 
		drop _merge 
}
*
sort i year
***
save Master2, replace
***
use Master2, clear



********************************************************************************
********************************************************************************
*  Step 3: Compute key variables
********************************************************************************
********************************************************************************



*-------------------------------------------------------------------------------
*  (3.1): ISS & ISS/FTSE variables  
*-------------------------------------------------------------------------------

***Treatment 
gen ISScoverage=.
replace ISScoverage=0 if countrycgq==.
replace ISScoverage=1 if ISScoverage==.

***FTSEISS Index Inclusion as Treatment reason  
replace FTSEISScoverage=0 if FTSEISScoverage==.
label var FTSEISScoverage "FTSEISS index inlusion dummy"
replace WtCGI=0 if WtCGI==.
label var WtCGI "FTSEISS index weights"


*-------------------------------------------------------------------------------
*  (3.2): Dependent variables  
*-------------------------------------------------------------------------------

***Financial Analyst Following
sum F1NEmean_CY - RECNOmax_m60FY 

*Key variables  
foreach x of varlist F1NEmean_CY - RECNOmax_m60FY {
	replace `x'=0 if `x'==.
	gen ln`x'=ln(`x'+1)
	winsor `x', generate (`x'win99) p(0.01)
	winsor ln`x', generate (ln`x'win99) p(0.01)
 }
*Sample Identifier (AF_sample) 
pca F1NEmean_CY - RECNOmax_m60FY
predict AF_sample, score


***Stock Liquidity
sum BASmean_CY- MVmedian_m60FY

*Key variables 
foreach x of varlist BASmean_CY- MVmedian_m60FY {
	gen ln`x'=ln(`x'+1)
	winsor `x', generate (`x'win99) p(0.01)
	winsor ln`x', generate (ln`x'win99) p(0.01)
 }
*Sample Identifier (ML_sample)  
pca BASmean_CY- ZTDmean_m60FY  TVmean_CY- MVmedian_m60FY   
predict ML_sample, score


	
***Institutional Ownership (IO measures multiplied by 1000 for the sake of interpretation ease)
sum OwnTypCount_ALL - IB_OthersNonIndex

*Key variables 
foreach x of varlist IB_ALL - IB_OthersNonIndex  {
	replace `x'=0 if `x'==.
	replace `x'=`x'*1000
 }
*
foreach x of varlist OwnTypCount_ALL - IB_OthersNonIndex  {
	*replace `x'=0 if `x'==.
	gen ln`x'=ln(`x'+1)
	winsor `x', generate (`x'win99) p(0.01)
	winsor ln`x', generate (ln`x'win99) p(0.01)
 }
*Sample Identifier (IO_sample)  
pca OwnTypCount_ALL - IB_OthersNonIndex 
predict IO_sample, score
		
		
***Tobin's Q

*Key variables
gen lnQ = ln((dwta+(mv*1000)-dwse) / (dwta))
label var lnQ "Ln of Tobin's Q based on Datastream data"

***
foreach x of varlist lnQ {
	winsor `x', generate (`x'win99) p(0.01)
 }
*Sample Identifier (Q_sample)
pca lnQ lnQwin99  
predict Q_sample, score


*-------------------------------------------------------------------------------
*  (3.3): Control variables  
*-------------------------------------------------------------------------------

*Firm Size in Total Assets
gen lnsize=ln(dwta *1000)
label var lnsize "Ln of total assets (dwta)"

*Market Capitalization
gen lnMaCap1=ln(mv)
label var lnMaCap1 "Ln of market value (mv)"

gen lnMaCap2=ln(nosh*wc05001)
label var lnMaCap2 "Ln of market value (mv)"

*Return on assets
gen ROA=wc04001/wc02999
label var ROA "Net Income before extraordinary items (wc04001) scaled by TA (wc02999)"

* Growth in sales
gen growth=(wc01001-l.wc01001)/l.wc01001
label var growth "Percentage change in sales (wc01001)"

*Leverage
gen lev=wc03251  /wc02999
label var lev"Accounting leverage long-term debt (wc03251) to ta (wc02999)"

*Dividend per Share
gen dps= wc05101
label var dps "dividends per share (wc05101)"

*PPE to TA
gen PPE_TA=wc02501/wc02999
label var PPE_TA "Net PPE (wc02501) to total assets (wc02999)"

*Cash from operations
gen cfo=wc04860/wc02999
label var cfo "Cash flow from operations (direct) deflated by ta"

*Inverse Stock Price
gen inv_stockprice=(-1)*wc05001
label var inv_stockprice "Inverse Stock price based on (wc05001)"

*IFRS Dummy
gen IFRS=.
replace IFRS=1 if wc07536=="IFRS"
replace IFRS=0 if IFRS==.
label var IFRS "IFRS reporting (wc07536)"

*Asset4 Coverage
gen asset4=.
replace asset4=0 if cgvscore == .
replace asset4=1 if asset4 == .
label var asset4 "Asset4 coverage (based on cgvscore)"

*Creating index information (split the wc05661)
gen stockindex=wc05661
split stockindex, p(,)
sort i year
gen FTSE100=.
foreach x of varlist stockindex*  {
		replace FTSE100=1 if `x'=="FTSE 100"
		replace FTSE100=1 if `x'==" FTSE 100"
}
*
replace FTSE100=0 if FTSE100==.
label var FTSE100 "FTSE100 - 100 largest firms at the London Stock Exchange (based on wc05661)"

***
gen FTSE250=.
foreach x of varlist stockindex*  {
		replace FTSE250=1 if `x'=="FT-SE 250"
		replace FTSE250=1 if `x'==" FT-SE 250"
}
*
replace FTSE250=0 if FTSE250==.
label var FTSE250 "FTSE 250 - 250 largest firms at the London Stock Exchange (based on wc05661)"
***
gen FTSEall=.
foreach x of varlist stockindex*  {
		replace FTSEall=1 if `x'=="FTSE ALL"
		replace FTSEall=1 if `x'==" FTSE ALL"
}
*
replace FTSEall=0 if FTSEall==.
label var FTSEall "FTSE ALL - ca. 500 largest firms at the London Stock Exchange (based on wc05661)"
***
drop stockindex*


*SIC industry classification
tostring wc07021, replace
gen nul="0"
gen nul2="00"
gen nul3="000"
egen hulp=concat(nul wc07021) if length(wc07021)==3
replace wc07021=hulp if length(wc07021)==3
drop hulp
egen hulp=concat(nul wc07021) if length(wc07021)==2
replace wc07021=hulp if length(wc07021)==2
drop hulp
egen hulp=concat(nul wc07021) if length(wc07021)==1
replace wc07021=hulp if length(wc07021)==1
drop hulp
drop nul*

*First-digit SIC groups (depends on your sample size)
gen ind1=substr(wc07021,1,1)
label var ind1 "First-digit sic group"
destring ind1, replace
tab ind1, gen(ind1_)


*-------------------------------------------------------------------------------
*  (3.4): Winsorize all control variables  
*-------------------------------------------------------------------------------

set more off
foreach x of varlist lnsize- inv_stockprice noshff {
	gen ln`x'=ln(`x'+1)
	winsor `x', generate (`x'win99) p(0.01)
	winsor ln`x', generate (ln`x'win99) p(0.01)
 }
*Sample Identifier (CONTROL_sample)
pca lnsize lnMaCap1 lnMaCap2 ROA growth lev dps PPE_TA cfo inv_stockprice noshff
predict CONTROL_sample, score

*-------------------------------------------------------------------------------
*  (3.5): Define subsamples w.r.t. individual data availability   
*-------------------------------------------------------------------------------

***Overall Sample
gen sample1 = .
replace sample1=1 if (AF_sample!=. & ML_sample!=. & IO_sample!=. & Q_sample!=.)

gen sample2 = .
replace sample2=1 if (AF_sample!=. & ML_sample!=. & IO_sample!=. & Q_sample!=. & CONTROL_sample!=.)

***

save Master3, replace
***
use Master3, clear


********************************************************************************
********************************************************************************
*  Step 4: Impose balanced sample restrictions & define DiD structure
********************************************************************************
********************************************************************************


*-------------------------------------------------------------------------------
*  (4.1): Define balanced DiD samples for each subsample 
*-------------------------------------------------------------------------------


set more off
	forvalues i = 1(1)2 {
	
		use Master3, replace
		drop if  sample`i' ==. 
		
		***PANEL Structure: 5-YEARS Structure (2003-2007) 
		gen company5y_id=i 
		replace company5y_id=0 if year_1==1
		replace company5y_id=0 if year_2==1
		replace company5y_id=0 if year_8==1
		replace company5y_id=0 if year_9==1
		sort company5y_id 
		by  company5y_id : gen eventcount5y1=_N 
		replace eventcount5y1=0 if company5y_id==0
		***
		gen CompleteSample5y=.
		replace CompleteSample5y=1 if eventcount5y1==5
		replace CompleteSample5y=0 if CompleteSample5y==.

		***CONTROL2: firms with constant ISS ratings
		gen ISS_id=ISScoverage
		sort  ISS_id  company5y_id
		by  ISS_id  company5y_id : gen eventcount5y2=_N 
		replace eventcount5y2=0 if company5y_id==0
		replace eventcount5y2=0 if ISScoverage==0
		***
		gen control5y2=.
		replace control5y2=1 if eventcount5y2==5
		replace control5y2=0 if control5y2==.

		***CONTROL1: firms with constant NON-ISS ratings
		gen nonISS_id=.
		replace nonISS_id=0 if ISScoverage ==1
		replace nonISS_id=1 if nonISS_id==.
		sort  nonISS_id  company5y_id
		by  nonISS_id  company5y_id: gen eventcount5y3=_N 
		replace eventcount5y3=0 if company5y_id==0
		replace eventcount5y3=0 if ISScoverage==1
		replace eventcount5y3=0 if control5y2==1
		***
		gen control5y1=.
		replace control5y1=1 if eventcount5y3==5
		replace control5y1=0 if control5y1==.

		***RESIDUAL: firms with and without ISS ratings (nonsystematic)
		gen ResidualGroup5y=.
		replace ResidualGroup5y=1 if CompleteSample5y==1
		replace ResidualGroup5y=0 if control5y2==1
		replace ResidualGroup5y=0 if control5y1==1
		replace ResidualGroup5y=0 if ResidualGroup5y==.

		***TREATMENT: firms with constant NON-ISS ratings prior to 2005 and constant ISS ratings afterwards
		sort isin
		by isin: egen ISScov0304y=sum(ISScoverage) if (year_3==1 | year_4==1)
		by isin: egen ISScov0507y=sum(ISScoverage) if (year_5==1 | year_6==1| year_7==1)
		replace ISScov0304y=0 if ResidualGroup5y==0
		replace ISScov0507y=0 if ResidualGroup5y==0
		replace ISScov0304y=0 if ISScov0304y==.
		replace ISScov0507y=0 if ISScov0507y==.
		sort isin
		by isin: egen MaxISScov0304y= max(ISScov0304y)
		by isin: egen MaxISScov0507y= max(ISScov0507y)
		***
		gen TreatmentGroup5y=.
		replace TreatmentGroup5y=1 if  MaxISScov0304y==0 & MaxISScov0507y==3  & ResidualGroup5y==1
		replace TreatmentGroup5y=0 if  TreatmentGroup5y==.

		***SUMMARY (control) REPORTS on each individual panel subsample
		tabstat ISScoverage if CompleteSample5y , stat (n sum mean) by(year)
		tabstat CompleteSample5y , stat (n sum mean) by(year)
		tabstat ISScoverage if control5y2 , stat (n sum mean) by(year)
		tabstat control5y2 , stat (n sum mean) by(year)
		tabstat ISScoverage if control5y1 , stat (n sum mean) by(year)
		tabstat control5y1 , stat (n sum mean) by(year)
		tabstat ISScoverage if ResidualGroup5y , stat (n sum mean) by(year)
		tabstat ResidualGroup5y , stat (n sum mean) by(year)
		tabstat ISScoverage if TreatmentGroup5y , stat (n sum mean) by(year)
		tabstat TreatmentGroup5y , stat (n sum mean) by(year)

		***TIME structure
		gen Post= year_5 + year_6 + year_7 
		gen Ante= year_3 + year_4
		gen Post_Treatment=TreatmentGroup5y*Post
		gen Ante_Treatment=TreatmentGroup5y*Ante
		gen Post_control5y1=control5y1*Post
		gen Ante_control5y1=control5y1*Ante
		gen Post_control5y2=control5y2*Post
		gen Ante_control5y2=control5y2*Ante


		***Subsample specific labelling
		rename control5y2 control5y2_s`i'
		rename control5y1 control5y1_s`i'
		rename TreatmentGroup5y TreatmentGroup5y_s`i'
		rename Post_Treatment Post_Treatment5y_s`i'
		rename Post Post5y_s`i'
		rename Ante Ante5y_s`i'

		***Clean and save
		keep wc06008 year control5y2_s`i' control5y1_s`i' TreatmentGroup5y_s`i' Post_Treatment5y_s`i' Post5y_s`i' Ante5y_s`i'
		save EM2data4_s`i', replace
}
*

*-------------------------------------------------------------------------------
*  (4.2): Merge Subsamples and Sample Selection variables with Masterfile 
*-------------------------------------------------------------------------------

set more off
use EM2data4_s1, replace	
sort wc06008 year
	forvalues i = 2(1)2 {
		merge 1:1 wc06008  year using EM2data4_s`i'
		drop if _merge ==2
		drop _merge
		save EM2data4_sALL, replace
}
*
use Master3, replace
sort wc06008 year
set more off
merge 1:1 wc06008 year using EM2data4_sALL
drop if _merge ==2
drop _merge
	
	
*-------------------------------------------------------------------------------
*  (4.3): Adjust Selection Variables for Masterfile
*-------------------------------------------------------------------------------
	
set more off
	forvalues i = 1(1)2 {
		replace  control5y2_s`i'=0 if control5y2_s`i'==.
		replace  control5y1_s`i'=0 if control5y1_s`i'==.
		replace  TreatmentGroup5y_s`i'=0 if TreatmentGroup5y_s`i'==.
		replace  Post_Treatment5y_s`i'=0 if Post_Treatment5y_s`i'==.
		replace  Post5y_s`i'=0 if Post5y_s`i'==.
		replace  Ante5y_s`i'=0 if Ante5y_s`i'==.
		
}
*
capture drop sample1-sample2


*-------------------------------------------------------------------------------
*  (4.4): PCA for COMPLETE sample with Controls (sample2)
*-------------------------------------------------------------------------------

*VARIABLE MANAGEMENT
set more off
macro dir
macro drop CG1 CG2 PERIOD TREATMENT
global CG1 			"control5y1_s2"
global CG2  		"control5y2_s2"
global PERIOD		"year_3|year_4|year_5|year_6|year_7"
global TREATMENT  	"TreatmentGroup5y_s2"

***MARKET LIQUIDITY measures based on PCA
pca lnBASmedian_m60FYwin99  ZTDmean_m60FY lnTOmedian_m60FYwin99   if   ($CG1 | $CG2 | $TREATMENT) & ($PERIOD)
predict help1  if   ($CG1 | $CG2 | $TREATMENT) & ($PERIOD), score
gen MLpc_ALLm60FY_raw = help1  
gen MLpc_ALLm60FY = MLpc_ALLm60FY_raw*(-1)  
drop help1

*** DROP Melrose Resource (MRS, Melrose Resources, GB0009354589) as it is included in FTSEISS Index but NOT in CGQ dataset - I thus correct dataset for data inconsistency in ISS files (Revision Feb 2018, location of drop command does not affect my findings)  
drop if isin=="GB0009354589"

***
save Master4, replace


*-------------------------------------------------------------------------------
*  (4.5): Handcollected governance data based on COMPLETE sample 
*-------------------------------------------------------------------------------

set more off
import excel using GOV_data.xlsx, first  sheet(data_new1) clear

*Define key variables
foreach x of varlist Board1all Board2all  Comp1all Audit1all  {
	gen `x'_d=`x'=="YES"
	replace `x'_d=. if `x'==""
}
gen GOVscore= (Board1all_d+Board2all_d+Comp1all_d+Audit1all_d)/4

*Labelling key variables
label var GOVscore 		"Composite governance index"
label var Board1all_d 	"CEO/chairman duality" 
label var Board2all_d 	"Board Independence " 
label var Comp1all_d 	"Compensation committee independence " 
label var Audit1all_d 	"Audit committee independence " 


*Sample & duplicates
egen count =count(GOVscore), by(isin)
drop if count!=3
gen HandcollectedGOV=1
capture drop wc06008
gen wc06008=isin
duplicates report wc06008 year
sort wc06008 year
keep HandcollectedGOV wc06008 year CGQdata  annualreport Board1all Board2all Comp1all Audit1all BoardSize Board1all_d Board2all_d Comp1all_d Audit1all_d GOVscore  proxyreport

*Save handcolleted data
save Handcollected_ISSGOV6, replace

*Merge handcollected data back to main file 
set more off
use Master4, clear
merge 1:1 wc06008 year using Handcollected_ISSGOV6, force
drop if _merge==2  


*Adjust handcollected dummy variables 0 for Masterfile (do not adjust numerical variables, such as BoardSize and GOVscore)
foreach x of varlist HandcollectedGOV Board1all_d Board2all_d Comp1all_d Audit1all_d  {
	replace `x'=0 if `x'==.
}
*

*Adjust treatment and control dummies (_sample2) in Masterfile for coverage of handcollected data
foreach x of varlist control5y1_s2 control5y2_s2 TreatmentGroup5y_s2 Post5y_s2 Post_Treatment5y_s2  {
	replace `x'=0 if HandcollectedGOV==0
}
*
***

save Master5, replace
***
use Master5, clear

*///////////////////////////////////////////////////////////////////////////////
*///////////////////////////////////////////////////////////////////////////////
*///////////////////////////////////////////////////////////////////////////////
*
*///////////////////////////////////////////////////////////////////////////////
*///////////////////////////////////////////////////////////////////////////////
*///////////////////////////////////////////////////////////////////////////////


*///////////////////////////////////////////////////////////////////////////////
*///////////////////////////////////////////////////////////////////////////////
*///////////////////////////////////////////////////////////////////////////////
*
*		II. RESULTS (as of November 2018)
*
*///////////////////////////////////////////////////////////////////////////////
*///////////////////////////////////////////////////////////////////////////////
*///////////////////////////////////////////////////////////////////////////////


********************************************************************************
********************************************************************************
********************************************************************************
*
*	TABLE 1: Sample Description
*
********************************************************************************
********************************************************************************
********************************************************************************

set more off
use Master3, clear

*Variable Management
macro drop CG1_all CG2_all TREATMENT_all   
global CG1_all 			"control5y1_s2"
global CG2_all  		"control5y2_s2"
global TREATMENT_all  	"TreatmentGroup5y_s2"

*-------------------------------------------------------------------------------
* Panel A (Table 1). Sample Selection
*-------------------------------------------------------------------------------

* (0) Start: Woldscope Firm universe (ISIN available)
tab year if (year_4|year_5|year_6)

* (1) Worldscope Data unavailable
drop if Q_sample ==.
drop if CONTROL_sample ==.
tab year if (year_4|year_5|year_6)

* (2) Datastream Data unavailable
drop if ML_sample ==.
tab year if (year_4|year_5|year_6)

* (3) IBES Data unavailable
drop if  AF_sample ==.
tab year if (year_4|year_5|year_6)

* (4) TRAA Data unavailable
drop if  IO_sample ==.
tab year if (year_4|year_5|year_6)

* (5) Balanced Sample Structure
use Master4, clear
*Variable Management
macro drop CG1_all CG2_all TREATMENT_all   
global CG1_all 			"control5y1_s2"
global CG2_all  		"control5y2_s2"
global TREATMENT_all  	"TreatmentGroup5y_s2"
***
tab year if (year_4|year_5|year_6)& ($TREATMENT_all | $CG1_all |$CG2_all)
tabstat ISScoverage if ($TREATMENT_all | $CG1_all|$CG2_all) & (year_4|year_5|year_6) , stat (n sum mean) 

* (6) Balanced Sample Structure with handcollected GOV data available: GOV
use Master5, clear
*Variable Management
macro drop CG1_all CG2_all TREATMENT_all   
global CG1_all 			"control5y1_s2"
global CG2_all  		"control5y2_s2"
global TREATMENT_all  	"TreatmentGroup5y_s2"
***
tab year if (year_4|year_5|year_6) & ($TREATMENT_all | $CG1_all |$CG2_all)
tabstat ISScoverage if ($TREATMENT_all | $CG1_all|$CG2_all) & (year_4|year_5|year_6) , stat (n sum mean) 


*-------------------------------------------------------------------------------
* Panel B (Table 1). Sample Distribution
*-------------------------------------------------------------------------------

tabstat ISScoverage if ($TREATMENT_all | $CG1_all |$CG2_all) & (year_4|year_5|year_6) , stat (n sum mean) by(year)
tabstat ISScoverage if $TREATMENT_all  & (year_4|year_5|year_6), stat (n sum mean) by(year)
tabstat ISScoverage if $CG1_all & (year_4|year_5|year_6), stat (n sum mean) by(year)
tabstat ISScoverage if $CG2_all & (year_4|year_5|year_6) , stat (n sum mean) by(year)

********************************************************************************
********************************************************************************
********************************************************************************
*
* TABLE 2: Baseline Results: Average Treatment Effect
*
********************************************************************************
********************************************************************************
********************************************************************************

set more off
use Master5, clear

*-------------------------------------------------------------------------------
* Panel A (Table 2): Mean comparisons 
*-------------------------------------------------------------------------------

qui estpost tabstat ISScoverage, stat(n) 
esttab using Platzhalter.rtf, replace cells("count(fmt(0))")  noobs nonumbers  title  (START)
	
foreach x of varlist GOVscore MLpc_ALLm60FY  lnRECNOmedian_m60FY IB_InvManNonIndex  {
	
set more off
use Master5, clear

*VARIABLE MANAGEMENT
set more off
macro dir  
macro drop CG1 CG2 TREATMENT POST DV PREPERIOD POSTPERIOD
global CG1 			"control5y1_s2"
global CG2  		"control5y2_s2"
global TREATMENT  	"TreatmentGroup5y_s2" 
global POST			"Post5y_s2"
global DV 			"`x'" 
global PREPERIOD 	"year_4"
global POSTPERIOD 	"year_5|year_6"

						
*** PANEL A: Main Descriptive Analysis and Univariate DiD

qui estpost tabstat $DV if ($TREATMENT ) & ($PREPERIOD) , stat(mean min max n) 
	esttab using Platzhalter.rtf, append cells("mean(fmt(2))    count(fmt(0))")  noobs nonumbers  title  ((1) TREATMENT & PREPERIOD: `x' ) compress order ($DV) keep ($DV )
qui estpost tabstat $DV if ($TREATMENT ) & ($POSTPERIOD) , stat(mean min max n) 
	esttab using Platzhalter.rtf, append cells("mean(fmt(2))    count(fmt(0))")  noobs nonumbers  title  ((2) TREATMENT & POSTPERIOD: `x') compress order ($DV)  keep ($DV)
qui estpost ttest $DV  if  ($TREATMENT) & ($PREPERIOD|$POSTPERIOD), by($PREPERIOD) 
	esttab using Platzhalter.rtf, append cells("b(fmt(2))  t(fmt(2))  p(fmt(2))  count(fmt(0))")  noobs nonumbers coeflabels(`x') title  ((1) TREATMENT & PREPERIOD vs.POSTPERIOD: `x') compress order ($DV) keep ($DV)
***
qui estpost tabstat $DV if ($CG1|$CG2 ) & ($PREPERIOD) , stat(mean min max n) 
	esttab using Platzhalter.rtf, append cells("mean(fmt(2))     count(fmt(0))")  noobs nonumbers  title  ((3) CG1CG2 & PREPERIOD: `x') compress order ($DV) keep ($DV)
qui estpost tabstat $DV if ($CG1|$CG2 ) & ($POSTPERIOD) , stat(mean min max n) 
	esttab using Platzhalter.rtf, append cells("mean(fmt(2))   count(fmt(0))")  noobs nonumbers  title  ((4) CG1CG2 & POSTPERIOD: `x') compress order ($DV) keep ($DV)
qui estpost ttest $DV  if  ($CG1|$CG2) & ($PREPERIOD|$POSTPERIOD), by($PREPERIOD) 
	esttab using Platzhalter.rtf, append cells("b(fmt(2))  t(fmt(2))  p(fmt(2))  count(fmt(0))")  noobs nonumbers coeflabels(`x') title  ((1) TREATMENT & PREPERIOD vs.POSTPERIOD: `x') compress order ($DV)  keep ($DV)
***
set more off
sort i year
gen var1 = $TREATMENT
gen var2 = ($CG1|$CG2)
***
	forvalues i = 1(1)2 {
		
		gen help1 = $DV if (var`i') & ($PREPERIOD)
		egen meanhelp1=mean(help1) if (var`i') & ($PREPERIOD), by(i)
		egen maxhelp1=max(meanhelp1)  if (var`i'), by(i)

		gen help2 = $DV if (var`i') & ($POSTPERIOD)
		egen meanhelp2=mean(help2) if (var`i') & ($POSTPERIOD), by(i)
		egen maxhelp2=max(meanhelp2)  if (var`i'), by(i)

		gen DV_var`i'diff=maxhelp2-maxhelp1
		drop help1-maxhelp2

}
***
drop var1 - var2
ttest DV_var1diff==0 if  ($PREPERIOD)
ttest DV_var2diff==0 if  ($PREPERIOD)
ttest DV_var1diff == DV_var2diff if  ($PREPERIOD), unpaired
}
*

********************************************************************************
********************************************************************************

set more off
use Master5, clear

*VARIABLE MANAGEMENT:
set more off
macro dir 
macro drop CG1  CG2 TREATMENT POST POST_TREAT DV1 CONTROLVAR1 DV2 CONTROLVAR2 PREPERIOD POSTPERIOD
global CG1 			"control5y1_s2"
global CG2  		"control5y2_s2"
global TREATMENT  	"TreatmentGroup5y_s2" 
global POST			"Post5y_s2"
global POST_TREAT   "Post_Treatment5y_s2"
global DV1 			"GOVscore" 
global CONTROLVAR1 	"lnsizewin99 levwin99 ROAwin99  growthwin99  noshffwin99 BoardSize asset4"
global DV2 			"MLpc_ALLm60FY" 
global CONTROLVAR2 	"lnMVmedian_m60FYwin99 lnRV_m60FYwin99 levwin99 ROAwin99 PPE_TAwin99 inv_stockpricewin99  IFRS noshffwin99 asset4"
global PREPERIOD 	"year_4"
global POSTPERIOD 	"year_5|year_6"

*-------------------------------------------------------------------------------
* Panel B (Table 2): Difference-in-differences regressions: CorpGov & Liquidity
*-------------------------------------------------------------------------------
						
estimates clear
quietly reg $DV1 i.$TREATMENT##i.$POST 	  	if  ($CG1|$CG2|$TREATMENT)  & ($PREPERIOD|$POSTPERIOD), vce(cluster i)
eststo
quietly areg $DV1 i.$TREATMENT##i.$POST   i.year	  	if  ($CG1|$CG2|$TREATMENT)  & ($PREPERIOD|$POSTPERIOD), a(i) cluster(i)
eststo
quietly areg $DV1 i.$TREATMENT##i.$POST  $CONTROLVAR1 i.year	  	if  ($CG1|$CG2|$TREATMENT)  & ($PREPERIOD|$POSTPERIOD), a(i) cluster(i)
eststo
quietly reg $DV2 i.$TREATMENT##i.$POST 	  	if  ($CG1|$CG2|$TREATMENT)  & ($PREPERIOD|$POSTPERIOD), vce(cluster i)
eststo
quietly areg $DV2 i.$TREATMENT##i.$POST   i.year	  	if  ($CG1|$CG2|$TREATMENT)  & ($PREPERIOD|$POSTPERIOD), a(i) cluster(i)
eststo
quietly areg $DV2 i.$TREATMENT##i.$POST  $CONTROLVAR2 i.year	  	if  ($CG1|$CG2|$TREATMENT)  & ($PREPERIOD|$POSTPERIOD), a(i) cluster(i)
eststo
esttab,  	star(* 0.10 ** 0.05 *** 0.01) b(3) stats(F N r2_a p_diff)   title (Panel B (Table 2): Difference-in-differences regressions: CorpGov & Liquidity) ///
				nonumbers mtitles("Model 1" "Model 2" "Model 3" "Model 4" "Model 5" "Model 6"   ) compress ///
				keep (1.$POST  1.$TREATMENT  1.$TREATMENT#1.$POST  $CONTROLVAR1 $CONTROLVAR2) ///
				order (1.$POST  1.$TREATMENT  1.$TREATMENT#1.$POST  $CONTROLVAR1 $CONTROLVAR2)
esttab using Platzhalter.rtf, replace ///
				star(* 0.10 ** 0.05 *** 0.01) b(3) stats(F N r2_a p_diff)  label title (Panel B (Table 2): Difference-in-differences regressions: CorpGov & Liquidity) ///
				nonumbers mtitles ("Model 1" "Model 2" "Model 3" "Model 4" "Model 5" "Model 6" ) compress varwidth(12)  modelwidth(6) ///
				keep (1.$POST  1.$TREATMENT  1.$TREATMENT#1.$POST  $CONTROLVAR1 $CONTROLVAR2) ///
				order (1.$POST  1.$TREATMENT  1.$TREATMENT#1.$POST  $CONTROLVAR1 $CONTROLVAR2)
estimates clear


********************************************************************************
********************************************************************************

set more off
use Master5, clear

*VARIABLE MANAGEMENT:
set more off
macro dir 
macro drop CG1  CG2 TREATMENT POST POST_TREAT DV1 CONTROLVAR1 DV2 CONTROLVAR2 PREPERIOD POSTPERIOD
global CG1 			"control5y1_s2"
global CG2  		"control5y2_s2"
global TREATMENT  	"TreatmentGroup5y_s2" 
global POST			"Post5y_s2"
global POST_TREAT   "Post_Treatment5y_s2"
global DV1 			"lnRECNOmedian_m60FY" 
global CONTROLVAR1 	"lnsizewin99 levwin99 ROAwin99 PPE_TAwin99 noshffwin99 IFRS inv_stockpricewin99 asset4"
global DV2 			"IB_InvManNonIndex" 
global CONTROLVAR2 	"lnsizewin99 levwin99 ROAwin99  cfowin99 dpswin99 PPE_TAwin99 IFRS inv_stockpricewin99 asset4 "
global PREPERIOD 	"year_4"
global POSTPERIOD 	"year_5|year_6"

*-------------------------------------------------------------------------------
* Panel C (Table 2): Difference-in-differences regressions: Ln(AF) & InvBreadth
*-------------------------------------------------------------------------------
						
estimates clear
quietly reg $DV1 i.$TREATMENT##i.$POST 	  	if  ($CG1|$CG2|$TREATMENT)  & ($PREPERIOD|$POSTPERIOD), vce(cluster i)
eststo
quietly areg $DV1 i.$TREATMENT##i.$POST   i.year	  	if  ($CG1|$CG2|$TREATMENT)  & ($PREPERIOD|$POSTPERIOD), a(i) cluster(i)
eststo
quietly areg $DV1 i.$TREATMENT##i.$POST  $CONTROLVAR1 i.year	  	if  ($CG1|$CG2|$TREATMENT)  & ($PREPERIOD|$POSTPERIOD), a(i) cluster(i)
eststo
quietly reg $DV2 i.$TREATMENT##i.$POST 	  	if  ($CG1|$CG2|$TREATMENT)  & ($PREPERIOD|$POSTPERIOD), vce(cluster i)
eststo
quietly areg $DV2 i.$TREATMENT##i.$POST   i.year	  	if  ($CG1|$CG2|$TREATMENT)  & ($PREPERIOD|$POSTPERIOD), a(i) cluster(i)
eststo
quietly areg $DV2 i.$TREATMENT##i.$POST  $CONTROLVAR2 i.year	  	if  ($CG1|$CG2|$TREATMENT)  & ($PREPERIOD|$POSTPERIOD), a(i) cluster(i)
eststo
esttab,  	star(* 0.10 ** 0.05 *** 0.01) b(3) stats(F N r2_a p_diff)   title (Panel C (Table 2): Difference-in-differences regressions: Ln(AF) & InvBreadth) ///
				nonumbers mtitles("Model 1" "Model 2" "Model 3" "Model 4" "Model 5" "Model 6"   ) compress ///
				keep (1.$POST  1.$TREATMENT  1.$TREATMENT#1.$POST  $CONTROLVAR1 $CONTROLVAR2) ///
				order (1.$POST  1.$TREATMENT  1.$TREATMENT#1.$POST  $CONTROLVAR1 $CONTROLVAR2)
esttab using Platzhalter.rtf, replace ///
				star(* 0.10 ** 0.05 *** 0.01) b(3) stats(F N r2_a p_diff)  label title (Panel C (Table 2): Difference-in-differences regressions: Ln(AF) & InvBreadth) ///
				nonumbers mtitles ("Model 1" "Model 2" "Model 3" "Model 4" "Model 5" "Model 6" ) compress varwidth(12)  modelwidth(6) ///
				keep (1.$POST  1.$TREATMENT  1.$TREATMENT#1.$POST  $CONTROLVAR1 $CONTROLVAR2) ///
				order (1.$POST  1.$TREATMENT  1.$TREATMENT#1.$POST  $CONTROLVAR1 $CONTROLVAR2)
estimates clear



*///////////////////////////////////////////////////////////////////////////////
*///////////////////////////////////////////////////////////////////////////////
*///////////////////////////////////////////////////////////////////////////////

*///////////////////////////////////////////////////////////////////////////////
*///////////////////////////////////////////////////////////////////////////////
*///////////////////////////////////////////////////////////////////////////////
*
*		THE END
*
*///////////////////////////////////////////////////////////////////////////////
*///////////////////////////////////////////////////////////////////////////////
*///////////////////////////////////////////////////////////////////////////////

*///////////////////////////////////////////////////////////////////////////////
*///////////////////////////////////////////////////////////////////////////////
*///////////////////////////////////////////////////////////////////////////////

****************************************************************************************************************************************************************
****************************************************************************************************************************************************************
****************************************************************************************************************************************************************
*
*	Do corporate governance analysts matter? Evidence from the expansion of governance analyst coverage (2018)
*
*	Nico Lehmann (Georg-August University of Goettingen, nico.lehmann@wiwi.uni-goettingen.de)
*
*	The Stata do-file uses all nine datasets (see "NL_data description") as inputs and provides a detailed step-by-step description that enables other researchers to arrive at the same dataset used in my study. 
*	In addition, it shows the Stata code for the main empirical analysis presented in Table 2 of the paper.
*	The analysis is based on three different data source types:
*		(1) commercially available data (i.e., Datastream, Worldscope, IBES, TRAA),
*		(2) proprietary data (ISS coverage data, FTSE/ISS index membership data),
*		(3) publically available data (handcolleted governance data from annual reports). 
*	Please read the data description ("NL_data description") accompanying this do-file beforehand for more details on the different data sources. 
*
****************************************************************************************************************************************************************
****************************************************************************************************************************************************************
****************************************************************************************************************************************************************


*///////////////////////////////////////////////////////////////////////////////
*///////////////////////////////////////////////////////////////////////////////
*///////////////////////////////////////////////////////////////////////////////
*
*  I. Data preparation
* 
*///////////////////////////////////////////////////////////////////////////////
*///////////////////////////////////////////////////////////////////////////////
*///////////////////////////////////////////////////////////////////////////////


********************************************************************************
********************************************************************************
*  Step 1: Read and clean datasets
********************************************************************************
********************************************************************************


*-------------------------------------------------------------------------------
*  (1.1): Read and clean Datastream, Worldscope, Asset4 raw data  
*-------------------------------------------------------------------------------

set more off
use TR_data, clear // Thomson Reuters dataset contains UK panel data for the years between 2001 and 2009

***Labelling variables

*COMPANY INFO 
label var wc05350 "Date Of Fiscal Year End (Key Item)"
label var wc06001 "Company Name (Key Item)"
label var wc06008 "Isin Number "
label var wc07536 "Accounting Standards Followed"
label var wc07021 "Sic Code 1 "
label var wc05661 "Stock Index Information "

*BALANCE 
label var wc03251 "Long Term Debt (WS) (Key Item) "
label var wc02501 "Property, Plant And Equipment - Net (Key Item) "
label var wc02999 "Total Assets (WS) (Key Item) "
label var dwta "Total Assets (Datastream)"
label var dwse "Book Value of Equity (Datastream)"
label var wc03501 "Common Equity (Key Item) "  
    
*INCOME 
label var wc01001 "Net Sales Or Revenues (Key Item)"
label var wc04001 "Net Income before extraordinary items"

*CFS
label var wc04860 "Net Cash Flow - Operating Activities (Key Item) "

*DIVIDENDS, SHARES & MARKET PRICES  
label var wc05101 "Dividends Per Share (WS) (Key Item) "
label var wc05001 "Market Price - Year End "
label var mv "Market Capitalisation (Datastream)"
label var nosh "Number of shares " 
  
*OWNERSHIP 
label var noshff "Free Float Number Of Shares "

*ASSET4 Info
label var cgvscore "Corporate Governance Score (ESG - ASSET4)"  


***Clean dataset to save estimation power: Delete observations where main variables are missing (total assets [numerical] and isin [string var])
drop if wc02999==.
drop if wc06008==""

***Creating variables***
***Creating fiscal year-end information (split the wc05350 - the month/day/year string var)
split wc05350, p(.)
destring wc053501, gen(day)
destring wc053502, gen(month)
destring wc053503, gen(year)
drop wc053501 wc053502 wc053503

***Duplicates
egen i=group(wc06008)
drop if i==.
drop if year==.
drop if year==2010
duplicates report i year
duplicates drop i year, force

***Identifying pooled data structure
tsset i year

***Creating Year-Dummies (one dummy for each year)
tab year, gen(year_)

***Save data
save Master1, replace


*-------------------------------------------------------------------------------
*  (1.2): Read and clean ISS data  
*-------------------------------------------------------------------------------

set more off
insheet using ISScoverage_data.txt, clear

*Labeling key variables
label var countrycgq	"ISS Country CGQ rating" 

***Identifier and country selection
capture drop wc06008
gen wc06008=isinmanuallycompleted
drop if wc06008==""
drop if indexcgq==.
keep if country=="United Kingdom"
sort wc06008 year

***Duplicates
duplicates report wc06008 year
duplicates drop wc06008 year, force

***Save data
capture drop _merge
save Data2, replace


*-------------------------------------------------------------------------------
*  (1.3): Read and clean IBES & stock data 
*-------------------------------------------------------------------------------

set more off
use IBES_data, clear

*Labelling key variables (all variables are averaged across a period of 60 days prior to the respective fiscal year-end)
label var RECNOmedian_m60FY		"Number of issued recommendations per firm " 
label var F1NEmedian_m60FY 		"Number of issued EPS forecasts per firm "
label var MVmedian_m60FY 		"Average fiscal year’s market value of equity "
label var RV_m60FY		 		"Standard deviation of daily share returns "
label var BASmedian_m60FY 		"Bid-ask spreads based on daily closing bid and ask prices "
label var ZTDmean_m60FY 		"Proportion of zero share return days "
label var TOmedian_m60FY	 	"Stock trading volume "

***Identifier
drop if isin==""
sort isin year
gen wc06008=isin

***Duplicates
duplicates report wc06008 year
duplicates drop wc06008 year, force

***Save data
capture drop _merge
save Data3, replace


*-------------------------------------------------------------------------------
*  (1.4): Read and clean TRAA data
*-------------------------------------------------------------------------------

set more off
use TRAA_data, clear

*Labelling key variables
label var IB_InvManNonIndex			"Number of institutional investors per firm scaled by the number of all institutional investors in the market" 
label var OTCountInvMan_nonIndex 	"Number of institutional investors per firm"

***Identifier
drop if isin==""
sort isin year
gen wc06008=isin

***Duplicates
duplicates report wc06008 year
duplicates drop wc06008 year, force

***Save data
capture drop _merge
save Data4, replace


*-------------------------------------------------------------------------------
*  (1.5): Read and clean FTSE/ISS data  
*-------------------------------------------------------------------------------

set more off
import excel ISSFTSE_data.xlsx, clear sheet(Handcollected_Feb2018) first

*Labelling key variables
capture drop FTSEISScoverage
gen FTSEISScoverage=1
label var FTSEISScoverage	"FTSEISS index inclusion dummy" 
label var WtCGI 			"FTSEISS index weights"

***Year 
split Date, p(/)
destring Date1, gen(month)
destring Date2, gen(day)
destring Date3, gen(year)
drop Date1 Date2 Date3

***Sample and identifier 
drop if year==.
drop if isin==""
capture drop wc06008
gen wc06008=isin
sort wc06008 year

***Duplicates
duplicates report wc06008 year
duplicates drop wc06008 year, force

***Save data
capture drop _merge
save Data5, replace


********************************************************************************
********************************************************************************
*  Step 2: Merge datasets  
********************************************************************************
********************************************************************************


set more off
use Master1, clear
sort wc06008 year
 forvalues i = 2(1)5 {
		merge 1:1 wc06008 year using Data`i', force
		drop if _merge==2 
		drop _merge 
}
*
sort i year
***
save Master2, replace
***
use Master2, clear



********************************************************************************
********************************************************************************
*  Step 3: Compute key variables
********************************************************************************
********************************************************************************



*-------------------------------------------------------------------------------
*  (3.1): ISS & ISS/FTSE variables  
*-------------------------------------------------------------------------------

***Treatment 
gen ISScoverage=.
replace ISScoverage=0 if countrycgq==.
replace ISScoverage=1 if ISScoverage==.

***FTSEISS Index Inclusion as Treatment reason  
replace FTSEISScoverage=0 if FTSEISScoverage==.
label var FTSEISScoverage "FTSEISS index inlusion dummy"
replace WtCGI=0 if WtCGI==.
label var WtCGI "FTSEISS index weights"


*-------------------------------------------------------------------------------
*  (3.2): Dependent variables  
*-------------------------------------------------------------------------------

***Financial Analyst Following
sum F1NEmean_CY - RECNOmax_m60FY 

*Key variables  
foreach x of varlist F1NEmean_CY - RECNOmax_m60FY {
	replace `x'=0 if `x'==.
	gen ln`x'=ln(`x'+1)
	winsor `x', generate (`x'win99) p(0.01)
	winsor ln`x', generate (ln`x'win99) p(0.01)
 }
*Sample Identifier (AF_sample) 
pca F1NEmean_CY - RECNOmax_m60FY
predict AF_sample, score


***Stock Liquidity
sum BASmean_CY- MVmedian_m60FY

*Key variables 
foreach x of varlist BASmean_CY- MVmedian_m60FY {
	gen ln`x'=ln(`x'+1)
	winsor `x', generate (`x'win99) p(0.01)
	winsor ln`x', generate (ln`x'win99) p(0.01)
 }
*Sample Identifier (ML_sample)  
pca BASmean_CY- ZTDmean_m60FY  TVmean_CY- MVmedian_m60FY   
predict ML_sample, score


	
***Institutional Ownership (IO measures multiplied by 1000 for the sake of interpretation ease)
sum OwnTypCount_ALL - IB_OthersNonIndex

*Key variables 
foreach x of varlist IB_ALL - IB_OthersNonIndex  {
	replace `x'=0 if `x'==.
	replace `x'=`x'*1000
 }
*
foreach x of varlist OwnTypCount_ALL - IB_OthersNonIndex  {
	*replace `x'=0 if `x'==.
	gen ln`x'=ln(`x'+1)
	winsor `x', generate (`x'win99) p(0.01)
	winsor ln`x', generate (ln`x'win99) p(0.01)
 }
*Sample Identifier (IO_sample)  
pca OwnTypCount_ALL - IB_OthersNonIndex 
predict IO_sample, score
		
		
***Tobin's Q

*Key variables
gen lnQ = ln((dwta+(mv*1000)-dwse) / (dwta))
label var lnQ "Ln of Tobin's Q based on Datastream data"

***
foreach x of varlist lnQ {
	winsor `x', generate (`x'win99) p(0.01)
 }
*Sample Identifier (Q_sample)
pca lnQ lnQwin99  
predict Q_sample, score


*-------------------------------------------------------------------------------
*  (3.3): Control variables  
*-------------------------------------------------------------------------------

*Firm Size in Total Assets
gen lnsize=ln(dwta *1000)
label var lnsize "Ln of total assets (dwta)"

*Market Capitalization
gen lnMaCap1=ln(mv)
label var lnMaCap1 "Ln of market value (mv)"

gen lnMaCap2=ln(nosh*wc05001)
label var lnMaCap2 "Ln of market value (mv)"

*Return on assets
gen ROA=wc04001/wc02999
label var ROA "Net Income before extraordinary items (wc04001) scaled by TA (wc02999)"

* Growth in sales
gen growth=(wc01001-l.wc01001)/l.wc01001
label var growth "Percentage change in sales (wc01001)"

*Leverage
gen lev=wc03251  /wc02999
label var lev"Accounting leverage long-term debt (wc03251) to ta (wc02999)"

*Dividend per Share
gen dps= wc05101
label var dps "dividends per share (wc05101)"

*PPE to TA
gen PPE_TA=wc02501/wc02999
label var PPE_TA "Net PPE (wc02501) to total assets (wc02999)"

*Cash from operations
gen cfo=wc04860/wc02999
label var cfo "Cash flow from operations (direct) deflated by ta"

*Inverse Stock Price
gen inv_stockprice=(-1)*wc05001
label var inv_stockprice "Inverse Stock price based on (wc05001)"

*IFRS Dummy
gen IFRS=.
replace IFRS=1 if wc07536=="IFRS"
replace IFRS=0 if IFRS==.
label var IFRS "IFRS reporting (wc07536)"

*Asset4 Coverage
gen asset4=.
replace asset4=0 if cgvscore == .
replace asset4=1 if asset4 == .
label var asset4 "Asset4 coverage (based on cgvscore)"

*Creating index information (split the wc05661)
gen stockindex=wc05661
split stockindex, p(,)
sort i year
gen FTSE100=.
foreach x of varlist stockindex*  {
		replace FTSE100=1 if `x'=="FTSE 100"
		replace FTSE100=1 if `x'==" FTSE 100"
}
*
replace FTSE100=0 if FTSE100==.
label var FTSE100 "FTSE100 - 100 largest firms at the London Stock Exchange (based on wc05661)"

***
gen FTSE250=.
foreach x of varlist stockindex*  {
		replace FTSE250=1 if `x'=="FT-SE 250"
		replace FTSE250=1 if `x'==" FT-SE 250"
}
*
replace FTSE250=0 if FTSE250==.
label var FTSE250 "FTSE 250 - 250 largest firms at the London Stock Exchange (based on wc05661)"
***
gen FTSEall=.
foreach x of varlist stockindex*  {
		replace FTSEall=1 if `x'=="FTSE ALL"
		replace FTSEall=1 if `x'==" FTSE ALL"
}
*
replace FTSEall=0 if FTSEall==.
label var FTSEall "FTSE ALL - ca. 500 largest firms at the London Stock Exchange (based on wc05661)"
***
drop stockindex*


*SIC industry classification
tostring wc07021, replace
gen nul="0"
gen nul2="00"
gen nul3="000"
egen hulp=concat(nul wc07021) if length(wc07021)==3
replace wc07021=hulp if length(wc07021)==3
drop hulp
egen hulp=concat(nul wc07021) if length(wc07021)==2
replace wc07021=hulp if length(wc07021)==2
drop hulp
egen hulp=concat(nul wc07021) if length(wc07021)==1
replace wc07021=hulp if length(wc07021)==1
drop hulp
drop nul*

*First-digit SIC groups (depends on your sample size)
gen ind1=substr(wc07021,1,1)
label var ind1 "First-digit sic group"
destring ind1, replace
tab ind1, gen(ind1_)


*-------------------------------------------------------------------------------
*  (3.4): Winsorize all control variables  
*-------------------------------------------------------------------------------

set more off
foreach x of varlist lnsize- inv_stockprice noshff {
	gen ln`x'=ln(`x'+1)
	winsor `x', generate (`x'win99) p(0.01)
	winsor ln`x', generate (ln`x'win99) p(0.01)
 }
*Sample Identifier (CONTROL_sample)
pca lnsize lnMaCap1 lnMaCap2 ROA growth lev dps PPE_TA cfo inv_stockprice noshff
predict CONTROL_sample, score

*-------------------------------------------------------------------------------
*  (3.5): Define subsamples w.r.t. individual data availability   
*-------------------------------------------------------------------------------

***Overall Sample
gen sample1 = .
replace sample1=1 if (AF_sample!=. & ML_sample!=. & IO_sample!=. & Q_sample!=.)

gen sample2 = .
replace sample2=1 if (AF_sample!=. & ML_sample!=. & IO_sample!=. & Q_sample!=. & CONTROL_sample!=.)

***

save Master3, replace
***
use Master3, clear


********************************************************************************
********************************************************************************
*  Step 4: Impose balanced sample restrictions & define DiD structure
********************************************************************************
********************************************************************************


*-------------------------------------------------------------------------------
*  (4.1): Define balanced DiD samples for each subsample 
*-------------------------------------------------------------------------------


set more off
	forvalues i = 1(1)2 {
	
		use Master3, replace
		drop if  sample`i' ==. 
		
		***PANEL Structure: 5-YEARS Structure (2003-2007) 
		gen company5y_id=i 
		replace company5y_id=0 if year_1==1
		replace company5y_id=0 if year_2==1
		replace company5y_id=0 if year_8==1
		replace company5y_id=0 if year_9==1
		sort company5y_id 
		by  company5y_id : gen eventcount5y1=_N 
		replace eventcount5y1=0 if company5y_id==0
		***
		gen CompleteSample5y=.
		replace CompleteSample5y=1 if eventcount5y1==5
		replace CompleteSample5y=0 if CompleteSample5y==.

		***CONTROL2: firms with constant ISS ratings
		gen ISS_id=ISScoverage
		sort  ISS_id  company5y_id
		by  ISS_id  company5y_id : gen eventcount5y2=_N 
		replace eventcount5y2=0 if company5y_id==0
		replace eventcount5y2=0 if ISScoverage==0
		***
		gen control5y2=.
		replace control5y2=1 if eventcount5y2==5
		replace control5y2=0 if control5y2==.

		***CONTROL1: firms with constant NON-ISS ratings
		gen nonISS_id=.
		replace nonISS_id=0 if ISScoverage ==1
		replace nonISS_id=1 if nonISS_id==.
		sort  nonISS_id  company5y_id
		by  nonISS_id  company5y_id: gen eventcount5y3=_N 
		replace eventcount5y3=0 if company5y_id==0
		replace eventcount5y3=0 if ISScoverage==1
		replace eventcount5y3=0 if control5y2==1
		***
		gen control5y1=.
		replace control5y1=1 if eventcount5y3==5
		replace control5y1=0 if control5y1==.

		***RESIDUAL: firms with and without ISS ratings (nonsystematic)
		gen ResidualGroup5y=.
		replace ResidualGroup5y=1 if CompleteSample5y==1
		replace ResidualGroup5y=0 if control5y2==1
		replace ResidualGroup5y=0 if control5y1==1
		replace ResidualGroup5y=0 if ResidualGroup5y==.

		***TREATMENT: firms with constant NON-ISS ratings prior to 2005 and constant ISS ratings afterwards
		sort isin
		by isin: egen ISScov0304y=sum(ISScoverage) if (year_3==1 | year_4==1)
		by isin: egen ISScov0507y=sum(ISScoverage) if (year_5==1 | year_6==1| year_7==1)
		replace ISScov0304y=0 if ResidualGroup5y==0
		replace ISScov0507y=0 if ResidualGroup5y==0
		replace ISScov0304y=0 if ISScov0304y==.
		replace ISScov0507y=0 if ISScov0507y==.
		sort isin
		by isin: egen MaxISScov0304y= max(ISScov0304y)
		by isin: egen MaxISScov0507y= max(ISScov0507y)
		***
		gen TreatmentGroup5y=.
		replace TreatmentGroup5y=1 if  MaxISScov0304y==0 & MaxISScov0507y==3  & ResidualGroup5y==1
		replace TreatmentGroup5y=0 if  TreatmentGroup5y==.

		***SUMMARY (control) REPORTS on each individual panel subsample
		tabstat ISScoverage if CompleteSample5y , stat (n sum mean) by(year)
		tabstat CompleteSample5y , stat (n sum mean) by(year)
		tabstat ISScoverage if control5y2 , stat (n sum mean) by(year)
		tabstat control5y2 , stat (n sum mean) by(year)
		tabstat ISScoverage if control5y1 , stat (n sum mean) by(year)
		tabstat control5y1 , stat (n sum mean) by(year)
		tabstat ISScoverage if ResidualGroup5y , stat (n sum mean) by(year)
		tabstat ResidualGroup5y , stat (n sum mean) by(year)
		tabstat ISScoverage if TreatmentGroup5y , stat (n sum mean) by(year)
		tabstat TreatmentGroup5y , stat (n sum mean) by(year)

		***TIME structure
		gen Post= year_5 + year_6 + year_7 
		gen Ante= year_3 + year_4
		gen Post_Treatment=TreatmentGroup5y*Post
		gen Ante_Treatment=TreatmentGroup5y*Ante
		gen Post_control5y1=control5y1*Post
		gen Ante_control5y1=control5y1*Ante
		gen Post_control5y2=control5y2*Post
		gen Ante_control5y2=control5y2*Ante


		***Subsample specific labelling
		rename control5y2 control5y2_s`i'
		rename control5y1 control5y1_s`i'
		rename TreatmentGroup5y TreatmentGroup5y_s`i'
		rename Post_Treatment Post_Treatment5y_s`i'
		rename Post Post5y_s`i'
		rename Ante Ante5y_s`i'

		***Clean and save
		keep wc06008 year control5y2_s`i' control5y1_s`i' TreatmentGroup5y_s`i' Post_Treatment5y_s`i' Post5y_s`i' Ante5y_s`i'
		save EM2data4_s`i', replace
}
*

*-------------------------------------------------------------------------------
*  (4.2): Merge Subsamples and Sample Selection variables with Masterfile 
*-------------------------------------------------------------------------------

set more off
use EM2data4_s1, replace	
sort wc06008 year
	forvalues i = 2(1)2 {
		merge 1:1 wc06008  year using EM2data4_s`i'
		drop if _merge ==2
		drop _merge
		save EM2data4_sALL, replace
}
*
use Master3, replace
sort wc06008 year
set more off
merge 1:1 wc06008 year using EM2data4_sALL
drop if _merge ==2
drop _merge
	
	
*-------------------------------------------------------------------------------
*  (4.3): Adjust Selection Variables for Masterfile
*-------------------------------------------------------------------------------
	
set more off
	forvalues i = 1(1)2 {
		replace  control5y2_s`i'=0 if control5y2_s`i'==.
		replace  control5y1_s`i'=0 if control5y1_s`i'==.
		replace  TreatmentGroup5y_s`i'=0 if TreatmentGroup5y_s`i'==.
		replace  Post_Treatment5y_s`i'=0 if Post_Treatment5y_s`i'==.
		replace  Post5y_s`i'=0 if Post5y_s`i'==.
		replace  Ante5y_s`i'=0 if Ante5y_s`i'==.
		
}
*
capture drop sample1-sample2


*-------------------------------------------------------------------------------
*  (4.4): PCA for COMPLETE sample with Controls (sample2)
*-------------------------------------------------------------------------------

*VARIABLE MANAGEMENT
set more off
macro dir
macro drop CG1 CG2 PERIOD TREATMENT
global CG1 			"control5y1_s2"
global CG2  		"control5y2_s2"
global PERIOD		"year_3|year_4|year_5|year_6|year_7"
global TREATMENT  	"TreatmentGroup5y_s2"

***MARKET LIQUIDITY measures based on PCA
pca lnBASmedian_m60FYwin99  ZTDmean_m60FY lnTOmedian_m60FYwin99   if   ($CG1 | $CG2 | $TREATMENT) & ($PERIOD)
predict help1  if   ($CG1 | $CG2 | $TREATMENT) & ($PERIOD), score
gen MLpc_ALLm60FY_raw = help1  
gen MLpc_ALLm60FY = MLpc_ALLm60FY_raw*(-1)  
drop help1

*** DROP Melrose Resource (MRS, Melrose Resources, GB0009354589) as it is included in FTSEISS Index but NOT in CGQ dataset - I thus correct dataset for data inconsistency in ISS files (Revision Feb 2018, location of drop command does not affect my findings)  
drop if isin=="GB0009354589"

***
save Master4, replace


*-------------------------------------------------------------------------------
*  (4.5): Handcollected governance data based on COMPLETE sample 
*-------------------------------------------------------------------------------

set more off
import excel using GOV_data.xlsx, first  sheet(data_new1) clear

*Define key variables
foreach x of varlist Board1all Board2all  Comp1all Audit1all  {
	gen `x'_d=`x'=="YES"
	replace `x'_d=. if `x'==""
}
gen GOVscore= (Board1all_d+Board2all_d+Comp1all_d+Audit1all_d)/4

*Labelling key variables
label var GOVscore 		"Composite governance index"
label var Board1all_d 	"CEO/chairman duality" 
label var Board2all_d 	"Board Independence " 
label var Comp1all_d 	"Compensation committee independence " 
label var Audit1all_d 	"Audit committee independence " 


*Sample & duplicates
egen count =count(GOVscore), by(isin)
drop if count!=3
gen HandcollectedGOV=1
capture drop wc06008
gen wc06008=isin
duplicates report wc06008 year
sort wc06008 year
keep HandcollectedGOV wc06008 year CGQdata  annualreport Board1all Board2all Comp1all Audit1all BoardSize Board1all_d Board2all_d Comp1all_d Audit1all_d GOVscore  proxyreport

*Save handcolleted data
save Handcollected_ISSGOV6, replace

*Merge handcollected data back to main file 
set more off
use Master4, clear
merge 1:1 wc06008 year using Handcollected_ISSGOV6, force
drop if _merge==2  


*Adjust handcollected dummy variables 0 for Masterfile (do not adjust numerical variables, such as BoardSize and GOVscore)
foreach x of varlist HandcollectedGOV Board1all_d Board2all_d Comp1all_d Audit1all_d  {
	replace `x'=0 if `x'==.
}
*

*Adjust treatment and control dummies (_sample2) in Masterfile for coverage of handcollected data
foreach x of varlist control5y1_s2 control5y2_s2 TreatmentGroup5y_s2 Post5y_s2 Post_Treatment5y_s2  {
	replace `x'=0 if HandcollectedGOV==0
}
*
***

save Master5, replace
***
use Master5, clear

*///////////////////////////////////////////////////////////////////////////////
*///////////////////////////////////////////////////////////////////////////////
*///////////////////////////////////////////////////////////////////////////////
*
*///////////////////////////////////////////////////////////////////////////////
*///////////////////////////////////////////////////////////////////////////////
*///////////////////////////////////////////////////////////////////////////////


*///////////////////////////////////////////////////////////////////////////////
*///////////////////////////////////////////////////////////////////////////////
*///////////////////////////////////////////////////////////////////////////////
*
*		II. RESULTS (as of November 2018)
*
*///////////////////////////////////////////////////////////////////////////////
*///////////////////////////////////////////////////////////////////////////////
*///////////////////////////////////////////////////////////////////////////////


********************************************************************************
********************************************************************************
********************************************************************************
*
*	TABLE 1: Sample Description
*
********************************************************************************
********************************************************************************
********************************************************************************

set more off
use Master3, clear

*Variable Management
macro drop CG1_all CG2_all TREATMENT_all   
global CG1_all 			"control5y1_s2"
global CG2_all  		"control5y2_s2"
global TREATMENT_all  	"TreatmentGroup5y_s2"

*-------------------------------------------------------------------------------
* Panel A (Table 1). Sample Selection
*-------------------------------------------------------------------------------

* (0) Start: Woldscope Firm universe (ISIN available)
tab year if (year_4|year_5|year_6)

* (1) Worldscope Data unavailable
drop if Q_sample ==.
drop if CONTROL_sample ==.
tab year if (year_4|year_5|year_6)

* (2) Datastream Data unavailable
drop if ML_sample ==.
tab year if (year_4|year_5|year_6)

* (3) IBES Data unavailable
drop if  AF_sample ==.
tab year if (year_4|year_5|year_6)

* (4) TRAA Data unavailable
drop if  IO_sample ==.
tab year if (year_4|year_5|year_6)

* (5) Balanced Sample Structure
use Master4, clear
*Variable Management
macro drop CG1_all CG2_all TREATMENT_all   
global CG1_all 			"control5y1_s2"
global CG2_all  		"control5y2_s2"
global TREATMENT_all  	"TreatmentGroup5y_s2"
***
tab year if (year_4|year_5|year_6)& ($TREATMENT_all | $CG1_all |$CG2_all)
tabstat ISScoverage if ($TREATMENT_all | $CG1_all|$CG2_all) & (year_4|year_5|year_6) , stat (n sum mean) 

* (6) Balanced Sample Structure with handcollected GOV data available: GOV
use Master5, clear
*Variable Management
macro drop CG1_all CG2_all TREATMENT_all   
global CG1_all 			"control5y1_s2"
global CG2_all  		"control5y2_s2"
global TREATMENT_all  	"TreatmentGroup5y_s2"
***
tab year if (year_4|year_5|year_6) & ($TREATMENT_all | $CG1_all |$CG2_all)
tabstat ISScoverage if ($TREATMENT_all | $CG1_all|$CG2_all) & (year_4|year_5|year_6) , stat (n sum mean) 


*-------------------------------------------------------------------------------
* Panel B (Table 1). Sample Distribution
*-------------------------------------------------------------------------------

tabstat ISScoverage if ($TREATMENT_all | $CG1_all |$CG2_all) & (year_4|year_5|year_6) , stat (n sum mean) by(year)
tabstat ISScoverage if $TREATMENT_all  & (year_4|year_5|year_6), stat (n sum mean) by(year)
tabstat ISScoverage if $CG1_all & (year_4|year_5|year_6), stat (n sum mean) by(year)
tabstat ISScoverage if $CG2_all & (year_4|year_5|year_6) , stat (n sum mean) by(year)

********************************************************************************
********************************************************************************
********************************************************************************
*
* TABLE 2: Baseline Results: Average Treatment Effect
*
********************************************************************************
********************************************************************************
********************************************************************************

set more off
use Master5, clear

*-------------------------------------------------------------------------------
* Panel A (Table 2): Mean comparisons 
*-------------------------------------------------------------------------------

qui estpost tabstat ISScoverage, stat(n) 
esttab using Platzhalter.rtf, replace cells("count(fmt(0))")  noobs nonumbers  title  (START)
	
foreach x of varlist GOVscore MLpc_ALLm60FY  lnRECNOmedian_m60FY IB_InvManNonIndex  {
	
set more off
use Master5, clear

*VARIABLE MANAGEMENT
set more off
macro dir  
macro drop CG1 CG2 TREATMENT POST DV PREPERIOD POSTPERIOD
global CG1 			"control5y1_s2"
global CG2  		"control5y2_s2"
global TREATMENT  	"TreatmentGroup5y_s2" 
global POST			"Post5y_s2"
global DV 			"`x'" 
global PREPERIOD 	"year_4"
global POSTPERIOD 	"year_5|year_6"

						
*** PANEL A: Main Descriptive Analysis and Univariate DiD

qui estpost tabstat $DV if ($TREATMENT ) & ($PREPERIOD) , stat(mean min max n) 
	esttab using Platzhalter.rtf, append cells("mean(fmt(2))    count(fmt(0))")  noobs nonumbers  title  ((1) TREATMENT & PREPERIOD: `x' ) compress order ($DV) keep ($DV )
qui estpost tabstat $DV if ($TREATMENT ) & ($POSTPERIOD) , stat(mean min max n) 
	esttab using Platzhalter.rtf, append cells("mean(fmt(2))    count(fmt(0))")  noobs nonumbers  title  ((2) TREATMENT & POSTPERIOD: `x') compress order ($DV)  keep ($DV)
qui estpost ttest $DV  if  ($TREATMENT) & ($PREPERIOD|$POSTPERIOD), by($PREPERIOD) 
	esttab using Platzhalter.rtf, append cells("b(fmt(2))  t(fmt(2))  p(fmt(2))  count(fmt(0))")  noobs nonumbers coeflabels(`x') title  ((1) TREATMENT & PREPERIOD vs.POSTPERIOD: `x') compress order ($DV) keep ($DV)
***
qui estpost tabstat $DV if ($CG1|$CG2 ) & ($PREPERIOD) , stat(mean min max n) 
	esttab using Platzhalter.rtf, append cells("mean(fmt(2))     count(fmt(0))")  noobs nonumbers  title  ((3) CG1CG2 & PREPERIOD: `x') compress order ($DV) keep ($DV)
qui estpost tabstat $DV if ($CG1|$CG2 ) & ($POSTPERIOD) , stat(mean min max n) 
	esttab using Platzhalter.rtf, append cells("mean(fmt(2))   count(fmt(0))")  noobs nonumbers  title  ((4) CG1CG2 & POSTPERIOD: `x') compress order ($DV) keep ($DV)
qui estpost ttest $DV  if  ($CG1|$CG2) & ($PREPERIOD|$POSTPERIOD), by($PREPERIOD) 
	esttab using Platzhalter.rtf, append cells("b(fmt(2))  t(fmt(2))  p(fmt(2))  count(fmt(0))")  noobs nonumbers coeflabels(`x') title  ((1) TREATMENT & PREPERIOD vs.POSTPERIOD: `x') compress order ($DV)  keep ($DV)
***
set more off
sort i year
gen var1 = $TREATMENT
gen var2 = ($CG1|$CG2)
***
	forvalues i = 1(1)2 {
		
		gen help1 = $DV if (var`i') & ($PREPERIOD)
		egen meanhelp1=mean(help1) if (var`i') & ($PREPERIOD), by(i)
		egen maxhelp1=max(meanhelp1)  if (var`i'), by(i)

		gen help2 = $DV if (var`i') & ($POSTPERIOD)
		egen meanhelp2=mean(help2) if (var`i') & ($POSTPERIOD), by(i)
		egen maxhelp2=max(meanhelp2)  if (var`i'), by(i)

		gen DV_var`i'diff=maxhelp2-maxhelp1
		drop help1-maxhelp2

}
***
drop var1 - var2
ttest DV_var1diff==0 if  ($PREPERIOD)
ttest DV_var2diff==0 if  ($PREPERIOD)
ttest DV_var1diff == DV_var2diff if  ($PREPERIOD), unpaired
}
*

********************************************************************************
********************************************************************************

set more off
use Master5, clear

*VARIABLE MANAGEMENT:
set more off
macro dir 
macro drop CG1  CG2 TREATMENT POST POST_TREAT DV1 CONTROLVAR1 DV2 CONTROLVAR2 PREPERIOD POSTPERIOD
global CG1 			"control5y1_s2"
global CG2  		"control5y2_s2"
global TREATMENT  	"TreatmentGroup5y_s2" 
global POST			"Post5y_s2"
global POST_TREAT   "Post_Treatment5y_s2"
global DV1 			"GOVscore" 
global CONTROLVAR1 	"lnsizewin99 levwin99 ROAwin99  growthwin99  noshffwin99 BoardSize asset4"
global DV2 			"MLpc_ALLm60FY" 
global CONTROLVAR2 	"lnMVmedian_m60FYwin99 lnRV_m60FYwin99 levwin99 ROAwin99 PPE_TAwin99 inv_stockpricewin99  IFRS noshffwin99 asset4"
global PREPERIOD 	"year_4"
global POSTPERIOD 	"year_5|year_6"

*-------------------------------------------------------------------------------
* Panel B (Table 2): Difference-in-differences regressions: CorpGov & Liquidity
*-------------------------------------------------------------------------------
						
estimates clear
quietly reg $DV1 i.$TREATMENT##i.$POST 	  	if  ($CG1|$CG2|$TREATMENT)  & ($PREPERIOD|$POSTPERIOD), vce(cluster i)
eststo
quietly areg $DV1 i.$TREATMENT##i.$POST   i.year	  	if  ($CG1|$CG2|$TREATMENT)  & ($PREPERIOD|$POSTPERIOD), a(i) cluster(i)
eststo
quietly areg $DV1 i.$TREATMENT##i.$POST  $CONTROLVAR1 i.year	  	if  ($CG1|$CG2|$TREATMENT)  & ($PREPERIOD|$POSTPERIOD), a(i) cluster(i)
eststo
quietly reg $DV2 i.$TREATMENT##i.$POST 	  	if  ($CG1|$CG2|$TREATMENT)  & ($PREPERIOD|$POSTPERIOD), vce(cluster i)
eststo
quietly areg $DV2 i.$TREATMENT##i.$POST   i.year	  	if  ($CG1|$CG2|$TREATMENT)  & ($PREPERIOD|$POSTPERIOD), a(i) cluster(i)
eststo
quietly areg $DV2 i.$TREATMENT##i.$POST  $CONTROLVAR2 i.year	  	if  ($CG1|$CG2|$TREATMENT)  & ($PREPERIOD|$POSTPERIOD), a(i) cluster(i)
eststo
esttab,  	star(* 0.10 ** 0.05 *** 0.01) b(3) stats(F N r2_a p_diff)   title (Panel B (Table 2): Difference-in-differences regressions: CorpGov & Liquidity) ///
				nonumbers mtitles("Model 1" "Model 2" "Model 3" "Model 4" "Model 5" "Model 6"   ) compress ///
				keep (1.$POST  1.$TREATMENT  1.$TREATMENT#1.$POST  $CONTROLVAR1 $CONTROLVAR2) ///
				order (1.$POST  1.$TREATMENT  1.$TREATMENT#1.$POST  $CONTROLVAR1 $CONTROLVAR2)
esttab using Platzhalter.rtf, replace ///
				star(* 0.10 ** 0.05 *** 0.01) b(3) stats(F N r2_a p_diff)  label title (Panel B (Table 2): Difference-in-differences regressions: CorpGov & Liquidity) ///
				nonumbers mtitles ("Model 1" "Model 2" "Model 3" "Model 4" "Model 5" "Model 6" ) compress varwidth(12)  modelwidth(6) ///
				keep (1.$POST  1.$TREATMENT  1.$TREATMENT#1.$POST  $CONTROLVAR1 $CONTROLVAR2) ///
				order (1.$POST  1.$TREATMENT  1.$TREATMENT#1.$POST  $CONTROLVAR1 $CONTROLVAR2)
estimates clear


********************************************************************************
********************************************************************************

set more off
use Master5, clear

*VARIABLE MANAGEMENT:
set more off
macro dir 
macro drop CG1  CG2 TREATMENT POST POST_TREAT DV1 CONTROLVAR1 DV2 CONTROLVAR2 PREPERIOD POSTPERIOD
global CG1 			"control5y1_s2"
global CG2  		"control5y2_s2"
global TREATMENT  	"TreatmentGroup5y_s2" 
global POST			"Post5y_s2"
global POST_TREAT   "Post_Treatment5y_s2"
global DV1 			"lnRECNOmedian_m60FY" 
global CONTROLVAR1 	"lnsizewin99 levwin99 ROAwin99 PPE_TAwin99 noshffwin99 IFRS inv_stockpricewin99 asset4"
global DV2 			"IB_InvManNonIndex" 
global CONTROLVAR2 	"lnsizewin99 levwin99 ROAwin99  cfowin99 dpswin99 PPE_TAwin99 IFRS inv_stockpricewin99 asset4 "
global PREPERIOD 	"year_4"
global POSTPERIOD 	"year_5|year_6"

*-------------------------------------------------------------------------------
* Panel C (Table 2): Difference-in-differences regressions: Ln(AF) & InvBreadth
*-------------------------------------------------------------------------------
						
estimates clear
quietly reg $DV1 i.$TREATMENT##i.$POST 	  	if  ($CG1|$CG2|$TREATMENT)  & ($PREPERIOD|$POSTPERIOD), vce(cluster i)
eststo
quietly areg $DV1 i.$TREATMENT##i.$POST   i.year	  	if  ($CG1|$CG2|$TREATMENT)  & ($PREPERIOD|$POSTPERIOD), a(i) cluster(i)
eststo
quietly areg $DV1 i.$TREATMENT##i.$POST  $CONTROLVAR1 i.year	  	if  ($CG1|$CG2|$TREATMENT)  & ($PREPERIOD|$POSTPERIOD), a(i) cluster(i)
eststo
quietly reg $DV2 i.$TREATMENT##i.$POST 	  	if  ($CG1|$CG2|$TREATMENT)  & ($PREPERIOD|$POSTPERIOD), vce(cluster i)
eststo
quietly areg $DV2 i.$TREATMENT##i.$POST   i.year	  	if  ($CG1|$CG2|$TREATMENT)  & ($PREPERIOD|$POSTPERIOD), a(i) cluster(i)
eststo
quietly areg $DV2 i.$TREATMENT##i.$POST  $CONTROLVAR2 i.year	  	if  ($CG1|$CG2|$TREATMENT)  & ($PREPERIOD|$POSTPERIOD), a(i) cluster(i)
eststo
esttab,  	star(* 0.10 ** 0.05 *** 0.01) b(3) stats(F N r2_a p_diff)   title (Panel C (Table 2): Difference-in-differences regressions: Ln(AF) & InvBreadth) ///
				nonumbers mtitles("Model 1" "Model 2" "Model 3" "Model 4" "Model 5" "Model 6"   ) compress ///
				keep (1.$POST  1.$TREATMENT  1.$TREATMENT#1.$POST  $CONTROLVAR1 $CONTROLVAR2) ///
				order (1.$POST  1.$TREATMENT  1.$TREATMENT#1.$POST  $CONTROLVAR1 $CONTROLVAR2)
esttab using Platzhalter.rtf, replace ///
				star(* 0.10 ** 0.05 *** 0.01) b(3) stats(F N r2_a p_diff)  label title (Panel C (Table 2): Difference-in-differences regressions: Ln(AF) & InvBreadth) ///
				nonumbers mtitles ("Model 1" "Model 2" "Model 3" "Model 4" "Model 5" "Model 6" ) compress varwidth(12)  modelwidth(6) ///
				keep (1.$POST  1.$TREATMENT  1.$TREATMENT#1.$POST  $CONTROLVAR1 $CONTROLVAR2) ///
				order (1.$POST  1.$TREATMENT  1.$TREATMENT#1.$POST  $CONTROLVAR1 $CONTROLVAR2)
estimates clear



*///////////////////////////////////////////////////////////////////////////////
*///////////////////////////////////////////////////////////////////////////////
*///////////////////////////////////////////////////////////////////////////////

*///////////////////////////////////////////////////////////////////////////////
*///////////////////////////////////////////////////////////////////////////////
*///////////////////////////////////////////////////////////////////////////////
*
*		THE END
*
*///////////////////////////////////////////////////////////////////////////////
*///////////////////////////////////////////////////////////////////////////////
*///////////////////////////////////////////////////////////////////////////////

*///////////////////////////////////////////////////////////////////////////////
*///////////////////////////////////////////////////////////////////////////////
*///////////////////////////////////////////////////////////////////////////////


brainstormingobra/superpowersYou MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).Stars: 323kUpdated Claude CodeCodexVerifiedInstall
brand-guidelinesanthropics/skillsApplies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
frontend-designanthropics/skillsGuidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
mcp-builderanthropics/skillsGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).Stars: 198kUpdated Claude CodeCodexVerifiedInstall