A Python toolkit for estimating firm-level markups using production function-based marginal cost recovery.
Project description
PyMarkup-estimator
A Python toolkit for estimating firm-level markups using production function-based marginal cost recovery.
- PyPI package: https://pypi.org/project/PyMarkup-estimator/
- GitHub repository: https://github.com/immortalsRDJ/PyMarkup-estimator
- Free software: MIT License
- Documentation: https://PyMarkup-estimator.readthedocs.io
Key Features
-
Three Production Function Estimators: Compare results across multiple methods
- Wooldridge IV: IV/GMM with lagged COGS as instrument, rolling 5-year windows by industry (main method, addresses simultaneity bias)
- Cost Share: Direct accounting approach assuming perfect competition (quick benchmark)
- ACF: Ackerberg-Caves-Frazer two-stage GMM with productivity proxy (robustness check)
-
Flexible Configuration: YAML config files or programmatic Python API
-
Industry-Level Estimation: Rolling windows with configurable minimum observation thresholds
-
Clean Modular Architecture: Separation between core logic, estimators, pipeline orchestration, and I/O
-
Rich Output Options:
- Save to CSV, Parquet, or Stata formats
- Plot aggregate markup time series
- Compare methods with summary statistics
- Full type hints and validation with Pydantic
-
Command-Line Interface: Run complete pipeline with a single command
-
Intermediate Results: Optionally save panel data, elasticities, and markups at each step
Quick Start
Installation
pip install PyMarkup-estimator
Note: The package name is PyMarkup-estimator, but you import it as PyMarkup:
from PyMarkup import MarkupPipeline # Import name stays the same!
Python API
from PyMarkup import MarkupPipeline, PipelineConfig, EstimatorConfig
# Configure pipeline
config = PipelineConfig(
compustat_path="data/compustat.dta",
macro_vars_path="data/macro_vars.xlsx",
estimator=EstimatorConfig(
method="wooldridge_iv", # or "cost_share", "acf", "all"
iv_specification="spec2",
window_years=5
),
output_dir="output/"
)
# Run pipeline
pipeline = MarkupPipeline(config)
results = pipeline.run()
# Save and analyze results
results.save("output/", format="csv")
comparison = results.compare_methods()
fig = results.plot_aggregate()
Command Line
# Using config file
pymarkup estimate --config config.yaml
# Direct parameters
pymarkup estimate --method wooldridge_iv \
--compustat data/compustat.dta \
--macro-vars data/macro_vars.xlsx \
--output results/
How It Works
The MarkupPipeline orchestrates a 3-step workflow:
- Data Preparation: Load Compustat panel, merge macro variables, deflate to real terms, apply percentile trimming
- Elasticity Estimation: Estimate production function output elasticities (θ) by industry-year using selected method(s)
- Markup Calculation: Compute firm-level markups as
markup = θ_cogs / cost_share
Requirements
- Python 3.10+
- pandas, numpy, scipy
- linearmodels (for IV/2SLS estimation)
- statsmodels
- pydantic (for configuration validation)
- typer (for CLI)
Development
# Install with development dependencies
pip install -e ".[test]"
# Run tests
pytest
# Run quality checks
ruff check .
ruff format .
TODO
- Decomposition
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pymarkup_estimator-0.2.0.tar.gz.
File metadata
- Download URL: pymarkup_estimator-0.2.0.tar.gz
- Upload date:
- Size: 75.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
33d56ad41a3515e3cbfba18289586be81e87483d9d0f004be6b6844f02fbd2d8
|
|
| MD5 |
b60c73bd2622aac264f85a60158e23e5
|
|
| BLAKE2b-256 |
ada2782d460b88563eebeee28856270ce4dc4315d5806b34c84a6e82a8740c47
|
File details
Details for the file pymarkup_estimator-0.2.0-py3-none-any.whl.
File metadata
- Download URL: pymarkup_estimator-0.2.0-py3-none-any.whl
- Upload date:
- Size: 79.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ad3203fbb26a9b5fa82bb4f846f7cff546a32079b9359eb373f372b27cd54169
|
|
| MD5 |
e4222369b95cd9d2fbcf4a71fcfc0ef9
|
|
| BLAKE2b-256 |
f64ddcddc15f2ec9606e52e4cf4c6c2ec6e5fabf489bb21e9ed5a2ec713465ed
|