Skip to content

Commit

Permalink
Merge pull request #168 from jmboehm/add-extra_space-option
Browse files Browse the repository at this point in the history
Add extra_space option for extra space between coefficient lines
  • Loading branch information
junder873 authored Oct 31, 2024
2 parents 1f0b3dd + 34dbc46 commit 5cbbfcb
Show file tree
Hide file tree
Showing 3 changed files with 172 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "RegressionTables"
uuid = "d519eb52-b820-54da-95a6-98e1306fdade"
authors = ["Johannes Boehm <[email protected]>"]
version = "0.7.7"
version = "0.7.8"

[deps]
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
Expand Down
147 changes: 147 additions & 0 deletions docs/src/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -972,6 +972,153 @@ Adj. R2 0.007 0.860 0.861 0.622
----------------------------------------------------------------------
```

## Adding an extra row between coefficients

Using the `extra_space` option allows for a default more like the Stargazer R package. This option adds an extra row after the below statistic and before the next coefficient (or simply between coefficients if there is no below statistic or the below statistic is on the same line as the coefficient).

```jldoctest
regtable(rr1,rr2,rr3,rr4; extra_space = true)
# output
----------------------------------------------------------------------
SepalLength SepalWidth
------------------------------ ----------
(1) (2) (3) (4)
----------------------------------------------------------------------
(Intercept) 6.526***
(0.479)
SepalWidth -0.223 0.432*** 0.516***
(0.155) (0.081) (0.104)
PetalLength 0.776*** 0.723*** -0.188*
(0.064) (0.129) (0.083)
PetalWidth -0.625 0.626***
(0.354) (0.123)
PetalLength & PetalWidth 0.066
(0.067)
SepalLength 0.378***
(0.066)
----------------------------------------------------------------------
Species Fixed Effects Yes Yes Yes
isSmall Fixed Effects Yes
----------------------------------------------------------------------
N 150 150 150 150
R2 0.014 0.863 0.868 0.635
Within-R2 0.642 0.598 0.391
----------------------------------------------------------------------
```

```jldoctest
regtable(rr1,rr2,rr3,rr4; below_statistic = nothing, extra_space=true)
# output
----------------------------------------------------------------------
SepalLength SepalWidth
------------------------------ ----------
(1) (2) (3) (4)
----------------------------------------------------------------------
(Intercept) 6.526***
SepalWidth -0.223 0.432*** 0.516***
PetalLength 0.776*** 0.723*** -0.188*
PetalWidth -0.625 0.626***
PetalLength & PetalWidth 0.066
SepalLength 0.378***
----------------------------------------------------------------------
Species Fixed Effects Yes Yes Yes
isSmall Fixed Effects Yes
----------------------------------------------------------------------
N 150 150 150 150
R2 0.014 0.863 0.868 0.635
Within-R2 0.642 0.598 0.391
----------------------------------------------------------------------
```

```jldoctest
regtable(rr1,rr2,rr3,rr4; stat_below=false, extra_space=true)
# output
----------------------------------------------------------------------------------------------------
SepalLength SepalWidth
------------------------------------------------------ ----------------
(1) (2) (3) (4)
----------------------------------------------------------------------------------------------------
(Intercept) 6.526*** (0.479)
SepalWidth -0.223 (0.155) 0.432*** (0.081) 0.516*** (0.104)
PetalLength 0.776*** (0.064) 0.723*** (0.129) -0.188* (0.083)
PetalWidth -0.625 (0.354) 0.626*** (0.123)
PetalLength & PetalWidth 0.066 (0.067)
SepalLength 0.378*** (0.066)
----------------------------------------------------------------------------------------------------
Species Fixed Effects Yes Yes Yes
isSmall Fixed Effects Yes
----------------------------------------------------------------------------------------------------
N 150 150 150 150
R2 0.014 0.863 0.868 0.635
Within-R2 0.642 0.598 0.391
----------------------------------------------------------------------------------------------------
```

```jldoctest
regtable(rr1,rr2,rr3,rr4; render = LatexTable(), extra_space=true)
# output
\begin{tabular}{lrrrr}
\toprule
& \multicolumn{3}{c}{SepalLength} & \multicolumn{1}{c}{SepalWidth} \\
\cmidrule(lr){2-4} \cmidrule(lr){5-5}
& (1) & (2) & (3) & (4) \\
\midrule
(Intercept) & 6.526*** & & & \\
& (0.479) & & & \\
& & & & \\
SepalWidth & -0.223 & 0.432*** & 0.516*** & \\
& (0.155) & (0.081) & (0.104) & \\
& & & & \\
PetalLength & & 0.776*** & 0.723*** & -0.188* \\
& & (0.064) & (0.129) & (0.083) \\
& & & & \\
PetalWidth & & & -0.625 & 0.626*** \\
& & & (0.354) & (0.123) \\
& & & & \\
PetalLength $\times$ PetalWidth & & & 0.066 & \\
& & & (0.067) & \\
& & & & \\
SepalLength & & & & 0.378*** \\
& & & & (0.066) \\
\midrule
Species Fixed Effects & & Yes & Yes & Yes \\
isSmall Fixed Effects & & & Yes & \\
\midrule
$N$ & 150 & 150 & 150 & 150 \\
$R^2$ & 0.014 & 0.863 & 0.868 & 0.635 \\
Within-$R^2$ & & 0.642 & 0.598 & 0.391 \\
\bottomrule
\end{tabular}
```


## All Available Statistics

```jldoctest
Expand Down
26 changes: 24 additions & 2 deletions src/regtable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ function regtable(
regressors=nothing,
use_relabeled_values=default_use_relabeled_values(render, rrs),
confint_level=default_confint_level(render, rrs),
extra_space::Bool=false,
kwargs...
) where {T<:AbstractRenderType}
@assert align (:l, :r, :c) "align must be one of :l, :r, :c"
Expand Down Expand Up @@ -634,18 +635,39 @@ function regtable(
in_header = false
if below_statistic === nothing
temp = hcat(nms, coefvalues)
push_DataRow!(out, temp, align, wdths, false, render)
if extra_space
for i in 1:size(temp, 1)
push_DataRow!(out, temp[i, :], align, wdths, false, render)
if i != size(temp, 1)
push_DataRow!(out, fill("", size(temp, 2)), align, wdths, false, render)
end
end
else
push_DataRow!(out, temp, align, wdths, false, render)
end
else
if stat_below
temp = hcat(nms, coefvalues)
for i in 1:size(temp, 1)
push_DataRow!(out, temp[i, :], align, wdths, false, render)
push_DataRow!(out, coefbelow[i, :], align, wdths, false, render)
if extra_space && i != size(temp, 1)
push_DataRow!(out, fill("", size(temp, 2)), align, wdths, false, render)
end
end
else
x = [(x, y) for (x, y) in zip(coefvalues, coefbelow)]
temp = hcat(nms, x)
push_DataRow!(out, temp, align, wdths, false, render)
if extra_space
for i in 1:size(temp, 1)
push_DataRow!(out, temp[i, :], align, wdths, false, render)
if i != size(temp, 1)
push_DataRow!(out, fill("", size(temp, 2)), align, wdths, false, render)
end
end
else
push_DataRow!(out, temp, align, wdths, false, render)
end
end
end
elseif v == :regtype
Expand Down

2 comments on commit 5cbbfcb

@junder873
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/118471

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.7.8 -m "<description of version>" 5cbbfcb5e7b9218fafc4d6b20d8a4771c9924e88
git push origin v0.7.8

Please sign in to comment.