Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add extra_space option for extra space between coefficient lines #168

Merged
merged 2 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading