Here you can find Python code to estimate production functions and firm-level markups from firm-level income statements.
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
This code is easy to use and to apply to different firm-level datasets.
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.)
(Stata code to estimate markup on compustat data can be found on Maarten De Ridder website here)
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: