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

View on GitHub
*LOAD DATA *********************************************************************


*change to the directory this do file lives in
//you have to manually change to this directory, it won't do it automatically.


//Eric Desktop
cd  "D:\Dropbox\IBES project 2\Code"

//Eric KU Laptop
cd "C:\Users\e679w418\Dropbox\IBES project 2\Code"

//For Musa
cd "C:\Users\msubasi\Dropbox\IBES project 2\Code"


// KB
cd "D:\Dropbox\IBES project 2\Code"


clear
set more off

macro drop _all

*use relative path from the code folder to the data folder

*load raw data
use "..\Data\main_sample_2021.dta", clear


//log variables that need logging
replace all_count = 0 if missing(all_count)
gen ln_media_coverage = ln(1+all_count)
gen ln_lagmins = ln(1 + pr_lagmins)


gen ln_size = ln(size)
gen ln_analyst_following = ln(1+analyst_following)
gen ln_advertising = ln(1+advertising_expense)
gen ln_firmage = ln(1+firm_age)

drop if reporting_lag < 1
gen ln_reporting_lag = ln(reporting_lag)

gen ln_unactivated_actuals = ln(1+ unact_ea)
 
//other transformations
gen abs_surprise = abs(surprise_con)

//check st earnings sample sizes
egen stmis=rmiss2 ( f_st_earnings f_cfo st_earnings)
replace f_st_earnings  = . if stmis != 0
replace f_cfo  = . if stmis != 0
replace st_earnings = . if stmis != 0


//winsorize intraday analyses variables to a 1-day timeframe

replace act_tmin_delay = 960 if act_tmin_delay > 960
replace aly_tmin_delay = 960 if aly_tmin_delay > 960
replace aly_tmin_delay = 960 if missing(aly_tmin_delay)
replace wmrt = -2.5 if missing(wmrt)

//log trading delays
gen ln_act_tmin_delay = ln(1+act_tmin_delay)
gen ln_aly_tmin_delay = ln(1+aly_tmin_delay)


*define controls
global controls abs_gaap_st_diff abs_surprise bnews guidance qtr4 ///
ln_reporting_lag  ///
ln_size ln_firmage io ln_analyst_following  sp500 ///
ln_advertising ln_unactivated_actuals friday ///
log_allwords hardinfomix nongaap_scaled ln_media_coverage 


//drop any missing controls
egen miss_control = rmiss2 ( $controls)
drop if miss_control > 0

//drop qtrs pre-2004 SEC regulation change because few/no 8-Ks
drop if yearqtr <= mdy(12,31,2004) 


// align samples for analyst tests


gen analyst_delay = aly_tmin_delay

replace analyst_delay=. if missing(dispersion_act_w)
replace analyst_delay=. if missing(mafe_act_w)
replace analyst_delay=. if n_fpi6_fcasts_5day < 3
replace dispersion_act_w=. if n_fpi6_fcasts_5day < 3
replace mafe_act_w = . if missing(dispersion_act_w)
replace mafe_act_w = . if n_fpi6_fcasts_5day < 3


gen ln_analyst_delay = ln(1 + analyst_delay)


//generate post_treatment interactions
gen post_treatment = post*treatment
gen post_st_earnings = post*st_earnings
gen treatment_st_earnings = treatment*st_earnings
gen post_treatment_st_earnings = post*treatment*st_earnings


*identify singleton observations
//table 3 singletons
reghdfe ln_lagmins post treatment post_treatment $controls ///
,absorb(permno yearqtr pr_hr) cluster(permno pr_date)

drop if e(sample)==0

//table 4 singletons
reghdfe f_st_earnings treatment post_treatment st_earnings ///
post_st_earnings treatment_st_earnings post_treatment_st_earnings ///
$controls , absorb(permno yearqtr pr_hr) cluster(permno pr_date)

replace f_st_earnings  = . if e(sample) == 0
replace f_cfo  = . if e(sample)==0
replace st_earnings = . if e(sample)==0

//Table 5, col 1
reghdfe diff post treatment post_treatment ///
$controls if !missing(dispersion_act_w) & n_fpi6_fcasts_5day > 2 ///
, absorb(permno yearqtr pr_hr) cluster(permno pr_date)

replace diff = . if e(sample)==0

//Table 5, col 2
reghdfe ln_aly_tmin_delay post treatment post_treatment ///
$controls if !missing(dispersion_act_w) & n_fpi6_fcasts_5day > 2 ///
, absorb(permno yearqtr pr_hr) cluster(permno pr_date)

replace analyst_delay =. if e(sample) == 0
replace ln_analyst_delay =. if e(sample) == 0
replace dispersion_act_w=. if e(sample) == 0
replace mafe_act_w = . if e(sample) == 0

