We provide Python code to estimate production functions and firm-level markups from firm-level income statements. The code implements the algorithm described in the appendix of The Hitchhiker's Guide to Markup Estimation: Assessing Estimates from Financial Data
In the code that can be downloaded here, we reproduce the estimation of markup and the underlying production function coefficients from:
The Rise of Market Power and the Macroeconomic Implications, De Loecker, Eeckhout, and Unger, The Quarterly Journal of Economics, Volume 135, Issue 2, May 2020, Pages 561–644, https://doi.org/10.1093/qje/qjz041
We believe that this code is easy to use and to apply to different firm-level datasets.
Citation suggestion:
De Ridder, Grassi, and Morzenti (2024), DP17532, "The Hitchhiker’s Guide to Markup Estimation: Assessing Estimates from Financial Data", CEPR Discussion Paper No. 17532. CEPR Press, Paris & London. https://cepr.org/publications/dp17532
The times series for the aggregate markups in the figure below can be downloaded here.
You will find:
mu_harmonic: sales-weighted harmonic mean of firm-level markups (for constant 2-digit Cobb-Douglas production functions)
mu_harmonic_roll: sales-weighted harmonic mean of firm-level markups (for 7-year rolling window 2-digit Cobb-Douglas production functions)
mu_wts : sales-weighted simple mean of firm-level markups (for constant 2-digit Cobb-Douglas production functions)
mu_wts_roll: sales-weighted simple mean of firm-level markups (for 7-year rolling window 2-digit Cobb-Douglas production functions)
The first two are aggregate markup series while the last two are moments of firm-level markup distribution.
(The last tow series estimates from the original De Loecker, Eeckhout, and Unger (2020) can be downloaded here from Jan De Loecker's website.)
The zip file contains:
a readme file
ProdFun_VPublic.py: a Python code that contains the production function estimation class.
Clean_Data.do: stata script which cleans the Compustat data.
Run_Compustat_VPublic.py: a Python code that estimates the production function and markup on Compustat data.
DEFL_Y.dta: a stata dataset that contains some deflators.
Note: you will need to bring your Compustat data
First, run the Clean_data.do in your Stata, after changing some path. This will compute the cleaned dataset COMPUSTAT_clean.csv.
Second Run_Compustat_HarmonicMean_VPublic.py with your python. This will perform the estimation and save the firm-level markups in Compustat_Markups_Python_V1.dta and the production function coefficients in the Stata datasets Compustat_Betas_Python_V1.dta and Compustat_BetasRoll_Python_V1.dta. The class ProdFun_VPublic.py allows for many different options that are explained directly in the script.
Our code produces the figure above that plots sales-weighted simple mean markup and the sales-weighted harmonic mean markup: