<jupyter_start><jupyter_text>Card-Heining-Kline event study examples<jupyter_code># Add BipartitePandas to system path, do not run this
# import sys
# sys.path.append('../../..')
# Import the BipartitePandas package 
# (Make sure you have installed it using pip install bipartitepandas)
import bipartitepandas as bpd
# For the example, we simulate bipartite labor data
sim_data = bpd.SimBipartite().sim_network()
bdf = bpd.BipartiteLong(sim_data)
bdf = bdf.clean_data()
display(bdf)<jupyter_output><empty_output><jupyter_text>Creating CHK event study plot<jupyter_code># We need to cluster the data first (using quartiles of mean firm-level income)
measures = bpd.measures.moments(measures='mean')
grouping = bpd.grouping.quantiles(n_quantiles=4)
bdf = bdf.cluster(measures=measures, grouping=grouping)
# Now to make the plots
bdf.plot_es_extended(periods_pre=2, periods_post=2)
# Be careful not to include too many clusters!
measures = bpd.measures.moments(measures='mean')
grouping = bpd.grouping.quantiles(n_quantiles=7)
bdf = bdf.cluster(measures=measures, grouping=grouping)
bdf.plot_es_extended(periods_pre=2, periods_post=2)<jupyter_output><empty_output><jupyter_text>Getting extended event study dataframes<jupyter_code># BipartitePandas allows you to use clustered long data to generate event studies with more than 2 periods
# So first, cluster the data
bdf = bdf.cluster()
es_extended = bdf.get_es_extended(periods_pre=3, periods_post=2) # periods_post includes the first period after the transition
display(es_extended)
# You can specify which columns to include (by default they are g and y)
es_extended = bdf.get_es_extended(periods_pre=3, periods_post=2, include=['j', 'y'])
display(es_extended)
# You can specify column(s) for stable_pre or stable_post to keep only workers with those columns constant before/after the transition
es_extended = bdf.get_es_extended(periods_pre=3, periods_post=2, stable_pre='j', stable_post='j', include=['j', 'y'])
display(es_extended)
# You can specify column(s) for stable_pre or stable_post that aren't included
es_extended = bdf.get_es_extended(periods_pre=3, periods_post=2, stable_pre='g', stable_post='g', include=['j', 'y'])
display(es_extended)
# You can also redefine what column to use to define a transition
es_extended = bdf.get_es_extended(periods_pre=3, periods_post=2, stable_pre='g', stable_post='j', include=['j', 'g', 'y'], transition_col='g')
display(es_extended)
display(es_extended[es_extended['j_l3'] != es_extended['j_l2']])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10922041946972695, 'fraction_numerical': 0.007518796992481203, 'mean_word_length': 7.6279863481228665, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '416531', 'license': 'MIT', 'n_tokens_mistral': 888, 'n_tokens_neox': 839, 'n_words': 227, 'path': 'docs/source/notebooks/chk_examples.ipynb', 'repo_name': 'adamoppenheimer/bipartitepandas', 'size': '2527'}