-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Layout improvements for etable, in particular for LaTex output (#583)
* Added feature to relabel variables in etable * Added explanation of relabeling feature * update etable docstring for order of keep, drop, label, felabels * add API tests * test only felabels * Regression table layout improvements; latex table layout; custom model headers & custom table notes * update stargazer nb on with new features * small cleanups * PR allows newline in tex * update readme * add tests * small update * bring back Dirk's notebook changes * bring back Dirks nb * delete fls changes * Small layout changes for type="df" * Option to print latex string in etable * Set default of print_tex to False (Reason: A user who includes the tables in a separate latex file or in overleaf will likely not want to see the printed code in the notebook. Moreover, for quarto rendering it must apparently be printed in any case in the end of the code block. When print_tex=True then the rendered document will also show the latex code block in addition to the table). * Edited the Stargazer notebook to document latex output and the use in quarto * Few edits in documentation * Corrected mistake I made in earlier commit * Display YAML code for quarto example as plain text * Update YAML code for quarto example as plain text * As the inclusion of the quarto example in the Stargazer notebook caused some issues, I have taken this out of the notebook and instead refer to an added qmd file that gives as an eample for including tables in quarto. * do not run, only format python code in quarto example * install tinytex in github action * add API test for print_tex argument * Allow to hide fixed effects and se-type rows. Allow to add custom model information/further model statistics. * Explain the new features in the Stargazer notebook * Update documentation * fix small typos --------- Co-authored-by: Alexander Fischer <alexander-fischer1801@t-online.de>
- Loading branch information
Showing
13 changed files
with
2,694 additions
and
830 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
\documentclass{article}% | ||
\usepackage[T1]{fontenc}% | ||
\usepackage[utf8]{inputenc}% | ||
\usepackage{lmodern}% | ||
\usepackage{textcomp}% | ||
\usepackage{lastpage}% | ||
\usepackage{booktabs}% | ||
\usepackage{threeparttable}% | ||
\usepackage{makecell}% | ||
% | ||
% | ||
% | ||
\begin{document}% | ||
\normalsize% | ||
\section{A PyFixest LateX Table}% | ||
\label{sec:APyFixestLateXTable}% | ||
|
||
|
||
\begin{table}[htbp]% | ||
\renewcommand\cellalign{t} | ||
\begin{threeparttable} | ||
\begin{tabular}{lcccccc} | ||
\toprule | ||
& \multicolumn{3}{c}{Y} & \multicolumn{3}{c}{Y2} \\ | ||
\cmidrule(lr){2-4} \cmidrule(lr){5-7} | ||
& (1) & (2) & (3) & (4) & (5) & (6) \\ | ||
\midrule | ||
X1 & \makecell{-0.95*** \\ (0.07)} & \makecell{-0.92*** \\ (0.06)} & \makecell{-0.92*** \\ (0.06)} & \makecell{-1.27*** \\ (0.17)} & \makecell{-1.23*** \\ (0.19)} & \makecell{-1.23*** \\ (0.19)} \\ | ||
X2 & \makecell{-0.17*** \\ (0.02)} & \makecell{-0.17*** \\ (0.01)} & \makecell{-0.19*** \\ (0.03)} & \makecell{-0.13*** \\ (0.04)} & \makecell{-0.12*** \\ (0.04)} & \makecell{-0.07 \\ (0.10)} \\ | ||
X1:X2 & & & \makecell{0.01 \\ (0.02)} & & & \makecell{-0.04 \\ (0.08)} \\ | ||
\midrule | ||
f1 & x & x & x & x & x & x \\ | ||
f2 & - & x & x & - & x & x \\ | ||
\midrule | ||
$R^2$ & 0.49 & 0.66 & 0.66 & 0.12 & 0.17 & 0.17 \\ | ||
S.E. type & by: f1 & by: f1 & by: f1 & by: f1 & by: f1 & by: f1 \\ | ||
Observations & 997 & 997 & 997 & 998 & 998 & 998 \\ | ||
\bottomrule | ||
\end{tabular} | ||
\footnotesize Significance levels: $*$ p $<$ 0.1, $**$ p $<$ 0.05, $***$ p $<$ 0.01. Format of coefficient cell: Coefficient | ||
(Std. Error) | ||
\end{threeparttable}% | ||
\end{table} | ||
|
||
% | ||
\end{document} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
\documentclass{article}% | ||
\usepackage[T1]{fontenc}% | ||
\usepackage[utf8]{inputenc}% | ||
\usepackage{lmodern}% | ||
\usepackage{textcomp}% | ||
\usepackage{lastpage}% | ||
\usepackage{booktabs}% | ||
\usepackage{threeparttable}% | ||
\usepackage{makecell}% | ||
% | ||
% | ||
% | ||
\begin{document}% | ||
\normalsize% | ||
\section{A PyFixest LateX Table}% | ||
\label{sec:APyFixestLateXTable}% | ||
|
||
|
||
\begin{table}[htbp]% | ||
\renewcommand\cellalign{t} | ||
\begin{threeparttable} | ||
\begin{tabular}{lcccccc} | ||
\toprule | ||
& \multicolumn{2}{c}{US} & \multicolumn{2}{c}{China} & \multicolumn{2}{c}{EU} \\ | ||
\cmidrule(lr){2-3} \cmidrule(lr){4-5} \cmidrule(lr){6-7} | ||
& Wage & Wealth & Wage & Wealth & Wage & Wealth \\ | ||
& (1) & (2) & (3) & (4) & (5) & (6) \\ | ||
\midrule | ||
Age & \makecell{-0.950*** \\ (0.067)} & \makecell{-1.267*** \\ (0.174)} & \makecell{-0.924*** \\ (0.061)} & \makecell{-1.232*** \\ (0.192)} & \makecell{-0.924*** \\ (0.061)} & \makecell{-1.231*** \\ (0.192)} \\ | ||
Years of Schooling & \makecell{-0.174*** \\ (0.018)} & \makecell{-0.131** \\ (0.042)} & \makecell{-0.174*** \\ (0.015)} & \makecell{-0.118** \\ (0.042)} & \makecell{-0.185*** \\ (0.025)} & \makecell{-0.074 \\ (0.104)} \\ | ||
Age $\times$ Years of Schooling & & & & & \makecell{0.011 \\ (0.018)} & \makecell{-0.041 \\ (0.081)} \\ | ||
\midrule | ||
Industry & x & x & x & x & x & x \\ | ||
Year & - & - & x & x & x & x \\ | ||
\midrule | ||
$R^2$ & 0.489 & 0.120 & 0.659 & 0.172 & 0.659 & 0.172 \\ | ||
S.E. type & by: f1 & by: f1 & by: f1 & by: f1 & by: f1 & by: f1 \\ | ||
Observations & 997 & 998 & 997 & 998 & 997 & 998 \\ | ||
\bottomrule | ||
\end{tabular} | ||
\footnotesize Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. | ||
\end{threeparttable}% | ||
\end{table} | ||
|
||
% | ||
\end{document} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
--- | ||
title: "Quarto and PyFixest" | ||
jupyter: python3 | ||
format: | ||
pdf: | ||
number-sections: true | ||
include-in-header: | ||
- text: | | ||
\usepackage{booktabs} | ||
\usepackage{makecell} | ||
\usepackage{threeparttable} | ||
execute: | ||
echo: false | ||
warning: false | ||
author: | ||
- Peter Pan^[University of Neverland] | ||
date: last-modified | ||
abstract: | | ||
\ | ||
\ | ||
We study the effect of X1 and X2 on Y and Y2 using PyFixest. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. | ||
\ | ||
\ | ||
**Keywords**: Regressions, PyFixest, Tables, Quarto | ||
--- | ||
|
||
{{< pagebreak >}} | ||
|
||
# Introduction | ||
|
||
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet." | ||
|
||
```{python} | ||
#| echo: false | ||
#| output: false | ||
import pandas as pd | ||
import pyfixest as pf | ||
data = pf.get_data() | ||
fit1 = pf.feols("Y ~ X1 + X2 | f1", data = data) | ||
fit2 = pf.feols("Y ~ X1 + X2 | f1 + f2", data = data) | ||
fit3 = pf.feols("Y ~ X1 *X2 | f1 + f2", data = data) | ||
fit4 = pf.feols("Y2 ~ X1 + X2 | f1", data = data) | ||
fit5 = pf.feols("Y2 ~ X1 + X2 | f1 + f2", data = data) | ||
fit6 = pf.feols("Y2 ~ X1 *X2 | f1 + f2", data = data) | ||
labels={ | ||
"Y": "Wage", | ||
"Y2": "Wealth", | ||
"X1": "Age", | ||
"X2": "Years of Schooling", | ||
"f1": "Industry", | ||
"f2": "Year" | ||
} | ||
``` | ||
|
||
# A PyFixest Regression Table | ||
As @tbl-main shows, LaTex Tables generated by PyFixest can be easily integrated into Quarto document when rendered as pdf. | ||
|
||
```{python} | ||
#| label: tbl-main | ||
#| tbl-cap: A PyFixest Regression Table | ||
#| output: asis | ||
#| echo: false | ||
#| tbl-pos: H | ||
mynotes="Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet." | ||
tab=pf.etable([fit1, fit2, fit4, fit5], | ||
labels=labels, notes=mynotes, type="tex", | ||
model_heads=["US", "China", "US", "China"]) | ||
print(tab) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"---\n", | ||
"title: \"Quarto and PyFixest\"\n", | ||
"jupyter: python3\n", | ||
"format:\n", | ||
" pdf:\n", | ||
" number-sections: true\n", | ||
" include-in-header:\n", | ||
" - text: |\n", | ||
" \\usepackage{booktabs}\n", | ||
" \\usepackage{makecell}\n", | ||
" \\usepackage{threeparttable}\n", | ||
"execute:\n", | ||
" echo: false\n", | ||
" warning: false\n", | ||
"author:\n", | ||
"- Peter Pan^[University of Neverland]\n", | ||
"date: last-modified\n", | ||
"abstract: |\n", | ||
" \\\n", | ||
" \\\n", | ||
" We study the effect of X1 and X2 on Y and Y2 using PyFixest. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.\n", | ||
" \\\n", | ||
" \\\n", | ||
" **Keywords**: Regressions, PyFixest, Tables, Quarto\n", | ||
"---\n", | ||
"\n", | ||
"{{< pagebreak >}}\n", | ||
"\n", | ||
"\n", | ||
"# Introduction\n", | ||
"\n", | ||
"Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.\"\n" | ||
], | ||
"id": "78e2a9c8" | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"metadata": {}, | ||
"source": [ | ||
"#| echo: false\n", | ||
"#| output: false\n", | ||
"import pandas as pd\n", | ||
"import pyfixest as pf\n", | ||
"\n", | ||
"data = pf.get_data()\n", | ||
"\n", | ||
"fit1 = pf.feols(\"Y ~ X1 + X2 | f1\", data = data)\n", | ||
"fit2 = pf.feols(\"Y ~ X1 + X2 | f1 + f2\", data = data)\n", | ||
"fit3 = pf.feols(\"Y ~ X1 *X2 | f1 + f2\", data = data)\n", | ||
"fit4 = pf.feols(\"Y2 ~ X1 + X2 | f1\", data = data)\n", | ||
"fit5 = pf.feols(\"Y2 ~ X1 + X2 | f1 + f2\", data = data)\n", | ||
"fit6 = pf.feols(\"Y2 ~ X1 *X2 | f1 + f2\", data = data)\n", | ||
"\n", | ||
"labels={\n", | ||
" \"Y\": \"Wage\",\n", | ||
" \"Y2\": \"Wealth\",\n", | ||
" \"X1\": \"Age\",\n", | ||
" \"X2\": \"Years of Schooling\",\n", | ||
" \"f1\": \"Industry\",\n", | ||
" \"f2\": \"Year\"\n", | ||
"}" | ||
], | ||
"id": "c444d358", | ||
"execution_count": null, | ||
"outputs": [] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# A PyFixest Regression Table\n", | ||
"As @tbl-main shows, LaTex Tables generated by PyFixest can be easily integrated into Quarto document when rendered as pdf.\n" | ||
], | ||
"id": "4fc14b82" | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"metadata": { | ||
"tbl-pos": "H" | ||
}, | ||
"source": [ | ||
"#| label: tbl-main\n", | ||
"#| tbl-cap: A PyFixest Regression Table\n", | ||
"#| output: asis\n", | ||
"#| echo: false\n", | ||
"\n", | ||
"mynotes=\"Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.\"\n", | ||
"\n", | ||
"tab=pf.etable([fit1, fit2, fit4, fit5],\n", | ||
" labels=labels, notes=mynotes, type=\"tex\",\n", | ||
" model_heads=[\"US\", \"China\", \"US\", \"China\"])\n", | ||
"\n", | ||
"print(tab)" | ||
], | ||
"id": "tbl-main", | ||
"execution_count": null, | ||
"outputs": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"name": "python3", | ||
"language": "python", | ||
"display_name": "Python 3 (ipykernel)", | ||
"path": "C:\\Users\\dirks\\AppData\\Roaming\\Python\\share\\jupyter\\kernels\\python3" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
Oops, something went wrong.