/* WINSORIZE VARIABLES */
winsor2 ln_size ln_analyst_following ln_firmage abs_gaap_st_diff mafe_act_w dispersion_act_w st_earnings f_st_earnings  f_cfo abs_surprise ln_reporting_lag log_allwords hardinfomix nongaap_scaled ln_media_coverage ln_unactivated_actuals ln_advertising ln_analyst_delay ln_aly_tmin_delay ln_act_tmin_delay onetimeitems_scaled, replace

//after winsorizing, we need to
//replace post_treatment interactions with winsorized st earnings
replace post_st_earnings = post*st_earnings
replace treatment_st_earnings = treatment*st_earnings
replace post_treatment_st_earnings = post*treatment*st_earnings




//Alternate treatment for internet appendix
sum onetimeitems_scaled, d

gen treatment2=(onetimeitems_scaled> r(p50)) // text-based treatment

gen post_treatment2 = post*treatment2

gen treatment2_st_earnings = treatment2*st_earnings

gen post_treatment2_st_earnings = post*treatment2*st_earnings



//Label variables

label var pr_lagmins "\emph{Activation Delay}"
label var ln_lagmins "\emph{Ln(Activation Delay)}"
label var post "\emph{Post}"
label var treatment "\emph{Treatment}"
label var post_treatment "\emph{Post} $\times$ \emph{Treatment}"

label var f_st_earnings "\emph{Future Street Earnings}"
label var f_cfo "\emph{Future Cash Flows}"
label var st_earnings "\emph{Street Earnings}"
label var post_st_earnings "\emph{Street Earnings} $\times$ \emph{Post}"
label var treatment_st_earnings "\emph{Street Earnings} $\times$ \emph{Treatment}"
label var post_treatment_st_earnings "\emph{Street Earnings} $\times$ \emph{Post} $\times$ \emph{Treatment}"

label var diff "\emph{DIFF}"
label var analyst_delay"\emph{Forecasting Delay}"
label var ln_analyst_delay"\emph{Ln(Forecasting Delay)}"
label var mafe_act_w "\emph{mafe_act_w}"
label var dispersion_act_w "\emph{dispersion_act_w}"

label var abs_gaap_st_diff "\emph{Abs(GAAP-Street)}"
label var abs_surprise "\emph{Abs(Surprise)}"
label var bnews "\emph{Bad News}"
label var guidance "\emph{EPS Guidance}"
label var qtr4 "\emph{QTR4}"
label var ln_reporting_lag "\emph{Reporting Lag}"
label var ln_size "\emph{Size}"
label var ln_firmage "\emph{Firm Age}"
label var io "\emph{Institutional Ownership}"
label var ln_analyst_following "\emph{Analyst Following}"
label var sp500 "\emph{S\&P 500}"

label var ln_advertising "\emph{Advertising}"
label var ln_unactivated_actuals "\emph{Unactivated Actuals}"
label var friday "\emph{Friday}"

label var log_allwords "\emph{Press Release Words}"
label var nongaap_scaled "\emph{Non-GAAP Words}"
label var hardinfomix "\emph{HardInfoMix}"
label var ln_media_coverage "\emph{Media Coverage}"
label var wmrt "\emph{MRT}"

//financial crisis dates for internet appendix 
gen crisis2 = pr_date> td(01jul2007) & pr_date< td(30mar2009)

save "..\Data\wins_sample_2021.dta", replace


*change to the directory this do file lives in
//you have to manually change to this directory, it won't do it automatically.


//Eric Desktop
cd  "D:\Dropbox\IBES project 2\Code"

//Eric KU Laptop
cd "C:\Users\e679w418\Dropbox\IBES project 2\Code"

//For Musa
cd "C:\Users\msubasi\Dropbox\IBES project 2\Code"


// KB
cd "D:\Dropbox\IBES project 2\Code"



// Analyst Wins Sample *********************************************************


clear
set more off

macro drop _all


use "..\Data\analyst_level_sample.dta", clear 

//generate the ana_first variable
gen ana_first = 1 if  analyst_cmin_delay < pr_lagmins
replace ana_first = 0 if  analyst_cmin_delay > pr_lagmins

//winsorize the continuous variables 
winsor2 gexp fexp analysts_employed mean_abs_fcast_error_act_w abs_fcast_error_prc abs_fcast_error_act_w n_ea_covered_5d, by(yearqtr) replace



//generate analyst-level variables
gen ln_analysts_employed=ln(analysts_employed)
gen ln_gexp=ln(gexp)
gen ln_fexp=ln(fexp)
gen ln_ea_covered_5d = ln(1+n_ea_covered_5d)
gen accuracy=-1* mean_abs_fcast_error_act_w


save "..\Data\wins_analyst_sample_2021.dta", replace
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