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_56_ksvw.do

View on GitHub
set memory 4096M
set matsize 5000

set more off
cd "C:\My_Works\Research_1\CDS_Information_Environment\Data\Results"

set seed 123456
gen u=uniform()
sort u

*Main tests
*Table 2: Main Test
use "C:\My_Works\Research_1\CDS_Information_Environment\Data\data_1_ver_2017_11.dta", clear  

* Panel A
xi:reg d_mf1 cds cds_traded log_at_w lag_mtb_w roa_w inst_own_w log_following_w rvol_w eq_iss lit mid_zscore lag_leverage_w i.fyear , cluster(gvkey)

xi:reg log_num_mf1_w cds cds_traded log_at_w lag_mtb_w roa_w  inst_own_w log_following_w rvol_w eq_iss lit mid_zscore lag_leverage_w i.fyear, cluster(gvkey)

* Panel B
xi: reg d_mf1 cds cds_traded log_at_w lag_mtb_w roa_w inst_own_w log_following_w rvol_w eq_iss lit mid_zscore lag_leverage_w i.fyear if fyear > 2001, cluster(gvkey)

xi: reg log_num_mf1_w cds cds_traded log_at_w lag_mtb_w roa_w  inst_own_w log_following_w rvol_w eq_iss lit mid_zscore lag_leverage_w i.fyear if  fyear > 2001, cluster(gvkey)


*Table 3: Cross-sectional test: ease of hedging by lenderst & Extent of Lender Monitoring
*Panel A: CDS Liquidity & Credit Derivative Protection
use "C:\My_Works\Research_1\CDS_Information_Environment\Data\data_1_ver_2017_11.dta", clear  

*(1) CDS Liquidity
xi:reg d_mf1 low_cds_1 high_cds_1  cds_traded   log_at_w lag_mtb_w roa_w inst_own_w log_following_w rvol_w eq_iss lit mid_zscore lag_leverage_w i.fyear , cluster(gvkey)
test low_cds_1 = high_cds_1

xi:reg log_num_mf1_w low_cds_1 high_cds_1  cds_traded  log_at_w lag_mtb_w roa_w  inst_own_w log_following_w rvol_w eq_iss lit mid_zscore lag_leverage_w i.fyear , cluster(gvkey)
test low_cds_1 = high_cds_1

xi:reg d_mf1 low_cds_2 high_cds_2  cds_traded   log_at_w lag_mtb_w roa_w inst_own_w log_following_w rvol_w eq_iss lit mid_zscore lag_leverage_w i.fyear , cluster(gvkey)
test low_cds_2 = high_cds_2

*(2) Credit Derivative Protection
xi:reg log_num_mf1_w low_cds_2 high_cds_2  cds_traded  log_at_w lag_mtb_w roa_w  inst_own_w log_following_w rvol_w eq_iss lit mid_zscore lag_leverage_w i.fyear , cluster(gvkey)
test low_cds_2 = high_cds_2

xi:reg d_mf1 low_rel_cds_protect high_rel_cds_protect cds_traded log_at_w lag_mtb_w roa_w inst_own_w log_following_w rvol_w eq_iss lit  mid_zscore lag_leverage_w i.fyear , cluster(gvkey)
test low_rel_cds_protect = high_rel_cds_protect

xi:reg log_num_mf1_w low_rel_cds_protect high_rel_cds_protect cds_traded log_at_w lag_mtb_w roa_w  inst_own_w log_following_w rvol_w eq_iss lit mid_zscore lag_leverage_w i.fyear , cluster(gvkey)
test low_rel_cds_protect = high_rel_cds_protect

*Panel B: Extent of Lender Monitoring (above/below median)
use "C:\My_Works\Research_1\CDS_Information_Environment\Data\data_1_ver_2017_11.dta", clear  

*(1): Bank Allocation
xi:reg d_mf1 cds cds_h2_bksh h2_bksh cds_traded log_at_w lag_mtb_w roa_w inst_own_w log_following_w rvol_w eq_iss lit  mid_zscore lag_leverage_w  i.fyear, cluster(gvkey)

xi:reg log_num_mf1_w cds cds_h2_bksh h2_bksh cds_traded log_at_w lag_mtb_w roa_w inst_own_w log_following_w rvol_w eq_iss lit  mid_zscore lag_leverage_w  i.fyear, cluster(gvkey)

*(2): financial covenant
xi:reg d_mf1 cds cds_h2_fincov h2_fincov cds_traded log_at_w lag_mtb_w roa_w inst_own_w log_following_w rvol_w eq_iss lit  mid_zscore lag_leverage_w  i.fyear, cluster(gvkey)

xi:reg log_num_mf1_w cds cds_h2_fincov h2_fincov cds_traded log_at_w lag_mtb_w roa_w inst_own_w log_following_w rvol_w eq_iss lit  mid_zscore lag_leverage_w i.fyear, cluster(gvkey)

*(3): distress risk
xi:reg d_mf1 cds cds_h2_lag_leverage h2_lag_leverage cds_traded log_at_w lag_mtb_w roa_w inst_own_w log_following_w rvol_w eq_iss lit mid_zscore i.fyear , cluster(gvkey)

xi:reg log_num_mf1_w cds cds_h2_lag_leverage h2_lag_leverage cds_traded log_at_w lag_mtb_w roa_w inst_own_w log_following_w rvol_w eq_iss lit mid_zscore i.fyear  , cluster(gvkey)


*Table 4: Equityholders' Demand above/below median)
use "C:\My_Works\Research_1\CDS_Information_Environment\Data\data_1_ver_2017_11.dta", clear  

