Python API
Overview
The main PyTwoWay API is split into multiple classes for estimating models and two for simulating data according to the BLM and Borovickova-Shimer dgps. It also has four modules: one for constructing the variance-covariance matrix for AKM and its bias corrections; one for generating constraints for BLM; one for generating attrition plots using increasing (building up from a fixed set of firms) or decreasing (with varying sets of firms) fractions of movers; and one for generating diagnostics for bipartite labor data. PyTwoWay is canonically imported using
import pytwoway as tw
Classes
pytwoway.FEEstimator
: Class for estimating AKM and its bias corrections without controlspytwoway.FEControlEstimator
: Class for estimating AKM and its bias corrections with controlspytwoway.CREEstimator
: Class for estimating the CRE modelpytwoway.BLMModel
: Class for estimating the BLM model with one set of starting valuespytwoway.BLMEstimator
: Class for estimating the BLM model with multiple sets of starting valuespytwoway.BLMBootstrap
: Class for estimating the BLM model with bootstrapped confidence intervalspytwoway.BLMVarianceDecomposition
: Class for estimating the variance decomposition of the BLM model with bootstrapped confidence intervalspytwoway.InteractedBLMModel
: Class for estimating the interacted BLM modelpytwoway.SorkinEstimator
: Class for estimating the fixed-point revealed preference model from Sorkinpytwoway.BSEstimator
: Class for estimating the non-parametric sorting model from Borovickova and Shimerpytwoway.Attrition
: Class for generating attrition plotspytwoway.MonteCarlo
: Class for running Monte Carlo estimationspytwoway.SimBLM
: Class for simulating BLM datapytwoway.SimBS
: Class for simulating Borovickova-Shimer data
Modules
pytwoway.Q
: Module for constructing the variance-covariance matrix for AKM and its bias correctionspytwoway.constraints
: Module for generating constraints for BLMpytwoway.attrition_utils
: Module for estimating attrition using increasing (building up from a fixed set of firms) or decreasing (with varying sets of firms) fractions of moverspytwoway.diagnostics
: Module for generating diagnostics for bipartite labor data
Classes and Methods
pytwoway.FEEstimator
|
Uses multigrid and partialing out to solve two way fixed effect models. |
|
Estimate FE model. |
pytwoway.FEControlEstimator
|
Solve two way fixed effect models with control variables. |
|
Estimate FE model. |
pytwoway.CREEstimator
|
Uses multigrid and partialing out to solve two way Fixed Effect model. |
|
Run CRE solver. |
pytwoway.BLMModel
|
Class for estimating BLM using a single set of starting values. |
|
Computes graph connectedness measure among the movers within each type and updates self.connectedness to be the smallest value. |
|
EM algorithm for movers. |
|
Run fit_movers(), first constrained, then using results as starting values, run unconstrained. |
|
EM algorithm for stayers. |
|
Plot log-earnings by worker-firm type pairs. |
|
Plot proportions of worker types at each firm class. |
pytwoway.BLMEstimator
|
Class for estimating BLM using multiple sets of starting values. |
|
Estimate BLM using multiple sets of starting values. |
|
Plot likelihoods vs connectedness for the estimations run. |
|
Plot log-earnings by worker-firm type pairs. |
|
Plot proportions of worker types at each firm class. |
pytwoway.BLMBootstrap
|
Class for estimating BLM using bootstrapping. |
|
Estimate bootstrap. |
|
Plot log-earnings by worker-firm type pairs. |
|
Plot proportions of worker types at each firm class. |
pytwoway.BLMVarianceDecomposition
|
Class for estimating BLM variance decomposition using bootstrapping. |
|
Estimate variance decomposition. |
pytwoway.InteractedBLMModel
pytwoway.SorkinEstimator
|
Class for estimating the fixed-point revealed preference model from Sorkin (2018). |
|
Estimate the fixed-point revealed preference model from Sorkin (2018). |
pytwoway.BSEstimator
|
Class for estimating the non-parametric sorting model from Borovickova and Shimer. |
|
Estimate the non-parametric sorting model from Borovickova and Shimer. |
pytwoway.Attrition
|
Class of Attrition, which generates attrition plots using bipartite labor data. |
|
Run Monte Carlo on attrition estimations of TwoWay to estimate variance of parameter estimates given fraction of movers remaining. |
|
Generate attrition result boxplots. |
|
Generate attrition result plots. |
pytwoway.MonteCarlo
|
Class of MonteCarlo, where MonteCarlo runs a Monte Carlo estimation by simulating bipartite networks of firms and workers. |
|
Plot histogram of how Monte Carlo simulation results differ from truth. |
|
Run Monte Carlo simulations of two way fixed effect models to see the distribution of the true vs. |
pytwoway.SimBLM
|
Class of SimBLM, where SimBLM simulates a bipartite BLM network of firms and workers. |
|
Simulate data (movers and stayers). |
pytwoway.SimBS
|
Class of SimBS, where SimBS simulates a bipartite Borovickova-Shimer network of firms and workers. |
|
Simulate data. |
Modules and Methods
pytwoway.Q
|
Generate Q to estimate cov(covariate 1, covariate 2). |
|
Generate Q to estimate cov(psi, alpha). |
|
Generate Q to estimate cov(psi_t, psi_{t+1}). |
|
Generate Q to estimate var(alpha). |
|
Generate Q to estimate var(covariate) or var(sum(covariates)) if multiple covariates are listed. |
|
Generate Q to estimate var(psi). |
|
Generate Q to estimate var(psi + alpha). |
pytwoway.constraints
|
Generate BLM constraints so that worker-firm pair effects are bounded above. |
|
Generate BLM constraints so that worker-firm pair effects are bounded below. |
|
Generate BLM constraints so that for a fixed firm type, worker types effects must change linearly. |
|
Generate BLM constraints so that for a fixed firm type, worker types effects must increase (or decrease) monotonically. |
|
Generate BLM constraints so that for a fixed firm type, worker types effects must all be the same. |
|
Solve a quadratic programming model of the following form: |
|
Generate BLM constraints so that worker-firm pair effects are the same in all periods. |
|
Generate BLM constraints so that the firm type induced variation of worker-firm pair effects is the same in all periods. |
pytwoway.attrition_utils
|
Generate increasing subsets of a dataset to estimate the effects of attrition. |
|
Generate decreasing subsets of a dataset to estimate the effects of attrition. |
pytwoway.diagnostics
|
Generate event study plots. |