Skip to main content

A Python toolkit for estimating firm-level markups using production function-based marginal cost recovery.

Project description

PyMarkup-estimator

PyPI version Documentation Status Tests Python 3.10+

A Python toolkit for estimating firm-level markups using production function-based marginal cost recovery.

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:

  1. Data Preparation: Load Compustat panel, merge macro variables, deflate to real terms, apply percentile trimming
  2. Elasticity Estimation: Estimate production function output elasticities (θ) by industry-year using selected method(s)
  3. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pymarkup_estimator-0.2.1.tar.gz (75.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pymarkup_estimator-0.2.1-py3-none-any.whl (79.1 kB view details)

Uploaded Python 3

File details

Details for the file pymarkup_estimator-0.2.1.tar.gz.

File metadata

  • Download URL: pymarkup_estimator-0.2.1.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

Hashes for pymarkup_estimator-0.2.1.tar.gz
Algorithm Hash digest
SHA256 7fea7479f6d9d40e5f803c30af91778695d7806fd8593c26d11d4b1b7ca46bde
MD5 269675a4770af622364c6afed9551620
BLAKE2b-256 096565bcd2d8011b502bfd6955622cf382b1ef0a7a2740f21b6207c7f9b06a65

See more details on using hashes here.

File details

Details for the file pymarkup_estimator-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for pymarkup_estimator-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a03d936775be528f8bf7cd18a361b86f7af141d0ca2c3f6b0eb9a6399c76f36c
MD5 32d7fcdb043023c264e09d2263ed3d49
BLAKE2b-256 6bab82c8d4cf4c2c872fc3b218b8cdced4f5a08274fc62e8b6c7304be60ae10b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page