BipartiteDataFrame class

class bipartitepandas.bipartitedataframe.BipartiteDataFrame(i, j=None, j1=None, j2=None, y=None, y1=None, y2=None, t=None, t1=None, t2=None, t11=None, t12=None, t21=None, t22=None, g=None, g1=None, g2=None, w=None, w1=None, w2=None, m=None, custom_categorical_dict=None, custom_dtype_dict=None, custom_how_collapse_dict=None, custom_long_es_split_dict=None, **kwargs)

Bases: object

Constructor class for easily constructing BipartitePandas dataframes without explicitly specifying a format.

Parameters
  • SECTION – ANY FORMAT COLUMNS

  • i (NumPy Array or Pandas Series of any type or Pandas DataFrame) – if NumPy Array or Pandas Series: worker id (required); if Pandas DataFrame: full dataframe including all required columns

  • SECTION – BASE LONG FORMAT COLUMNS

  • j (NumPy Array or Pandas Series of any type) – firm id (required)

  • y (NumPy Array or Pandas Series of floats or ints) – income (required)

  • m (NumPy Array or Pandas Series of ints) – mover value (optional)

  • SECTION – NON-COLLAPSED LONG FORMAT COLUMNS

  • t (NumPy Array or Pandas Series of ints) – time (optional)

  • g (NumPy Array or Pandas Series of any type) – firm cluster (optional)

  • w (NumPy Array or Pandas Series of floats or ints) – observation weight (optional)

  • SECTION – COLLAPSED LONG FORMAT COLUMNS

  • t1 (NumPy Array or Pandas Series of ints) – first time in worker-firm spell (optional)

  • t2 (NumPy Array or Pandas Series of ints) – last time in worker-firm spell (optional)

  • SECTION – BASE EVENT STUDY FORMAT COLUMNS

  • j1 (NumPy Array or Pandas Series of any type) – firm id in first period of event study (required)

  • j2 (NumPy Array or Pandas Series of any type) – firm id in second period of event study (required)

  • y1 (NumPy Array or Pandas Series of floats or ints) – income in first period of event study (required)

  • y2 (NumPy Array or Pandas Series of floats or ints) – income in second period of event study (required)

  • g1 (NumPy Array or Pandas Series of any type) – firm cluster in first period of event study (optional)

  • g2 (NumPy Array or Pandas Series of any type) – firm cluster in second period of event study (optional)

  • w1 (NumPy Array or Pandas Series of floats or ints) – observation weight in first period of event study (optional)

  • w2 (NumPy Array or Pandas Series of floats or ints) – observation weight in second period of event study (optional)

  • SECTION – NON-COLLAPSED EVENT STUDY FORMAT COLUMNS

  • t1 – time in first period of event study (optional)

  • t2 – time in second period of event study (optional)

  • SECTION – COLLAPSED EVENT STUDY FORMAT COLUMNS

  • t11 (NumPy Array or Pandas Series of ints) – first time in worker-firm spell in first period of event study (optional)

  • t12 (NumPy Array or Pandas Series of ints) – last time in worker-firm spell in first period of event study (optional)

  • t21 (NumPy Array or Pandas Series of ints) – first time in worker-firm spell in second period of event study (optional)

  • t22 (NumPy Array or Pandas Series of ints) – last time in worker-firm spell in second period of event study (optional)

  • SECTION – CUSTOM COLUMNS

  • custom_categorical_dict (dict of bool or None) – for new columns, optionally link general column names to whether that set of columns is categorical (e.g. ‘j’ is firm ids, links to columns ‘j1’ and ‘j2’ and should be categorical; then set {‘j’: True}); None is equivalent to {}

  • custom_dtype_dict (dict of str or None) – for new columns, optionally link general column names to the datatype for that set of columns (e.g. ‘y’ is income, links to columns ‘y1’ and ‘y2’ and should be float; then set {‘y’: ‘float’}); must be one of ‘int’, ‘float’, ‘any’, or ‘categorical’; None is equivalent to {}

  • custom_how_collapse_dict (dict of (function or str or None) or None) – for new columns, optionally link general column names to how members of that set of columns should be collapsed at the worker-firm spell level (e.g. ‘y’ is income, links to columns ‘y1’ and ‘y2’ and should become the mean at the worker-firm spell level; then set {‘y’: ‘mean’}); must be a valid input for Pandas groupby; if None, column will be dropped during collapse/uncollapse; None is equivalent to {}

  • custom_long_es_split_dict (dict of (bool or None) or None) – for new columns, optionally link general column names to whether members of that set of columns should split into two when converting from long to event study; if None, columns will be dropped when converting between (collapsed) long and (collapsed) event study formats; None is equivalent to {}

  • **kwargs – keyword arguments for BipartiteBase, or new columns