I am working with the community-contributed command coefplot in Stata.
I have a large number of estimated coefficients, which I would like to plot on the same graph.
As such, I would like to reduce the spacing between coefficients.
Consider the following toy example using Stata's auto toy dataset:
quietly sysuse auto, clear
quietly regress price mpg trunk length turn
coefplot, drop(_cons) xline(0)

How can the spacing between Mileage (mpg) and Trunk space (cu. ft.) be decreased?
Some white space around the graph is an unavoidable limitation because of how Stata's graphics system works. With that said, an alternative way around this (which does not tinker with the aspect ratio of the graph) is to increase the range of the y-axis.
For example:
forvalues i = 1 / 4 {
coefplot, drop(_cons) xline(0) yscale(range(-`i' `=6+`i''))
}

A different but related approach, is to turn off the y labels entirely and use marker labels instead:
forvalues i = 1 / 4 {
coefplot, drop(_cons) ///
xline(0) ///
yscale(range(-`i' `=6+`i'')) ///
yscale(off) ///
mlabels(mpg = 12 "Mileage" ///
trunk = 12 "Trunk space (cu. ft.)" ///
length = 12 "Length (in.)" ///
turn = 12 "Turn Circle (ft.)")
}

In both approaches, the starting and ending positions (i.e. the amount of space above and below the labels) can be set by tweaking the values specified within the range() suboption.
Note that the grid lines can be turned off by using the option grid(none).
In addition, by combining the at(matrix()) option and yscale(range()) one can allow for unequal reductions in the distance of the coefficients:
matrix A = (0.2,0.21,0.22,0.225,0.255)
coefplot, drop(_cons) ///
xline(0) ///
yscale(range(0.18 0.26)) ///
yscale(off) ///
mlabels(mpg = 12 "Mileage" ///
trunk = 12 "Trunk space (cu. ft.)" ///
length = 12 "Length (in.)" ///
turn = 12 "Turn Circle (ft.)") ///
at(matrix(A)) ///
horizontal

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With