MonteCarlo class

class pytwoway.montecarlo.MonteCarlo(sim_params=None, fe_params=None, cre_params=None, estimate_bs=False, cluster_params=None, clean_params=None, collapse=None, move_to_worker=False, log=False)

Bases: object

Class of MonteCarlo, where MonteCarlo runs a Monte Carlo estimation by simulating bipartite networks of firms and workers.

Parameters
  • sim_params (ParamsDict or None) – dictionary of parameters for simulating data. Run bpd.sim_params().describe_all() for descriptions of all valid parameters. None is equivalent to bpd.sim_params().

  • fe_params (ParamsDict or None) – dictionary of parameters for FE estimation. Run tw.fe_params().describe_all() for descriptions of all valid parameters. None is equivalent to tw.fe_params().

  • cre_params (ParamsDict or None) – dictionary of parameters for CRE estimation. Run tw.cre_params().describe_all() for descriptions of all valid parameters. None is equivalent to tw.cre_params().

  • estimate_bs (bool) – if True, estimate Borovickova-Shimer model

  • cluster_params (ParamsDict or None) – dictionary of parameters for clustering in CRE estimation. Run bpd.cluster_params().describe_all() for descriptions of all valid parameters. None is equivalent to bpd.cluster_params().

  • clean_params (ParamsDict or None) – dictionary of parameters for cleaning. Run bpd.clean_params().describe_all() for descriptions of all valid parameters. None is equivalent to bpd.clean_params().

  • collapse (str or None) – if None, run estimators on full dataset; if ‘spell’, run estimators on data collapsed at the worker-firm spell level; if ‘spell’, run estimators on data collapsed at the worker-firm match level

  • move_to_worker (bool) – if True, each move is treated as a new worker

  • log (bool) – if True, will create log file(s)

hist(fe=True, ho=True, he=True, cre=True, bs1=True, bs2=True, density=False)

Plot histogram of how Monte Carlo simulation results differ from truth.

Parameters
  • fe (bool) – if True, plot FE results

  • ho (bool) – if True, plot FE-HO results

  • he (bool) – if True, plot FE-HE results

  • cre (bool) – if True, plot CRE results

  • bs1 (bool) – if True, plot Borovickova-Shimer results for the standard estimator

  • bs2 (bool) – if True, plot Borovickova-Shimer results for the alternative estimator

  • density (bool) – if True, plot density; if False, plot count

monte_carlo(N=10, ncore=1, rng=None)

Run Monte Carlo simulations of two way fixed effect models to see the distribution of the true vs. estimated variance of psi and covariance between psi and alpha. Saves the following results in the dictionary self.res: true, plug-in FE, FE-HO, FE-HE, CRE, and Borovickova-Shimer estimates for var(psi) and cov(psi, alpha), where psi gives firm effects and alpha gives worker effects.

Parameters
  • N (int) – number of simulations

  • ncore (int) – number of cores to use

  • rng (np.random.Generator or None) – NumPy random number generator. This overrides the random number generators for simulating, FE, and CRE. None is equivalent to np.random.default_rng(None).