| name | stata-accounting-research |
| description | STATA code patterns for empirical accounting and finance research |
| metadata | {"openclaw":{"emoji":"📒","category":"domains","subcategory":"finance","keywords":["STATA","accounting","empirical finance","panel data","earnings management","audit"],"source":"wentor-research-plugins"}} |
STATA Accounting Research Guide
Overview
Empirical accounting research relies heavily on STATA for data manipulation, statistical analysis, and robustness testing. The field has developed standardized methodological approaches -- earnings quality models, event studies, difference-in-differences for regulatory changes, and instrument variable strategies for endogeneity -- that are implemented in a relatively stable set of STATA patterns.
This guide provides the core STATA code patterns used in top accounting journals (The Accounting Review, Journal of Accounting Research, Journal of Accounting and Economics, and Review of Accounting Studies). These patterns are drawn from commonly used research designs in financial reporting, auditing, tax, and managerial accounting research.
Whether you are estimating discretionary accruals, conducting an event study around an earnings announcement, testing the effect of auditor rotation on audit quality, or implementing a regulatory shock analysis, these patterns provide tested, reviewable STATA implementations.
Data Preparation
Loading and Cleaning COMPUSTAT Data
* ============================================================
* COMPUSTAT Annual Data Preparation for Accounting Research
* Standard preparation used across most empirical accounting papers
* ============================================================
* Load COMPUSTAT annual data
use "compustat_annual.dta", clear
* Keep relevant variables
keep gvkey fyear datadate at sale cogs xsga dp ib oancf act lct che dlc ///
csho prcc_f ceq re dltt txp xrd ppegt ppent invt rect
* Set panel structure
destring gvkey, replace
xtset gvkey fyear
* --- Basic cleaning ---
* Drop financial firms (SIC 6000-6999) and utilities (SIC 4900-4999)
drop if inrange(sic, 6000, 6999) | inrange(sic, 4900, 4999)
* Require minimum observations
bysort gvkey: gen nobs = _N
drop if nobs < 3
drop nobs
* --- Generate common variables ---
* Total accruals (balance sheet approach)
gen total_accruals = (D.act - D.che) - (D.lct - D.dlc) - dp
* Total accruals (cash flow approach, preferred)
gen total_accruals_cf = ib - oancf
* Scale by lagged total assets
gen lag_at = L.at
gen ta_scaled = total_accruals_cf / lag_at
gen sale_scaled = sale / lag_at
gen ppe_scaled = ppent / lag_at
gen dsale = D.sale / lag_at
gen drec = D.rect / lag_at
gen roa = ib / lag_at
* Market value of equity
gen mve = csho * prcc_f
* Book-to-market ratio
gen btm = ceq / mve
* Leverage
gen leverage = (dlc + dltt) / at
* Firm size
gen size = ln(at)
* --- Winsorize at 1% and 99% ---
foreach var of varlist ta_scaled sale_scaled ppe_scaled roa btm leverage size {
winsor2 `var', replace cuts(1 99)
}
* Label variables
label var ta_scaled "Total accruals / lagged assets"
label var roa "Return on assets"
label var btm "Book-to-market ratio"
label var leverage "Total debt / total assets"
label var size "Log(total assets)"
save "compustat_clean.dta", replace