Skip to content

Commit d6edae8

Browse files
author
Christian Zimpelmann
committed
add simple two step procedure.
1 parent 4a3e42c commit d6edae8

File tree

6 files changed

+85
-60
lines changed

6 files changed

+85
-60
lines changed

.github/workflows/main.yml

Lines changed: 0 additions & 47 deletions
This file was deleted.

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
# Reproducible Research Template
1+
# Estimagic Tables Examples
22

3-
[![image](https://img.shields.io/github/actions/workflow/status/ariannaw.rosenbluth/estimagic_tables_examples/main.yml?branch=main)](https://github.com/ariannaw.rosenbluth/estimagic_tables_examples/actions?query=branch%3Amain) [![image](https://codecov.io/gh/ariannaw.rosenbluth/estimagic_tables_examples/branch/main/graph/badge.svg)](https://codecov.io/gh/ariannaw.rosenbluth/estimagic_tables_examples)
3+
[![image](https://img.shields.io/github/actions/workflow/status/OpenSourceEconomics/estimagic_tables_examples/main.yml?branch=main)](https://github.com/OpenSourceEconomics/estimagic_tables_examples/actions?query=branch%3Amain)
4+
[![image](https://codecov.io/gh/OpenSourceEconomics/estimagic_tables_examples/branch/main/graph/badge.svg)](https://codecov.io/gh/OpenSourceEconomics/estimagic_tables_examples)
45

5-
[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/ariannaw.rosenbluth/estimagic_tables_examples/main.svg)](https://results.pre-commit.ci/latest/github/ariannaw.rosenbluth/estimagic_tables_examples/main)
6+
[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/OpenSourceEconomics/estimagic_tables_examples/main.svg)](https://results.pre-commit.ci/latest/github/OpenSourceEconomics/estimagic_tables_examples/main)
67
[![image](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
78

9+
This repository collects a set of example tables produced by
10+
`estimagic.estimation_table`
11+
812
## Usage
913

1014
To get started, create and activate the environment with

paper/estimagic_tables_examples.tex

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,10 @@
8585
\input{../bld/tables/statsmodels_basic.tex}
8686
\end{table}
8787

88-
88+
\begin{table}[!h]
89+
\caption{Simple statsmodels two-step results}
90+
\input{../bld/tables/statsmodels_simple_two_step.tex}
91+
\end{table}
8992

9093

9194

setup.cfg

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = estimagic_tables_examples
33
description = Reproducible Research Template
44
long_description = file: README.md
55
long_description_content_type = text/markdown
6-
url = https://github.com/ariannaw.rosenbluth/estimagic_tables_examples
6+
url = https://github.com/OpenSourceEconomics/estimagic_tables_examples
77
author = Christian Zimpelmann
88
author_email = zimpelmann.christian@gmail.com
99
license = MIT
@@ -18,10 +18,10 @@ classifiers =
1818
Programming Language :: Python :: 3
1919
Programming Language :: Python :: 3 :: Only
2020
project_urls =
21-
Changelog = https://github.com/ariannaw.rosenbluth/estimagic_tables_examples
22-
Documentation = https://github.com/ariannaw.rosenbluth/estimagic_tables_examples
23-
Github = https://github.com/ariannaw.rosenbluth/estimagic_tables_examples
24-
Tracker = https://github.com/ariannaw.rosenbluth/estimagic_tables_examples/issues
21+
Changelog = https://github.com/OpenSourceEconomics/estimagic_tables_examples
22+
Documentation = https://github.com/OpenSourceEconomics/estimagic_tables_examples
23+
Github = https://github.com/OpenSourceEconomics/estimagic_tables_examples
24+
Tracker = https://github.com/OpenSourceEconomics/estimagic_tables_examples/issues
2525

2626
[options]
2727
packages = find:

src/estimagic_tables_examples/create_tables/task_simple_statsmodels_table.py renamed to src/estimagic_tables_examples/create_tables/task_simple_statsmodels.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
"""Tasks running the results formatting (tables, figures)."""
22

3+
import estimagic as em
34
import pandas as pd
45
import pytask
5-
import estimagic as em
6+
import statsmodels.formula.api as sm
67

78
from estimagic_tables_examples.config import BLD, IN_DATA
8-
import statsmodels.formula.api as sm
99

1010
PARAMETRIZATION = {}
1111
for return_type, file_ending in [("latex", "tex"), ("html", "html")]:
@@ -26,11 +26,19 @@ def task_simple_statsmodels_table_latex(
2626
produces=kwargs["produces"],
2727
return_type=kwargs["return_type"],
2828
):
29-
"""Simple statsmodels table. The example is taken from the documentation."""
29+
"""Simple statsmodels table.
30+
31+
The example is taken from the documentation.
32+
33+
"""
3034
df = pd.read_csv(depends_on, index_col=0)
3135
mod1 = sm.ols("target ~ Age + Sex", data=df).fit()
3236
mod2 = sm.ols("target ~ Age + Sex + BMI + ABP", data=df).fit()
3337
models = [mod1, mod2]
34-
table = em.estimation_table(models, return_type=return_type)
38+
table = em.estimation_table(
39+
models,
40+
return_type=return_type,
41+
siunitx_warning=False,
42+
)
3543
with open(produces, "w") as f:
3644
f.writelines(table)
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
"""Tasks running the results formatting (tables, figures)."""
2+
3+
import estimagic as em
4+
import pandas as pd
5+
import pytask
6+
import statsmodels.formula.api as sm
7+
8+
from estimagic_tables_examples.config import BLD, IN_DATA
9+
10+
PARAMETRIZATION = {}
11+
for return_type, file_ending in [("latex", "tex"), ("html", "html")]:
12+
depends_on = IN_DATA / "diabetes.csv"
13+
produces = BLD / "tables" / f"statsmodels_simple_two_step.{file_ending}"
14+
PARAMETRIZATION[return_type] = {
15+
"depends_on": depends_on,
16+
"produces": produces,
17+
"return_type": return_type,
18+
}
19+
20+
21+
for task_id, kwargs in PARAMETRIZATION.items():
22+
23+
@pytask.mark.task(id=task_id)
24+
def task_two_step_statsmodels_table_latex(
25+
depends_on=kwargs["depends_on"],
26+
produces=kwargs["produces"],
27+
return_type=kwargs["return_type"],
28+
):
29+
"""Simple Statsmodels table using two step procedure."""
30+
df = pd.read_csv(depends_on, index_col=0)
31+
mod1 = sm.ols("target ~ Age + Sex", data=df).fit()
32+
mod2 = sm.ols("target ~ Age + Sex + BMI + ABP", data=df).fit()
33+
models = [mod1, mod2]
34+
render_inputs = em.estimation_table(models, return_type="render_inputs")
35+
36+
# Remove rows from footer.
37+
render_inputs["footer"] = render_inputs["footer"].loc[["R$^2$", "Observations"]]
38+
39+
# Remove rows from body.
40+
render_inputs["body"] = pd.concat(
41+
[render_inputs["body"].iloc[:6], render_inputs["body"].iloc[-2:]],
42+
)
43+
44+
# Add a row to the footer.
45+
render_inputs["footer"].loc[("Control for BMI",)] = ["Yes"] + ["No"]
46+
47+
if return_type == "html":
48+
out = em.render_html(render_inputs["body"], render_inputs["footer"])
49+
elif return_type == "latex":
50+
out = em.render_latex(
51+
render_inputs["body"],
52+
render_inputs["footer"],
53+
siunitx_warning=False,
54+
)
55+
56+
with open(produces, "w") as f:
57+
f.writelines(out)

0 commit comments

Comments
 (0)