PyTwoWay
PyTwoWay is the Python package associated with the following paper:
“How Much Should we Trust Estimates of Firm Effects and Worker Sorting?” by Stéphane Bonhomme, Kerstin Holzheu, Thibaut Lamadon, Elena Manresa, Magne Mogstad, and Bradley Setzler. No. w27368. National Bureau of Economic Research, 2020.
The package provides implementations for a series of estimators for models with two sided heterogeneity:
two way fixed effect estimator as proposed by Abowd, Kramarz, and Margolis
homoskedastic bias correction as in Andrews, et al.
heteroskedastic bias correction as in Kline, Saggio, and Sølvsten
group fixed estimator as in Bonhomme, Lamadon, and Manresa
group correlated random effect as presented in the main paper
If you want to give it a try, you can start an example notebook for the FE estimator here: for the CRE estimator here:
and for the BLM estimator here:
. These start fully interactive notebooks with simple examples that simulate data and run the estimators.
The code is relatively efficient. Solving large sparse linear models relies on PyAMG. This is the code we use to estimate the different decompositions on US data. Data cleaning is handled by BipartitePandas.
The package provides a Python interface. Installation is handled by pip or Conda (TBD). The source of the package is available on GitHub at PyTwoWay. The online documentation is hosted here.
Quick Start
To install via pip, from the command line run:
pip install pytwoway
Citation
Please use following citation to cite PyTwoWay in academic publications:
Bibtex entry:
@techreport{bhlmms2020,
title={How Much Should We Trust Estimates of Firm Effects and Worker Sorting?},
author={Bonhomme, St{\'e}phane and Holzheu, Kerstin and Lamadon, Thibaut and Manresa, Elena and Mogstad, Magne and Setzler, Bradley},
year={2020},
institution={National Bureau of Economic Research}
}
Development
If you want to contribute to the package, the easiest way is to use poetry to set up a local environment:
poetry install
poetry run python -m pytest
To push the package to PiP, increase the version number in the pyproject.toml file and then:
poetry build
poetry publish
Finally to build the package for conda and upload it:
conda skeleton pypi pytwoway
conda config --set anaconda_upload yes
conda-build pytwoway -c tlamadon --output-folder pytwoway
User documentation
Notebook examples
- FE
- CRE
- BLM
- Import the PyTwoWay package
- First, check out parameter options
- Second, set parameter choices
- Extract data (we simulate for the example)
- Prepare data
- Separate observed and unobserved data
- Separate movers and stayers data
- Check the data
- Initialize and run BLMEstimator
- Check that log-likelihoods are monotonic
- Now we can investigate the results
- Finally, we can compare estimates to the truth
- Bootstrapped errors
- Now we can investigate the results
- Control variables
- Simulating data with controls
- Check out simulation parameter options
- Set simulation parameter choices
- Estimating control variables
- Check out estimation parameter options
- Set estimation parameter choices
- Simulate data
- Initialize and run BLMEstimator
- Check that log-likelihoods are monotonic
- Now we can investigate the results
- Finally, we can compare estimates to the truth
- Attrition
- Monte Carlo