*! version 1.1 20apr2023

Title

plotbetas -- Plot regression coefficients (post-estimation)

Syntax

plotbetas varlist [if] [in]
[, options]

where varlist defines the set of variables to be plotted.

Basic options
over(varlist) an alternative way to specify the varlist

graph(graph_type) specify the twoway graph_type for coefficient estimates: line(default)/bar/connected/scatter/etc.

rgraph(rgraph_type) specify the twoway rgraph_type for confidence intervals: rarea(default)/rbar/rcap/rspike/etc.

ci(#,ci_options) specify the confidence level for confidence intervals:  # = 0...100, off = suppress CIs. By default, # is the confidence level used in the regression output.

  ci_options denote rgraph_type customization options (e.g., color and transparency)

Memory/data management
frame(frame_name) specify the name of the frame that stores the plot data (frame_pt is the default frame_name)

clear clear all plot data stored in frame_name

replace(#) replace data and/or options for plot # in frame_name

plotonly display the plots already stored in frame_name

Plot customization
command print out the twoway command used to display the chart (useful for finer customization)

global apply the same customization options to all plots in frame_name

plname(plot_name) name the current plot (used in legends when displaying multiple plots at once)

xshift(real) shift the plotted values along the x-axis

yshift(real) shift the plotted values along the y-axis

yzero a shorthand option for displaying zero on the y-axis (and scaling ylabels accordingly)

twoway_options change titles, legends, axes, aspect ratio, etc.

connect_options change look of lines or connecting method

marker_options change look of
markers (color, size, etc.)

Other options
nodraw do not display the plotted values (useful when looping/overlaying many intermediate plots)

times(real) multiply the plotted values by a constant (useful for normalizations)

varlist needs to be specified (one way or the other) to produce a new plot. It does not need to be specified when displaying plots that are already stored in the memory (using the option plotonly).

Description

plotbetas is a post-estimation (!) command that visualizes regression coefficient estimates of varlist along with their confidence intervals.
The varlist can be either a list of multiple variables, or a single factorized variable (i.varname).

plotbetas avoids time-consuming memory operations performed by native graphing commands.
By leveraging the data frame environment, it proves extremely fast in very large datasets.

plotbetas can be called sequentially. The plotted data is stored in a dedicated data frame (see Memory/data management options), which allows users to create complex visualizations that combine multiple plots.
plotbetas can be also combined with other commands in the plot suite (plottabs, plotmeans, and plotshares).

Customization: the coefficient plots can be customized by selecting the preferred twoway graph_type, and adjusting it further using the twoway_options and other options specific to the given graph_type.
The confidence-interval plots can be customized by selecting the preferred twoway rgraph_type, and adjusting it further using the ci_options suboption of ci(#,ci_options). See examples below.

CURRENT LIMITATIONS: Custom confidence levels for confidence intervals are currently restricted to OLS models (command regress). However, you can work around this limitation by estimating your model with pre-specified
confidence level (option level(#)), and run the plotbetas command without specifying the confidence level. See example below.

Examples

Basic use:

. clear all

. sysuse nlsw88

. reg ttl_exp i.age

. plotbetas i.age

* produce a whisker plot instead:

. plotbetas i.age, clear graph(scatter) rgraph(rcap)

Compare regression estimates for two groups:

. clear all

. sysuse nlsw88

. reg ttl_exp i.age if union==0

. plotbetas i.age, graph(connect) plname(Non-union)

. reg ttl_exp i.age if union==1

. plotbetas i.age, graph(connect) plname(Union)

Customize line color, CI color & CI transparency:

. clear all

. sysuse nlsw88

. reg ttl_exp i.age

. plotbetas i.age, color(green) ci(, color(gold%35))

Plot non-linear model coefficients with 99% CIs:

. clear all

. sysuse nlsw88

. logit collgrad i.age, level(99)

. plotbetas i.age

Plot data management:

See plottabs / Plot data management

Frames

See plottabs / Frames

Contact

Jan Kabátek, The University of Melbourne

j.kabatek@unimelb.edu.au