diff --git a/docs/_quarto.yml b/docs/_quarto.yml index b2e48dcf7..b74ef48db 100644 --- a/docs/_quarto.yml +++ b/docs/_quarto.yml @@ -53,8 +53,12 @@ website: file: stata-2-pyfixest.qmd - text: "PyFixest on the GPU" file: pyfixest_gpu.ipynb + - text: "Other Resources around PyFixest" + file: resources.qmd - text: "Replicating 'The Effect' with PyFixest" file: replicating-the-effect.qmd + - text: "Replicating 'The Mixtape' with PyFixest" + file: mixtape.ipynb quartodoc: diff --git a/docs/difference-in-differences.qmd b/docs/difference-in-differences.qmd index 9b749e8ea..56fa3d0ac 100644 --- a/docs/difference-in-differences.qmd +++ b/docs/difference-in-differences.qmd @@ -186,7 +186,7 @@ fit_dynamic_twfe.iplot( figsize=[1200, 400], yintercept=0, xintercept=13.5, - labels=rename_event_study_coefs(fit_dynamic_twfe._coefnames), + cat_template="{variable}::{value}" ) ``` @@ -218,7 +218,7 @@ fit_dynamic_twfe.iplot( yintercept=0, xintercept=13.5, joint="both", - labels=rename_event_study_coefs(fit_dynamic_twfe._coefnames), + cat_template="{variable}::{value}" ) ``` @@ -348,7 +348,7 @@ fit_twfe.iplot( figsize=figsize, xintercept=18.5, yintercept=0, - labels=rename_event_study_coefs(fit_twfe._coefnames), # rename coefficients + cat_template="{variable}::{value}" ).show() ``` diff --git a/docs/mixtape.ipynb b/docs/mixtape.ipynb index abe6f43c9..209741fbd 100644 --- a/docs/mixtape.ipynb +++ b/docs/mixtape.ipynb @@ -20,7 +20,7 @@ "data": { "text/html": [ "\n", - "
\n", + "
\n", " \n", @@ -60,7 +60,7 @@ "data": { "text/html": [ "\n", - "
\n", + "
\n", " \n", @@ -98,8 +98,6 @@ } ], "source": [ - "import re\n", - "\n", "import numpy as np\n", "import pandas as pd\n", "\n", @@ -412,52 +410,52 @@ { "data": { "text/html": [ - "
\n", + "
\n", "\n", "\n", @@ -570,7 +568,7 @@ "4 1028 1028 \n", "5 by: id by: id \n", "6 0.302643 0.832214 \n", - "7 - 0.515959 , _body=, _boxhead=Boxhead([ColInfo(var='level_0', type=, column_label='level_0', column_align='center', column_width=None), ColInfo(var='level_1', type=, column_label='level_1', column_align='center', column_width=None), ColInfo(var='0', type=, column_label='(1)', column_align='center', column_width=None), ColInfo(var='1', type=, column_label='(2)', column_align='center', column_width=None)]), _stub=, _spanners=Spanners([SpannerInfo(spanner_id='lnw', spanner_level=2, spanner_label='lnw', spanner_units=None, spanner_pattern=None, vars=['0', '1'], built=None), SpannerInfo(spanner_id='POLS', spanner_level=1, spanner_label='POLS', spanner_units=None, spanner_pattern=None, vars=['0'], built=None), SpannerInfo(spanner_id='FE', spanner_level=1, spanner_label='FE', spanner_units=None, spanner_pattern=None, vars=['1'], built=None)]), _heading=Heading(title=None, subtitle=None, preheader=None), _stubhead=None, _source_notes=['Significance levels: * p < 0.05, ** p < 0.01, *** p < 0.001. Format of coefficient cell:\\nCoefficient \\n (Std. Error)'], _footnotes=[], _styles=[], _locale=, _formats=[], _substitutions=[], _options=Options(table_id=OptionsInfo(scss=False, category='table', type='value', value=None), table_caption=OptionsInfo(scss=False, category='table', type='value', value=None), table_width=OptionsInfo(scss=True, category='table', type='px', value='auto'), table_layout=OptionsInfo(scss=True, category='table', type='value', value='fixed'), table_margin_left=OptionsInfo(scss=True, category='table', type='px', value='auto'), table_margin_right=OptionsInfo(scss=True, category='table', type='px', value='auto'), table_background_color=OptionsInfo(scss=True, category='table', type='value', value='#FFFFFF'), table_additional_css=OptionsInfo(scss=False, category='table', type='values', value=[]), table_font_names=OptionsInfo(scss=False, category='table', type='values', value=['-apple-system', 'BlinkMacSystemFont', 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Helvetica Neue', 'Fira Sans', 'Droid Sans', 'Arial', 'sans-serif']), table_font_size=OptionsInfo(scss=True, category='table', type='px', value='16px'), table_font_weight=OptionsInfo(scss=True, category='table', type='value', value='normal'), table_font_style=OptionsInfo(scss=True, category='table', type='value', value='normal'), table_font_color=OptionsInfo(scss=True, category='table', type='value', value='#333333'), table_font_color_light=OptionsInfo(scss=True, category='table', type='value', value='#FFFFFF'), table_border_top_include=OptionsInfo(scss=False, category='table', type='boolean', value=True), table_border_top_style=OptionsInfo(scss=True, category='table', type='value', value='solid'), table_border_top_width=OptionsInfo(scss=True, category='table', type='px', value='2px'), table_border_top_color=OptionsInfo(scss=True, category='table', type='value', value='#A8A8A8'), table_border_right_style=OptionsInfo(scss=True, category='table', type='value', value='none'), table_border_right_width=OptionsInfo(scss=True, category='table', type='px', value='2px'), table_border_right_color=OptionsInfo(scss=True, category='table', type='value', value='#D3D3D3'), table_border_bottom_include=OptionsInfo(scss=False, category='table', type='boolean', value=True), table_border_bottom_style=OptionsInfo(scss=True, category='table', type='value', value='hidden'), table_border_bottom_width=OptionsInfo(scss=True, category='table', type='px', value='2px'), table_border_bottom_color=OptionsInfo(scss=True, category='table', type='value', value='#A8A8A8'), table_border_left_style=OptionsInfo(scss=True, category='table', type='value', value='none'), table_border_left_width=OptionsInfo(scss=True, category='table', type='px', value='2px'), table_border_left_color=OptionsInfo(scss=True, category='table', type='value', value='#D3D3D3'), heading_background_color=OptionsInfo(scss=True, category='heading', type='value', value=None), heading_align=OptionsInfo(scss=True, category='heading', type='value', value='center'), heading_title_font_size=OptionsInfo(scss=True, category='heading', type='px', value='125%'), heading_title_font_weight=OptionsInfo(scss=True, category='heading', type='value', value='initial'), heading_subtitle_font_size=OptionsInfo(scss=True, category='heading', type='px', value='85%'), heading_subtitle_font_weight=OptionsInfo(scss=True, category='heading', type='value', value='initial'), heading_padding=OptionsInfo(scss=True, category='heading', type='px', value='4px'), heading_padding_horizontal=OptionsInfo(scss=True, category='heading', type='px', value='5px'), heading_border_bottom_style=OptionsInfo(scss=True, category='heading', type='value', value='solid'), heading_border_bottom_width=OptionsInfo(scss=True, category='heading', type='px', value='2px'), heading_border_bottom_color=OptionsInfo(scss=True, category='heading', type='value', value='#D3D3D3'), heading_border_lr_style=OptionsInfo(scss=True, category='heading', type='value', value='none'), heading_border_lr_width=OptionsInfo(scss=True, category='heading', type='px', value='1px'), heading_border_lr_color=OptionsInfo(scss=True, category='heading', type='value', value='#D3D3D3'), column_labels_background_color=OptionsInfo(scss=True, category='column_labels', type='value', value=None), column_labels_font_size=OptionsInfo(scss=True, category='column_labels', type='px', value='100%'), column_labels_font_weight=OptionsInfo(scss=True, category='column_labels', type='value', value='normal'), column_labels_text_transform=OptionsInfo(scss=True, category='column_labels', type='value', value='inherit'), column_labels_padding=OptionsInfo(scss=True, category='column_labels', type='px', value='4px'), column_labels_padding_horizontal=OptionsInfo(scss=True, category='column_labels', type='px', value='5px'), column_labels_vlines_style=OptionsInfo(scss=True, category='table_body', type='value', value='none'), column_labels_vlines_width=OptionsInfo(scss=True, category='table_body', type='px', value='0px'), column_labels_vlines_color=OptionsInfo(scss=True, category='table_body', type='value', value='white'), column_labels_border_top_style=OptionsInfo(scss=True, category='column_labels', type='value', value='solid'), column_labels_border_top_width=OptionsInfo(scss=True, category='column_labels', type='px', value='2px'), column_labels_border_top_color=OptionsInfo(scss=True, category='column_labels', type='value', value='black'), column_labels_border_bottom_style=OptionsInfo(scss=True, category='column_labels', type='value', value='solid'), column_labels_border_bottom_width=OptionsInfo(scss=True, category='column_labels', type='px', value='0.5px'), column_labels_border_bottom_color=OptionsInfo(scss=True, category='column_labels', type='value', value='black'), column_labels_border_lr_style=OptionsInfo(scss=True, category='column_labels', type='value', value='none'), column_labels_border_lr_width=OptionsInfo(scss=True, category='column_labels', type='px', value='1px'), column_labels_border_lr_color=OptionsInfo(scss=True, category='column_labels', type='value', value='#D3D3D3'), column_labels_hidden=OptionsInfo(scss=False, category='column_labels', type='boolean', value=False), row_group_background_color=OptionsInfo(scss=True, category='row_group', type='value', value=None), row_group_font_size=OptionsInfo(scss=True, category='row_group', type='px', value='0px'), row_group_font_weight=OptionsInfo(scss=True, category='row_group', type='value', value='initial'), row_group_text_transform=OptionsInfo(scss=True, category='row_group', type='value', value='inherit'), row_group_padding=OptionsInfo(scss=True, category='row_group', type='px', value='0px'), row_group_padding_horizontal=OptionsInfo(scss=True, category='row_group', type='px', value='5px'), row_group_border_top_style=OptionsInfo(scss=True, category='row_group', type='value', value='solid'), row_group_border_top_width=OptionsInfo(scss=True, category='row_group', type='px', value='0.5px'), row_group_border_top_color=OptionsInfo(scss=True, category='row_group', type='value', value='black'), row_group_border_right_style=OptionsInfo(scss=True, category='row_group', type='value', value='none'), row_group_border_right_width=OptionsInfo(scss=True, category='row_group', type='px', value='1px'), row_group_border_right_color=OptionsInfo(scss=True, category='row_group', type='value', value='white'), row_group_border_bottom_style=OptionsInfo(scss=True, category='row_group', type='value', value='solid'), row_group_border_bottom_width=OptionsInfo(scss=True, category='row_group', type='px', value='0.5px'), row_group_border_bottom_color=OptionsInfo(scss=True, category='row_group', type='value', value='black'), row_group_border_left_style=OptionsInfo(scss=True, category='row_group', type='value', value='none'), row_group_border_left_width=OptionsInfo(scss=True, category='row_group', type='px', value='1px'), row_group_border_left_color=OptionsInfo(scss=True, category='row_group', type='value', value='white'), row_group_as_column=OptionsInfo(scss=False, category='row_group', type='boolean', value=False), table_body_hlines_style=OptionsInfo(scss=True, category='table_body', type='value', value='none'), table_body_hlines_width=OptionsInfo(scss=True, category='table_body', type='px', value='1px'), table_body_hlines_color=OptionsInfo(scss=True, category='table_body', type='value', value='#D3D3D3'), table_body_vlines_style=OptionsInfo(scss=True, category='table_body', type='value', value='none'), table_body_vlines_width=OptionsInfo(scss=True, category='table_body', type='px', value='0px'), table_body_vlines_color=OptionsInfo(scss=True, category='table_body', type='value', value='white'), table_body_border_top_style=OptionsInfo(scss=True, category='table_body', type='value', value='solid'), table_body_border_top_width=OptionsInfo(scss=True, category='table_body', type='px', value='0.5px'), table_body_border_top_color=OptionsInfo(scss=True, category='table_body', type='value', value='black'), table_body_border_bottom_style=OptionsInfo(scss=True, category='table_body', type='value', value='solid'), table_body_border_bottom_width=OptionsInfo(scss=True, category='table_body', type='px', value='2px'), table_body_border_bottom_color=OptionsInfo(scss=True, category='table_body', type='value', value='black'), data_row_padding=OptionsInfo(scss=True, category='data_row', type='px', value='4px'), data_row_padding_horizontal=OptionsInfo(scss=True, category='data_row', type='px', value='5px'), stub_background_color=OptionsInfo(scss=True, category='stub', type='value', value=None), stub_font_size=OptionsInfo(scss=True, category='stub', type='px', value='100%'), stub_font_weight=OptionsInfo(scss=True, category='stub', type='value', value='initial'), stub_text_transform=OptionsInfo(scss=True, category='stub', type='value', value='inherit'), stub_border_style=OptionsInfo(scss=True, category='stub', type='value', value='hidden'), stub_border_width=OptionsInfo(scss=True, category='stub', type='px', value='2px'), stub_border_color=OptionsInfo(scss=True, category='stub', type='value', value='#D3D3D3'), stub_row_group_background_color=OptionsInfo(scss=True, category='stub', type='value', value=None), stub_row_group_font_size=OptionsInfo(scss=True, category='stub', type='px', value='100%'), stub_row_group_font_weight=OptionsInfo(scss=True, category='stub', type='value', value='initial'), stub_row_group_text_transform=OptionsInfo(scss=True, category='stub', type='value', value='inherit'), stub_row_group_border_style=OptionsInfo(scss=True, category='stub', type='value', value='solid'), stub_row_group_border_width=OptionsInfo(scss=True, category='stub', type='px', value='2px'), stub_row_group_border_color=OptionsInfo(scss=True, category='stub', type='value', value='#D3D3D3'), source_notes_padding=OptionsInfo(scss=True, category='source_notes', type='px', value='4px'), source_notes_padding_horizontal=OptionsInfo(scss=True, category='source_notes', type='px', value='5px'), source_notes_background_color=OptionsInfo(scss=True, category='source_notes', type='value', value=None), source_notes_font_size=OptionsInfo(scss=True, category='source_notes', type='px', value='90%'), source_notes_border_bottom_style=OptionsInfo(scss=True, category='source_notes', type='value', value='none'), source_notes_border_bottom_width=OptionsInfo(scss=True, category='source_notes', type='px', value='2px'), source_notes_border_bottom_color=OptionsInfo(scss=True, category='source_notes', type='value', value='#D3D3D3'), source_notes_border_lr_style=OptionsInfo(scss=True, category='source_notes', type='value', value='none'), source_notes_border_lr_width=OptionsInfo(scss=True, category='source_notes', type='px', value='2px'), source_notes_border_lr_color=OptionsInfo(scss=True, category='source_notes', type='value', value='#D3D3D3'), source_notes_multiline=OptionsInfo(scss=False, category='source_notes', type='boolean', value=True), source_notes_sep=OptionsInfo(scss=False, category='source_notes', type='value', value=' '), row_striping_background_color=OptionsInfo(scss=True, category='row', type='value', value='rgba(128,128,128,0.05)'), row_striping_include_stub=OptionsInfo(scss=False, category='row', type='boolean', value=False), row_striping_include_table_body=OptionsInfo(scss=False, category='row', type='boolean', value=False), container_width=OptionsInfo(scss=False, category='container', type='px', value='auto'), container_height=OptionsInfo(scss=False, category='container', type='px', value='auto'), container_padding_x=OptionsInfo(scss=False, category='container', type='px', value='0px'), container_padding_y=OptionsInfo(scss=False, category='container', type='px', value='10px'), container_overflow_x=OptionsInfo(scss=False, category='container', type='overflow', value='auto'), container_overflow_y=OptionsInfo(scss=False, category='container', type='overflow', value='auto'), quarto_disable_processing=OptionsInfo(scss=False, category='quarto', type='logical', value=False), quarto_use_bootstrap=OptionsInfo(scss=False, category='quarto', type='logical', value=False)), _has_built=False)" + "7 - 0.515959 , _body=, _boxhead=Boxhead([ColInfo(var='level_0', type=, column_label='level_0', column_align='center', column_width=None), ColInfo(var='level_1', type=, column_label='level_1', column_align='center', column_width=None), ColInfo(var='0', type=, column_label='(1)', column_align='center', column_width=None), ColInfo(var='1', type=, column_label='(2)', column_align='center', column_width=None)]), _stub=, _spanners=Spanners([SpannerInfo(spanner_id='lnw', spanner_level=2, spanner_label='lnw', spanner_units=None, spanner_pattern=None, vars=['0', '1'], built=None), SpannerInfo(spanner_id='POLS', spanner_level=1, spanner_label='POLS', spanner_units=None, spanner_pattern=None, vars=['0'], built=None), SpannerInfo(spanner_id='FE', spanner_level=1, spanner_label='FE', spanner_units=None, spanner_pattern=None, vars=['1'], built=None)]), _heading=Heading(title=None, subtitle=None, preheader=None), _stubhead=None, _source_notes=['Significance levels: * p < 0.05, ** p < 0.01, *** p < 0.001. Format of coefficient cell:\\nCoefficient \\n (Std. Error)'], _footnotes=[], _styles=[], _locale=, _formats=[], _substitutions=[], _options=Options(table_id=OptionsInfo(scss=False, category='table', type='value', value=None), table_caption=OptionsInfo(scss=False, category='table', type='value', value=None), table_width=OptionsInfo(scss=True, category='table', type='px', value='auto'), table_layout=OptionsInfo(scss=True, category='table', type='value', value='fixed'), table_margin_left=OptionsInfo(scss=True, category='table', type='px', value='auto'), table_margin_right=OptionsInfo(scss=True, category='table', type='px', value='auto'), table_background_color=OptionsInfo(scss=True, category='table', type='value', value='#FFFFFF'), table_additional_css=OptionsInfo(scss=False, category='table', type='values', value=[]), table_font_names=OptionsInfo(scss=False, category='table', type='values', value=['-apple-system', 'BlinkMacSystemFont', 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Helvetica Neue', 'Fira Sans', 'Droid Sans', 'Arial', 'sans-serif']), table_font_size=OptionsInfo(scss=True, category='table', type='px', value='16px'), table_font_weight=OptionsInfo(scss=True, category='table', type='value', value='normal'), table_font_style=OptionsInfo(scss=True, category='table', type='value', value='normal'), table_font_color=OptionsInfo(scss=True, category='table', type='value', value='#333333'), table_font_color_light=OptionsInfo(scss=True, category='table', type='value', value='#FFFFFF'), table_border_top_include=OptionsInfo(scss=False, category='table', type='boolean', value=True), table_border_top_style=OptionsInfo(scss=True, category='table', type='value', value='solid'), table_border_top_width=OptionsInfo(scss=True, category='table', type='px', value='2px'), table_border_top_color=OptionsInfo(scss=True, category='table', type='value', value='#A8A8A8'), table_border_right_style=OptionsInfo(scss=True, category='table', type='value', value='none'), table_border_right_width=OptionsInfo(scss=True, category='table', type='px', value='2px'), table_border_right_color=OptionsInfo(scss=True, category='table', type='value', value='#D3D3D3'), table_border_bottom_include=OptionsInfo(scss=False, category='table', type='boolean', value=True), table_border_bottom_style=OptionsInfo(scss=True, category='table', type='value', value='hidden'), table_border_bottom_width=OptionsInfo(scss=True, category='table', type='px', value='2px'), table_border_bottom_color=OptionsInfo(scss=True, category='table', type='value', value='#A8A8A8'), table_border_left_style=OptionsInfo(scss=True, category='table', type='value', value='none'), table_border_left_width=OptionsInfo(scss=True, category='table', type='px', value='2px'), table_border_left_color=OptionsInfo(scss=True, category='table', type='value', value='#D3D3D3'), heading_background_color=OptionsInfo(scss=True, category='heading', type='value', value=None), heading_align=OptionsInfo(scss=True, category='heading', type='value', value='center'), heading_title_font_size=OptionsInfo(scss=True, category='heading', type='px', value='125%'), heading_title_font_weight=OptionsInfo(scss=True, category='heading', type='value', value='initial'), heading_subtitle_font_size=OptionsInfo(scss=True, category='heading', type='px', value='85%'), heading_subtitle_font_weight=OptionsInfo(scss=True, category='heading', type='value', value='initial'), heading_padding=OptionsInfo(scss=True, category='heading', type='px', value='4px'), heading_padding_horizontal=OptionsInfo(scss=True, category='heading', type='px', value='5px'), heading_border_bottom_style=OptionsInfo(scss=True, category='heading', type='value', value='solid'), heading_border_bottom_width=OptionsInfo(scss=True, category='heading', type='px', value='2px'), heading_border_bottom_color=OptionsInfo(scss=True, category='heading', type='value', value='#D3D3D3'), heading_border_lr_style=OptionsInfo(scss=True, category='heading', type='value', value='none'), heading_border_lr_width=OptionsInfo(scss=True, category='heading', type='px', value='1px'), heading_border_lr_color=OptionsInfo(scss=True, category='heading', type='value', value='#D3D3D3'), column_labels_background_color=OptionsInfo(scss=True, category='column_labels', type='value', value=None), column_labels_font_size=OptionsInfo(scss=True, category='column_labels', type='px', value='100%'), column_labels_font_weight=OptionsInfo(scss=True, category='column_labels', type='value', value='normal'), column_labels_text_transform=OptionsInfo(scss=True, category='column_labels', type='value', value='inherit'), column_labels_padding=OptionsInfo(scss=True, category='column_labels', type='px', value='4px'), column_labels_padding_horizontal=OptionsInfo(scss=True, category='column_labels', type='px', value='5px'), column_labels_vlines_style=OptionsInfo(scss=True, category='table_body', type='value', value='none'), column_labels_vlines_width=OptionsInfo(scss=True, category='table_body', type='px', value='0px'), column_labels_vlines_color=OptionsInfo(scss=True, category='table_body', type='value', value='white'), column_labels_border_top_style=OptionsInfo(scss=True, category='column_labels', type='value', value='solid'), column_labels_border_top_width=OptionsInfo(scss=True, category='column_labels', type='px', value='2px'), column_labels_border_top_color=OptionsInfo(scss=True, category='column_labels', type='value', value='black'), column_labels_border_bottom_style=OptionsInfo(scss=True, category='column_labels', type='value', value='solid'), column_labels_border_bottom_width=OptionsInfo(scss=True, category='column_labels', type='px', value='0.5px'), column_labels_border_bottom_color=OptionsInfo(scss=True, category='column_labels', type='value', value='black'), column_labels_border_lr_style=OptionsInfo(scss=True, category='column_labels', type='value', value='none'), column_labels_border_lr_width=OptionsInfo(scss=True, category='column_labels', type='px', value='1px'), column_labels_border_lr_color=OptionsInfo(scss=True, category='column_labels', type='value', value='#D3D3D3'), column_labels_hidden=OptionsInfo(scss=False, category='column_labels', type='boolean', value=False), row_group_background_color=OptionsInfo(scss=True, category='row_group', type='value', value=None), row_group_font_size=OptionsInfo(scss=True, category='row_group', type='px', value='0px'), row_group_font_weight=OptionsInfo(scss=True, category='row_group', type='value', value='initial'), row_group_text_transform=OptionsInfo(scss=True, category='row_group', type='value', value='inherit'), row_group_padding=OptionsInfo(scss=True, category='row_group', type='px', value='0px'), row_group_padding_horizontal=OptionsInfo(scss=True, category='row_group', type='px', value='5px'), row_group_border_top_style=OptionsInfo(scss=True, category='row_group', type='value', value='solid'), row_group_border_top_width=OptionsInfo(scss=True, category='row_group', type='px', value='0.5px'), row_group_border_top_color=OptionsInfo(scss=True, category='row_group', type='value', value='black'), row_group_border_right_style=OptionsInfo(scss=True, category='row_group', type='value', value='none'), row_group_border_right_width=OptionsInfo(scss=True, category='row_group', type='px', value='1px'), row_group_border_right_color=OptionsInfo(scss=True, category='row_group', type='value', value='white'), row_group_border_bottom_style=OptionsInfo(scss=True, category='row_group', type='value', value='solid'), row_group_border_bottom_width=OptionsInfo(scss=True, category='row_group', type='px', value='0.5px'), row_group_border_bottom_color=OptionsInfo(scss=True, category='row_group', type='value', value='black'), row_group_border_left_style=OptionsInfo(scss=True, category='row_group', type='value', value='none'), row_group_border_left_width=OptionsInfo(scss=True, category='row_group', type='px', value='1px'), row_group_border_left_color=OptionsInfo(scss=True, category='row_group', type='value', value='white'), row_group_as_column=OptionsInfo(scss=False, category='row_group', type='boolean', value=False), table_body_hlines_style=OptionsInfo(scss=True, category='table_body', type='value', value='none'), table_body_hlines_width=OptionsInfo(scss=True, category='table_body', type='px', value='1px'), table_body_hlines_color=OptionsInfo(scss=True, category='table_body', type='value', value='#D3D3D3'), table_body_vlines_style=OptionsInfo(scss=True, category='table_body', type='value', value='none'), table_body_vlines_width=OptionsInfo(scss=True, category='table_body', type='px', value='0px'), table_body_vlines_color=OptionsInfo(scss=True, category='table_body', type='value', value='white'), table_body_border_top_style=OptionsInfo(scss=True, category='table_body', type='value', value='solid'), table_body_border_top_width=OptionsInfo(scss=True, category='table_body', type='px', value='0.5px'), table_body_border_top_color=OptionsInfo(scss=True, category='table_body', type='value', value='black'), table_body_border_bottom_style=OptionsInfo(scss=True, category='table_body', type='value', value='solid'), table_body_border_bottom_width=OptionsInfo(scss=True, category='table_body', type='px', value='2px'), table_body_border_bottom_color=OptionsInfo(scss=True, category='table_body', type='value', value='black'), data_row_padding=OptionsInfo(scss=True, category='data_row', type='px', value='4px'), data_row_padding_horizontal=OptionsInfo(scss=True, category='data_row', type='px', value='5px'), stub_background_color=OptionsInfo(scss=True, category='stub', type='value', value=None), stub_font_size=OptionsInfo(scss=True, category='stub', type='px', value='100%'), stub_font_weight=OptionsInfo(scss=True, category='stub', type='value', value='initial'), stub_text_transform=OptionsInfo(scss=True, category='stub', type='value', value='inherit'), stub_border_style=OptionsInfo(scss=True, category='stub', type='value', value='hidden'), stub_border_width=OptionsInfo(scss=True, category='stub', type='px', value='2px'), stub_border_color=OptionsInfo(scss=True, category='stub', type='value', value='#D3D3D3'), stub_row_group_background_color=OptionsInfo(scss=True, category='stub', type='value', value=None), stub_row_group_font_size=OptionsInfo(scss=True, category='stub', type='px', value='100%'), stub_row_group_font_weight=OptionsInfo(scss=True, category='stub', type='value', value='initial'), stub_row_group_text_transform=OptionsInfo(scss=True, category='stub', type='value', value='inherit'), stub_row_group_border_style=OptionsInfo(scss=True, category='stub', type='value', value='solid'), stub_row_group_border_width=OptionsInfo(scss=True, category='stub', type='px', value='2px'), stub_row_group_border_color=OptionsInfo(scss=True, category='stub', type='value', value='#D3D3D3'), source_notes_padding=OptionsInfo(scss=True, category='source_notes', type='px', value='4px'), source_notes_padding_horizontal=OptionsInfo(scss=True, category='source_notes', type='px', value='5px'), source_notes_background_color=OptionsInfo(scss=True, category='source_notes', type='value', value=None), source_notes_font_size=OptionsInfo(scss=True, category='source_notes', type='px', value='90%'), source_notes_border_bottom_style=OptionsInfo(scss=True, category='source_notes', type='value', value='none'), source_notes_border_bottom_width=OptionsInfo(scss=True, category='source_notes', type='px', value='2px'), source_notes_border_bottom_color=OptionsInfo(scss=True, category='source_notes', type='value', value='#D3D3D3'), source_notes_border_lr_style=OptionsInfo(scss=True, category='source_notes', type='value', value='none'), source_notes_border_lr_width=OptionsInfo(scss=True, category='source_notes', type='px', value='2px'), source_notes_border_lr_color=OptionsInfo(scss=True, category='source_notes', type='value', value='#D3D3D3'), source_notes_multiline=OptionsInfo(scss=False, category='source_notes', type='boolean', value=True), source_notes_sep=OptionsInfo(scss=False, category='source_notes', type='value', value=' '), row_striping_background_color=OptionsInfo(scss=True, category='row', type='value', value='rgba(128,128,128,0.05)'), row_striping_include_stub=OptionsInfo(scss=False, category='row', type='boolean', value=False), row_striping_include_table_body=OptionsInfo(scss=False, category='row', type='boolean', value=False), container_width=OptionsInfo(scss=False, category='container', type='px', value='auto'), container_height=OptionsInfo(scss=False, category='container', type='px', value='auto'), container_padding_x=OptionsInfo(scss=False, category='container', type='px', value='0px'), container_padding_y=OptionsInfo(scss=False, category='container', type='px', value='10px'), container_overflow_x=OptionsInfo(scss=False, category='container', type='overflow', value='auto'), container_overflow_y=OptionsInfo(scss=False, category='container', type='overflow', value='auto'), quarto_disable_processing=OptionsInfo(scss=False, category='quarto', type='logical', value=False), quarto_use_bootstrap=OptionsInfo(scss=False, category='quarto', type='logical', value=False)), _has_built=False)" ] }, "execution_count": 6, @@ -672,7 +670,7 @@ " \n", " \n", " \n", - " \n", + " \n", " \n", " \n", " \n", @@ -696,7 +694,7 @@ " \n", " \n", " \n", - " \n", + " \n", " \n", " \n", " \n", @@ -720,7 +718,7 @@ " \n", " \n", " \n", - " \n", + " \n", " \n", " \n", " \n", @@ -744,7 +742,7 @@ " \n", " \n", " \n", - " \n", + " \n", " \n", " \n", " \n", @@ -768,7 +766,7 @@ " \n", " \n", " \n", - " \n", + " \n", " \n", " \n", " \n", @@ -793,12 +791,12 @@ "" ], "text/plain": [ - " fip age race year sex totcase totpop rate totrate \\\n", - "19 1.0 15.0 2.0 1985.0 2 5683.0 106187 6527.500000 5351.899902 \n", - "39 1.0 15.0 2.0 1986.0 2 5344.0 106831 6351.200195 5002.299805 \n", - "71 1.0 15.0 2.0 1987.0 2 4983.0 106496 5759.100098 4679.000000 \n", - "89 1.0 15.0 2.0 1988.0 2 5276.0 105238 6139.600098 5013.399902 \n", - "106 1.0 15.0 2.0 1989.0 2 5692.0 102956 5951.500000 5528.600098 \n", + " fip age race year sex totcase totpop rate totrate \\\n", + "19 1.0 15.0 2.0 1985 2 5683.0 106187 6527.500000 5351.899902 \n", + "39 1.0 15.0 2.0 1986 2 5344.0 106831 6351.200195 5002.299805 \n", + "71 1.0 15.0 2.0 1987 2 4983.0 106496 5759.100098 4679.000000 \n", + "89 1.0 15.0 2.0 1988 2 5276.0 105238 6139.600098 5013.399902 \n", + "106 1.0 15.0 2.0 1989 2 5692.0 102956 5951.500000 5528.600098 \n", "\n", " id ... female lnr t younger fa pi wm15 wf15 bm15 \\\n", "19 14.0 ... 1.0 8.783779 1.0 1.0 1.0 0.0 0.0 0.0 0.0 \n", @@ -830,35 +828,13 @@ "abortion_bf15 = abortion[abortion.bf15 == 1]\n", "# pf throws error when weights are 0\n", "abortion_bf15 = abortion_bf15[abortion_bf15.totpop > 0]\n", + "abortion_bf15[\"year\"] = abortion_bf15[\"year\"].astype(int)\n", "abortion_bf15.head()" ] }, { "cell_type": "code", - "execution_count": 11, - "id": "8b880c1d", - "metadata": {}, - "outputs": [], - "source": [ - "def _extract_bracket_numbers(str_list) -> dict:\n", - " \"Extract time from event study coefficients and store in dict.\"\n", - " out = {}\n", - " pattern = re.compile(r\"\\[(\\d+\\.?\\d*)\\]\") # capture numbers inside []\n", - "\n", - " for s in str_list:\n", - " match = pattern.search(str(s)) # convert np.str_ -> str\n", - " if match:\n", - " num_str = match.group(1)\n", - " # Convert to int if it's whole, else keep as string\n", - " if num_str.endswith(\".0\"):\n", - " num_str = str(int(float(num_str)))\n", - " out[s] = num_str\n", - " return out" - ] - }, - { - "cell_type": "code", - "execution_count": 12, + "execution_count": 9, "id": "913e912c", "metadata": {}, "outputs": [ @@ -880,7 +856,7 @@ "
" ] }, - "execution_count": 12, + "execution_count": 9, "metadata": { "image/png": { "height": 588, @@ -905,7 +881,7 @@ " coord_flip=False,\n", " plot_backend=\"matplotlib\",\n", " title=\"Event Study Estimate\",\n", - " labels=_extract_bracket_numbers(fit._coefnames),\n", + " cat_template=\"{value}\",\n", ")" ] }, @@ -916,6 +892,14 @@ "metadata": {}, "outputs": [], "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e1120d82", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { diff --git a/docs/resources.qmd b/docs/resources.qmd new file mode 100644 index 000000000..56865f372 --- /dev/null +++ b/docs/resources.qmd @@ -0,0 +1,37 @@ +--- +title: Learning Econometrics with PyFixest +format: + html: + html-table-processing: none +toc: true +toc-title: "On this page" +toc-location: left +--- + +A few classes and textbooks have adopted PyFixest for teaching. And for core textbooks in causal inference that have not (yet =) ) , we have (or are planning to) write PyFixest translations (there are also multiple current "good first issues" for this if you'd like to help us). + +## Textbooks + +- Data Analysis for Business, Economics, and Policy ("Gabor's Data Analysis"). [Data and code](https://gabors-data-analysis.com/data-and-code/) and [Jupyter Notebooks on github](https://github.com/gabors-data-analysis/da_case_studies) +- Coding for Economists: [Regression](https://aeturrell.github.io/coding-for-economists/econmt-regression.html) +- Tidy Finance comes with a [chapter on fixed effects](https://www.tidy-finance.org/python/fixed-effects-and-clustered-standard-errors.html) and clustered standard errors and [Differene-in-Differences estimation](https://www.tidy-finance.org/python/difference-in-differences.html) that uses pyfixest +- The Effect (first edition): [our PyFixest translation](https://py-econometrics.github.io/pyfixest/replicating-the-effect.html) +- The Panel Data Chapter in [the Mixtape](https://mixtape.scunning.com/08-panel_data#data-exercise-survey-of-adult-service-providers). You can find a PyFixest translation [here](https://py-econometrics.github.io/pyfixest/replicating-the-mixtape.html) + +Textbooks / textbook chapters that we still want to cover: + +- The Difference-in-Differences chapter in the Mixtape ([github issue here](https://github.com/py-econometrics/pyfixest/issues/998)) +- All of the Python translation of Ding's textbook on causal inference ([github issue here](https://github.com/py-econometrics/pyfixest/issues/957)) +- The "Brave and True" chapters on [Dummy Regression](https://matheusfacure.github.io/python-causality-handbook/06-Grouped-and-Dummy-Regression.html), [Instrumental Variables](https://matheusfacure.github.io/python-causality-handbook/08-Instrumental-Variables.html), [Difference-in-Differences](https://matheusfacure.github.io/python-causality-handbook/13-Difference-in-Differences.html) and [Panel Data and Fixed Effects](https://matheusfacure.github.io/python-causality-handbook/14-Panel-Data-and-Fixed-Effects.html). + +## Classes + +If you are teaching with pyfixest, we'd love to hear from you! + +- Econometrics II (taught by Vladislav Morozov at UBonn): Great intro to fixed effects estimation theory. Slides on fixed effects [here](https://vladislav-morozov.github.io/econometrics-2/slides/panel/fe.html#/title-slide), full class notes [here](https://vladislav-morozov.github.io/econometrics-2/), [github repository](https://github.com/vladislav-morozov/econometrics-2) + +## Blog Posts, Notebooks, Videos + +If you've written a blog post that illustrates how to use pyfixest, please let us know, we'd love to link to it. + +- PyData Berlin Presentation (2024) on PyFixest: [link](https://www.youtube.com/watch?v=kSQxGGA7Rr4) diff --git a/pyfixest/report/utils.py b/pyfixest/report/utils.py index 80f7260b2..ee91e228e 100644 --- a/pyfixest/report/utils.py +++ b/pyfixest/report/utils.py @@ -35,7 +35,7 @@ def _relabel_expvar( str The relabeled variable """ - if labels == {} and cat_template != "" and ("C(" in varname or "[" in varname): + if not labels and cat_template != "" and ("C(" in varname or "[" in varname): v = _rename_categorical(varname, template=cat_template, labels=labels) else: v = labels.get(varname, varname) @@ -166,4 +166,9 @@ def rename_event_study_coefs(coef_names_list: list): 'Intercept': 'Intercept' } """ + # add a deprecation warning + warnings.warn( + "rename_event_study_coefs is deprecated and will be removed in a future version. Please use the cat_template argument instead." + ) + return {col: _rename_event_study_coefs(col) for col in coef_names_list} diff --git a/pyfixest/report/visualize.py b/pyfixest/report/visualize.py index 150a59ae5..cd4fbf43e 100644 --- a/pyfixest/report/visualize.py +++ b/pyfixest/report/visualize.py @@ -94,6 +94,7 @@ def iplot( exact_match: bool = False, plot_backend: str = "lets_plot" if _HAS_LETS_PLOT else "matplotlib", labels: Optional[dict] = None, + cat_template: Optional[str] = None, rename_models: Optional[dict[str, str]] = None, ax: Optional[plt.Axes] = None, joint: Optional[Union[str, bool]] = None, @@ -148,6 +149,11 @@ def iplot( A dictionary to relabel the variables. The keys in this dictionary are the original variable names, which correspond to the names stored in the `_coefnames` attribute of the model. The values in the dictionary are the new names you want to assign to these variables. Note that interaction terms will also be relabeled using the labels of the individual variables. The renaming is applied after the selection of the coefficients via `keep` and `drop`. + cat_template: str, optional + Template to relabel categorical variables. None by default, which applies no relabeling. + Other options include combinations of "{variable}" and "{value}", e.g. "{variable}::{value}" + to mimic fixest encoding. But "{variable}--{value}" or "{variable}{value}" or just "{value}" + are also possible. joint: str or bool, optional Whether to plot simultaneous confidence bands for the coefficients. If True, simultaneous confidence bands are plotted. If False, "standard" confidence intervals are plotted. If "both", both are plotted in @@ -259,6 +265,7 @@ def iplot( title=title, flip_coord=coord_flip, labels=labels, + cat_template=cat_template, ax=ax, ) @@ -514,6 +521,7 @@ def _coefplot_lets_plot( title: Optional[str] = None, flip_coord: Optional[bool] = True, labels: Optional[dict] = None, + cat_template: Optional[str] = None, ax=None, # for compatibility with matplotlib backend ): """ @@ -539,6 +547,11 @@ def _coefplot_lets_plot( Whether to flip the coordinates of the plot. Default is True. labels : dict, optional A dictionary to relabel the variables. The keys are the original variable names and the values the new names. + cat_template : str, optional + Template to relabel categorical variables. None by default, which applies no relabeling. + Other options include combinations of "{variable}" and "{value}", e.g. "{variable}::{value}" + to mimic fixest encoding. But "{variable}--{value}" or "{variable}{value}" or just "{value}" + are also possible. ax : None, optional Not used. Only for compatibility with the matplotlib backend. @@ -551,10 +564,17 @@ def _coefplot_lets_plot( df.rename(columns={"fml": "Model"}, inplace=True) ub, lb = 1 - alpha / 2, alpha / 2 - if labels is not None: - interactionSymbol = " x " + labels_dict = {} if labels is None else labels + + if not labels_dict or cat_template is not None: + interactionSymbol = ":" df["Coefficient"] = df["Coefficient"].apply( - lambda x: _relabel_expvar(x, labels, interactionSymbol) + lambda x: _relabel_expvar( + x, + labels_dict, + interactionSymbol, + cat_template if cat_template is not None else "", + ) ) plot = ( @@ -594,6 +614,7 @@ def _coefplot_matplotlib( title: Optional[str] = None, flip_coord: Optional[bool] = True, labels: Optional[dict] = None, + cat_template: Optional[str] = None, ax: Optional[plt.Axes] = None, dodge: float = 0.5, **fig_kwargs, @@ -622,6 +643,11 @@ def _coefplot_matplotlib( Whether to flip the coordinates of the plot. Default is True. labels : dict, optional A dictionary to relabel the variables. The keys are the original variable names and the values the new names. + cat_template : str, optional + Template to relabel categorical variables. None by default, which applies no relabeling. + Other options include combinations of "{variable}" and "{value}", e.g. "{variable}::{value}" + to mimic fixest encoding. But "{variable}--{value}" or "{variable}{value}" or just "{value}" + are also possible. dodge : float, optional The amount to dodge each model's points by. Default is 0.1. fig_kwargs : dict @@ -632,10 +658,17 @@ def _coefplot_matplotlib( matplotlib.figure.Figure A matplotlib Figure object. """ - if labels is not None: + labels_dict = {} if labels is None else labels + + if not labels_dict or cat_template is not None: interactionSymbol = ":" df["Coefficient"] = df["Coefficient"].apply( - lambda x: _relabel_expvar(x, labels, interactionSymbol) + lambda x: _relabel_expvar( + x, + labels_dict, + interactionSymbol, + cat_template if cat_template is not None else "", + ) ) ub, lb = (f"{round(x * 100, 1)}%" for x in [1 - alpha / 2, alpha / 2])
1.015.02.01985.0198525683.01061871.015.02.01986.0198625344.01068311.015.02.01987.0198724983.01064961.015.02.01988.0198825276.01052381.015.02.01989.0198925692.0102956