Skip to content

Commit 5cbbfcb

Browse files
authored
Merge pull request #168 from jmboehm/add-extra_space-option
Add extra_space option for extra space between coefficient lines
2 parents 1f0b3dd + 34dbc46 commit 5cbbfcb

File tree

3 files changed

+172
-3
lines changed

3 files changed

+172
-3
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "RegressionTables"
22
uuid = "d519eb52-b820-54da-95a6-98e1306fdade"
33
authors = ["Johannes Boehm <[email protected]>"]
4-
version = "0.7.7"
4+
version = "0.7.8"
55

66
[deps]
77
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"

docs/src/examples.md

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,153 @@ Adj. R2 0.007 0.860 0.861 0.622
972972
----------------------------------------------------------------------
973973
```
974974

975+
## Adding an extra row between coefficients
976+
977+
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).
978+
979+
```jldoctest
980+
regtable(rr1,rr2,rr3,rr4; extra_space = true)
981+
982+
# output
983+
984+
985+
----------------------------------------------------------------------
986+
SepalLength SepalWidth
987+
------------------------------ ----------
988+
(1) (2) (3) (4)
989+
----------------------------------------------------------------------
990+
(Intercept) 6.526***
991+
(0.479)
992+
993+
SepalWidth -0.223 0.432*** 0.516***
994+
(0.155) (0.081) (0.104)
995+
996+
PetalLength 0.776*** 0.723*** -0.188*
997+
(0.064) (0.129) (0.083)
998+
999+
PetalWidth -0.625 0.626***
1000+
(0.354) (0.123)
1001+
1002+
PetalLength & PetalWidth 0.066
1003+
(0.067)
1004+
1005+
SepalLength 0.378***
1006+
(0.066)
1007+
----------------------------------------------------------------------
1008+
Species Fixed Effects Yes Yes Yes
1009+
isSmall Fixed Effects Yes
1010+
----------------------------------------------------------------------
1011+
N 150 150 150 150
1012+
R2 0.014 0.863 0.868 0.635
1013+
Within-R2 0.642 0.598 0.391
1014+
----------------------------------------------------------------------
1015+
```
1016+
1017+
```jldoctest
1018+
regtable(rr1,rr2,rr3,rr4; below_statistic = nothing, extra_space=true)
1019+
1020+
# output
1021+
1022+
1023+
----------------------------------------------------------------------
1024+
SepalLength SepalWidth
1025+
------------------------------ ----------
1026+
(1) (2) (3) (4)
1027+
----------------------------------------------------------------------
1028+
(Intercept) 6.526***
1029+
1030+
SepalWidth -0.223 0.432*** 0.516***
1031+
1032+
PetalLength 0.776*** 0.723*** -0.188*
1033+
1034+
PetalWidth -0.625 0.626***
1035+
1036+
PetalLength & PetalWidth 0.066
1037+
1038+
SepalLength 0.378***
1039+
----------------------------------------------------------------------
1040+
Species Fixed Effects Yes Yes Yes
1041+
isSmall Fixed Effects Yes
1042+
----------------------------------------------------------------------
1043+
N 150 150 150 150
1044+
R2 0.014 0.863 0.868 0.635
1045+
Within-R2 0.642 0.598 0.391
1046+
----------------------------------------------------------------------
1047+
```
1048+
1049+
```jldoctest
1050+
regtable(rr1,rr2,rr3,rr4; stat_below=false, extra_space=true)
1051+
1052+
# output
1053+
1054+
1055+
----------------------------------------------------------------------------------------------------
1056+
SepalLength SepalWidth
1057+
------------------------------------------------------ ----------------
1058+
(1) (2) (3) (4)
1059+
----------------------------------------------------------------------------------------------------
1060+
(Intercept) 6.526*** (0.479)
1061+
1062+
SepalWidth -0.223 (0.155) 0.432*** (0.081) 0.516*** (0.104)
1063+
1064+
PetalLength 0.776*** (0.064) 0.723*** (0.129) -0.188* (0.083)
1065+
1066+
PetalWidth -0.625 (0.354) 0.626*** (0.123)
1067+
1068+
PetalLength & PetalWidth 0.066 (0.067)
1069+
1070+
SepalLength 0.378*** (0.066)
1071+
----------------------------------------------------------------------------------------------------
1072+
Species Fixed Effects Yes Yes Yes
1073+
isSmall Fixed Effects Yes
1074+
----------------------------------------------------------------------------------------------------
1075+
N 150 150 150 150
1076+
R2 0.014 0.863 0.868 0.635
1077+
Within-R2 0.642 0.598 0.391
1078+
----------------------------------------------------------------------------------------------------
1079+
```
1080+
1081+
```jldoctest
1082+
1083+
regtable(rr1,rr2,rr3,rr4; render = LatexTable(), extra_space=true)
1084+
1085+
# output
1086+
1087+
\begin{tabular}{lrrrr}
1088+
\toprule
1089+
& \multicolumn{3}{c}{SepalLength} & \multicolumn{1}{c}{SepalWidth} \\
1090+
\cmidrule(lr){2-4} \cmidrule(lr){5-5}
1091+
& (1) & (2) & (3) & (4) \\
1092+
\midrule
1093+
(Intercept) & 6.526*** & & & \\
1094+
& (0.479) & & & \\
1095+
& & & & \\
1096+
SepalWidth & -0.223 & 0.432*** & 0.516*** & \\
1097+
& (0.155) & (0.081) & (0.104) & \\
1098+
& & & & \\
1099+
PetalLength & & 0.776*** & 0.723*** & -0.188* \\
1100+
& & (0.064) & (0.129) & (0.083) \\
1101+
& & & & \\
1102+
PetalWidth & & & -0.625 & 0.626*** \\
1103+
& & & (0.354) & (0.123) \\
1104+
& & & & \\
1105+
PetalLength $\times$ PetalWidth & & & 0.066 & \\
1106+
& & & (0.067) & \\
1107+
& & & & \\
1108+
SepalLength & & & & 0.378*** \\
1109+
& & & & (0.066) \\
1110+
\midrule
1111+
Species Fixed Effects & & Yes & Yes & Yes \\
1112+
isSmall Fixed Effects & & & Yes & \\
1113+
\midrule
1114+
$N$ & 150 & 150 & 150 & 150 \\
1115+
$R^2$ & 0.014 & 0.863 & 0.868 & 0.635 \\
1116+
Within-$R^2$ & & 0.642 & 0.598 & 0.391 \\
1117+
\bottomrule
1118+
\end{tabular}
1119+
```
1120+
1121+
9751122
## All Available Statistics
9761123

9771124
```jldoctest

