1. Market to Book
MTB at the calendar year end.
use week_ret.dta,clear
gen year=year(date)
bys PERMNO year: egen max_date=max(date)
keep if date==max_date
drop max_date
gen market_v=SHROUT*1000*PRC
keep PERMNO year market_v SHROUT
duplicates drop PERMNO year,force
merge m:1 PERMNO using ccmlink_permno
keep if _merge==3
drop _merge
keep year market_v gvkey SHROUT
duplicates drop gvkey year,force
save mtb.dta,replace
2. Average return and average trading volume (daily)
use vol_prc_ret.dta,clear
gen year=year(date)
drop if missing(VOL)
gen vol_deflate=VOL/SHROUT
bys PERMNO year:egen ave_vol=mean(vol_deflate)
bys PERMNO year:egen mean_ret=mean(RET)
duplicates drop PERMNO year,force
xtset PERMNO year
gen delta_vol=ave_vol-L.ave_vol
keep PERMNO year ave_vol delta_vol mean_ret
//Link to GVKEY
merge m:1 PERMNO using ccmlink_permno.dta
keep if _merge==3
drop _merge
duplicates drop gvkey year,force
save vol_ret_control.dta,replace
3. Return Volatility, weekly return
use week_ret2.dta,clear
bys PERMNO year:egen mean_ret=mean(week_ret)
bys PERMNO year:egen std_ret=sd(week_ret)
rename std_ret ret_sd
keep PERMNO year ret_sd mean_ret
duplicates drop PERMNO year,force
merge m:1 PERMNO using ccmlink_permno
keep if _merge==3
drop _merge PERMNO
duplicates drop gvkey year,force
save ret_control.dta,replace
4. Earnings volatility, proxied by sd of ROA, and total accruals
use sd_roa_ta.dta,clear
drop if at==.
gen t_accruals=(ib-oancf)/at
gen roa=ib/at
rangestat (sd) roa, interval(fyear -4 0) by(gvkey)
rename roa_sd sd_roa
rangestat (sd) roa, interval(fyear -5 0) by(gvkey)
rename roa_sd sd_roa2
gen year=fyear if fyr>5
replace year=fyear+1 if fyr<6
keep gvkey year sd_roa sd_roa2 t_accruals
duplicates drop gvkey year,force
destring gvkey,replace
gen raw_ta=t_accruals
replace t_accruals=abs(t_accruals)
save sd_roa_ta.dta,replace
5. Segment HHI, Segment concentration
//Control: segment HHI of firms
use seg_hhi.dta,clear
gen year=year(datadate)
egen double total = total(sales), by(year gvkey)
egen double seg_HHI = total((sales/total)^2), by(year gvkey)
keep gvkey year seg_HHI
duplicates drop gvkey year,force
destring gvkey,replace
save seg_hhi.dta,replace
6. Other fiscal fundamental variables - applicable almost to all papers
gen size=ln(at)
gen m_cap=ln(market_v/1000)
gen lev=dt/at
gen roa=ib/at
7. Industry size, industry concentration
replace sic=substr(sic,1,2)
bys sic year:gen ind_size_raw=_N
gen ind_size=ln(ind_size_raw+1)
egen double total = total(sale), by(year sic)
egen double ind_HHI = total((sale/total)^2), by(year sic)
8. Earnings Comovement
use "fund_corr.dta",clear
drop indfmt consol popsrc datafmt curcdq costat
replace sic=substr(sic,1,2)
destring sic,replace
drop if sic==.
drop if missing(fyearq)
bys sic datafqtr:egen sum_at=sum(atq/1000)
gen wgt_at=(atq/1000)/sum_at
gen roa=ibq/atq
drop if roa==.
gen w_roa=roa*wgt_at
bys sic datafqtr:egen ind_w_roa=sum(w_roa)
drop sum_at wgt_at w_roa
gen yq = yq(fyearq, fqtr)
format yq %tq
drop if missing(yq)
bys gvkey: asreg ind_w_roa roa, window(yq -12 0) save(roa_reg)
drop if _Nobs==.
drop if _Nobs<10
gen r2_roa = log(_R2/(1-_R2))
bys gvkey fyearq: egen fund_cor=mean(r2_roa)
duplicates drop gvkey fyearq,force
rename fyearq fyear
gen year=fyear if fyr>5
replace year=fyear+1 if fyr<6
keep year gvkey fund_cor
duplicates drop year gvkey,force
destring gvkey,replace
save fund_cor.dta,replace