*(1): strong board: borad independence
xi:reg d_mf1 cds cds_high_bd high_bd cds_traded log_at_w lag_mtb_w roa_w inst_own_w log_following_w rvol_w eq_iss lit  mid_zscore lag_leverage_w  i.fyear , cluster(gvkey)

xi:reg log_num_mf1 cds cds_high_bd high_bd cds_traded log_at_w lag_mtb_w roa_w inst_own_w log_following_w rvol_w eq_iss lit  mid_zscore lag_leverage_w  i.fyear , cluster(gvkey)

*(2)  High Institutions & No blocking holders
xi:reg d_mf1 cds cds_comb_ins_blk_2 comb_ins_blk_2 cds_traded log_at_w lag_mtb_w roa_w inst_own_w log_following_w rvol_w eq_iss lit  mid_zscore lag_leverage_w  i.fyear, cluster(gvkey)

xi:reg log_num_mf1_w cds cds_comb_ins_blk_2 comb_ins_blk_2 cds_traded log_at_w lag_mtb_w roa_w inst_own_w log_following_w rvol_w eq_iss lit  mid_zscore lag_leverage_w i.fyear, cluster(gvkey)


*Table 5: Interaction of Lender monitoring intensity and shareholder' information demand
use "C:\My_Works\Research_1\CDS_Information_Environment\Data\data_1_ver_2017_11.dta", clear  

*(1) high cds liquidity & high institutional ownership (no block) & low lead lenders' share;
xi: reg d_mf1 cds_other_1 cds_low_all_1 cds_high_all_1   cds_traded   log_at_w lag_mtb_w roa_w inst_own_w log_following_w rvol_w eq_iss lit mid_zscore lag_leverage_w i.fyear if high_all_1_miss == 0, cluster(gvkey)
test cds_high_all_1 = cds_low_all_1

xi:reg log_num_mf1_w  cds_other_1 cds_low_all_1 cds_high_all_1   cds_traded   log_at_w lag_mtb_w roa_w inst_own_w log_following_w rvol_w eq_iss lit mid_zscore lag_leverage_w i.fyear if high_all_1_miss == 0, cluster(gvkey)
test cds_high_all_1 = cds_low_all_1

*(2) high cds liquidity & high institutional ownership (no block) & low financial covenants;
xi: reg d_mf1 cds_other_2 cds_low_all_2 cds_high_all_2   cds_traded   log_at_w lag_mtb_w roa_w inst_own_w log_following_w rvol_w eq_iss lit mid_zscore lag_leverage_w i.fyear if high_all_2_miss == 0, cluster(gvkey)
test cds_high_all_2 = cds_low_all_2

xi:reg log_num_mf1_w  cds_other_2 cds_low_all_2 cds_high_all_2   cds_traded   log_at_w lag_mtb_w roa_w inst_own_w log_following_w rvol_w eq_iss lit mid_zscore lag_leverage_w i.fyear if high_all_2_miss == 0, cluster(gvkey)
test cds_high_all_2 = cds_low_all_2


*Table 6: Endogeneity - 1: PSM for CDS Initiation using 5year period around CDS initation
use "C:\My_Works\Research_1\CDS_Information_Environment\Data\data_2_ver_2017_11.dta", clear

set seed 123456
gen u=uniform()
sort u

*first stage (
xi: probit cds_initiation pre_rated pre_inv_grade pre_leverage_w pre_profit_margin_w pre_log_ta_w pre_ret_volatility_w pre_mtb_w , cluster(gvkey)
predict pscore if e(sample), pr

egen year_dind = group(year_cds_match)
gen pscore2=year_dind*100+pscore

drop if cds_traded == 1 & cds_year != first_cds_year

table cds_initiation if cds_traded  == 1
table cds_initiation if cds_traded  == 0

sort u

psmatch2 cds_initiation , pscore(pscore2) neighbor(3) 

#d;
keep u pscore pscore2 _pscore _weight _id _n1 _n2 _n3 _nn _pdif 
       cds_initiation gvkey datadate fyear cds cds_year first_cds_year cds_traded cds_first_date year_cds_match
	   pre_rated pre_inv_grade pre_leverage_w pre_profit_margin_w pre_log_ta_w pre_ret_volatility_w pre_mtb_w;
#d cr;

export sasxport "C:\My_Works\Research_1\CDS_Information_Environment\Data\psm_1st.xpt", rename replace vallabfile(none)

*second stage model;
use "C:\My_Works\Research_1\CDS_Information_Environment\Data\data_3_ver_2017_11.dta", clear
xi:reg log_num_mf1_w psm_cds post psm_cds_post log_at_w lag_mtb_w roa_w  inst_own_w log_following_w rvol_w eq_iss lit mid_zscore lag_leverage_w post_fd , cluster(gvkey)


*Table 7: Endogeneity - 2: Change analysis for CDS Initiation;
use "C:\My_Works\Research_1\CDS_Information_Environment\Data\data_4_ver_2017_11.dta", clear

*Panel A: change test
xi: reg chg_log_num_mf1_w chg_cds chg_log_at_w chg_lag_mtb_w chg_roa_w chg_inst_own_w chg_log_following_w chg_rvol_w chg_eq_iss lit chg_mid_zscore lagchg_leverage_w log_lag_num_mf1_w  i.fyear, cluster(gvkey)

*Panel B: Reverse Casaulity: OLS for cds initaiton 
xi: reg chg_cds pre_chg_log_num_mf1_w log_lag_num_mf1_w chg_log_at_w chg_lag_mtb_w chg_roa_w chg_inst_own_w chg_log_following_w chg_rvol_w chg_eq_iss lit chg_mid_zscore lagchg_leverage_w i.fyear, cluster(gvkey)
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