src/regtable.jl

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,7 @@ function regtable(
408408
regressors=nothing,
409409
use_relabeled_values=default_use_relabeled_values(render, rrs),
410410
confint_level=default_confint_level(render, rrs),
411+
extra_space::Bool=false,
411412
kwargs...
412413
) where {T<:AbstractRenderType}
413414
@assert align (:l, :r, :c) "align must be one of :l, :r, :c"
@@ -634,18 +635,39 @@ function regtable(
634635
in_header = false
635636
if below_statistic === nothing
636637
temp = hcat(nms, coefvalues)
637-
push_DataRow!(out, temp, align, wdths, false, render)
638+
if extra_space
639+
for i in 1:size(temp, 1)
640+
push_DataRow!(out, temp[i, :], align, wdths, false, render)
641+
if i != size(temp, 1)
642+
push_DataRow!(out, fill("", size(temp, 2)), align, wdths, false, render)
643+
end
644+
end
645+
else
646+
push_DataRow!(out, temp, align, wdths, false, render)
647+
end
638648
else
639649
if stat_below
640650
temp = hcat(nms, coefvalues)
641651
for i in 1:size(temp, 1)
642652
push_DataRow!(out, temp[i, :], align, wdths, false, render)
643653
push_DataRow!(out, coefbelow[i, :], align, wdths, false, render)
654+
if extra_space && i != size(temp, 1)
655+
push_DataRow!(out, fill("", size(temp, 2)), align, wdths, false, render)
656+
end
644657
end
645658
else
646659
x = [(x, y) for (x, y) in zip(coefvalues, coefbelow)]
647660
temp = hcat(nms, x)
648-
push_DataRow!(out, temp, align, wdths, false, render)
661+
if extra_space
662+
for i in 1:size(temp, 1)
663+
push_DataRow!(out, temp[i, :], align, wdths, false, render)
664+
if i != size(temp, 1)
665+
push_DataRow!(out, fill("", size(temp, 2)), align, wdths, false, render)
666+
end
667+
end
668+
else
669+
push_DataRow!(out, temp, align, wdths, false, render)
670+
end
649671
end
650672
end
651673
elseif v == :regtype

0 commit comments

Comments
 (0)