*! regproject v1.0.0 April 2026

Title

regproject -- Post-estimation projection and boundary analysis

Syntax

regproject varname
[,
options]

Focal IV bounds (scalar — applies to focal variable only)
ivmin(#) lower bound for focal IV

ivmax(#) upper bound for focal IV

All IV bounds (positional — applies to all IVs in regression order)
ivmins(numlist) lower bounds for all IVs (same order as regression output)

ivmaxs(numlist) upper bounds for all IVs (same order as regression output)

DV limits
ymin(#) lower limit of dependent variable

ymax(#) upper limit of dependent variable

Output
saving(stub) save graphs as stub_1.gph, stub_2.gph, ...

combine combine all mode graphs into a single figure

nodisplay suppress screen display (useful in batch scripts)

Description

regproject is a post-estimation command that projects the effect of a
chosen independent variable (IV) on the dependent variable (DV), while
holding all other regressors at their median values. It automatically detects
whether the current dataset is cross-sectional, time-series, or panel, and
produces a mode-appropriate set of graphs.

regproject must be run immediately after a supported estimation command.
Supported commands include: regress, xtreg, qreg,
xtregar, newey, arima, ardl, ivregress.

Note on ivmin/ivmax vs ivmins/ivmaxs: These option pairs are mutually
exclusive. Use ivmin/ivmax to set bounds only for the focal IV.
Use ivmins/ivmaxs to set bounds for all IVs simultaneously, in
the same order as regressors appear in regression output (excluding _cons).

Options

Focal IV bounds

ivmin(#) specifies the lower bound for the focal IV only. If omitted,
the minimum observed value in the data is used.

ivmax(#) specifies the upper bound for the focal IV only. If omitted,
the maximum observed value in the data is used.

All IV bounds

ivmins(numlist) specifies lower bounds for all IVs in the model, in
regression order (excluding _cons). The list must contain exactly as many
values as there are regressors. The value at the position of the focal IV
is used as its lower bound.

ivmaxs(numlist) specifies upper bounds for all IVs in the model.
Same positional rules as ivmins().

DV limits

ymin(#) sets the lower limit of the DV. Used to shade the region below
this value on graphs, and to detect when the projected DV crosses this
threshold in time-series forward projections.

ymax(#) sets the upper limit of the DV. Used for upper shading and
crossing detection.

Output

saving(stub) saves all generated graphs. Graph files are named
stub_1.gph through stub_n.gph, where n is the number of
graphs for the detected data mode.

combine combines all graphs for the detected mode into a single figure
using graph combine.

nodisplay suppresses screen output of graphs. Useful in batch runs.

Graphs by data mode

Cross-sectional (4 graphs)

Graph 1 — Entity bar chart. Bar height equals predicted ŷ for each
entity using its own covariate values. Entities sorted ascending by focal IV.
Four horizontal reference lines show ŷ at max/min observed IV and
user-supplied IV bounds (median base for non-focal covariates).
DV limit shading applied if ymin/ymax supplied.

Graph 2 — Sensitivity ranking. Horizontal bars for all IVs, ranked
by |coef × (upper − lower bound)|. Shows which variable has the most
leverage on the DV across its range. Focal IV highlighted in orange.

Graph 3 — Gap to boundary. For each entity, shows headroom to the
DV upper limit (or distance below DV lower limit). Entities breaching
a limit shown in red. Requires ymin or ymax.

Graph 4 — Counterfactual comparison. Grouped bars showing actual ŷ
vs counterfactual ŷ where the focal IV is replaced with its median.
The difference isolates the IV's contribution per entity.

Panel data (4 graphs)

Graph 1 — Latest-period dot chart. Dot per entity at ŷ using latest
period values. Sorted ascending by focal IV. Same reference line and
shading logic as cross-sectional Graph 1.

Graph 2 — Spaghetti trajectories. Entity ŷ trajectories over time,
with median trajectory overlaid in red.

Graph 3 — Delta IV vs Delta ŷ scatter. Change in focal IV (first to
last period) on X; change in ŷ on Y. Theoretical slope from regression
coefficient shown as dashed reference line.

Graph 4 — Heat map. Entities × time periods, with cell color
proportional to ŷ. Uses heatplot (SSC) if installed; falls back
to a simple scatter if not.

Time series (3 graphs)

Graph 1 — Static sweep. IV swept from lower to upper bound on X;
predicted ŷ on Y. 95% CI ribbon shown. Red diamond marks the latest
observed IV value.

Graph 2 — IV-only forward projection. Focal IV extrapolated 25 periods
ahead using its linear trend. All other covariates held at median.
DV limit lines drawn; first period of crossing annotated.

Graph 3 — Full system projection. All covariates extrapolated 25 periods
using their individual linear trends. Inhibitor dynamics naturally reflected
in the trajectory shape.

Examples

Cross-sectional — sysuse auto

The auto dataset contains 74 observations on car models (1978).
No xtset or tsset is active, so regproject automatically
detects cross-sectional mode.

. sysuse auto, clear

. regress price mpg weight length

. regproject weight, ivmin(1500) ivmax(5000) ymin(3000) ymax(16000)

With bounds for all IVs and combined output:

. regproject weight, ivmins(10 1500 140) ivmaxs(41 5000 233) ymin(3000) ymax(16000) combine

Interpretation: Graph 1 shows predicted price per car sorted by weight.
The four reference lines show predicted price when weight is at its
observed min/max and at user-supplied realistic bounds. Graph 2 ranks
mpg, weight, and length by their leverage on price. Graph 3 shows each
car's headroom to the price ceiling. Graph 4 shows actual vs counterfactual
predicted price if weight were replaced with its median.

Time series — sysuse uslifeexp

The uslifeexp dataset contains annual US life expectancy data 1900–1999.
After tsset year, regproject detects time-series mode and
produces three graphs including a 25-period forward projection.

. sysuse uslifeexp, clear

. tsset year

. regress le_wmale le_wfemale le_bmale

. regproject le_wfemale, ymin(60) ymax(90) combine

With user-supplied IV bounds:

. regproject le_wfemale, ivmin(55) ivmax(95) ymin(60) ymax(90) combine

Interpretation: Graph 1 sweeps white female life expectancy across
its range and shows where male life expectancy is projected to land, with
a CI ribbon and a dot at the latest observed value. Graph 2 projects
25 years forward using the current trend in le_wfemale only. Graph 3
projects forward using trends in all covariates simultaneously.

Panel data — 10 Asian economies × 5 periods (synthetic)

The panel example uses 10 named economies observed biennially 2010–2018,
with poverty rate as the outcome and GDP growth as the focal IV.
Data is generated programmatically so no external file is needed.

. clear

. set obs 50

. generate cid = ceil(_n / 5)

. generate year = 2010 + mod(_n-1, 5) * 2

. generate str15 cname = ""

. replace cname = "Malaysia" if cid==1

. replace cname = "Thailand" if cid==2

. replace cname = "Indonesia" if cid==3

. replace cname = "Philippines" if cid==4

. replace cname = "Vietnam" if cid==5

. replace cname = "Cambodia" if cid==6

. replace cname = "Bangladesh" if cid==7

. replace cname = "Pakistan" if cid==8

. replace cname = "SriLanka" if cid==9

. replace cname = "India" if cid==10

. generate gdp = 3 + 4*runiform() + 0.2*(year-2010)/2

. generate trade = 40 + 80*runiform()

. generate govexp = 15 + 10*runiform()

. generate poverty = 35 - 1.8*gdp - 0.05*trade - 0.3*govexp + rnormal(0,1.5)

. xtset cid year

. xtreg poverty gdp trade govexp, fe

. regproject gdp, ivmins(-2 25 10) ivmaxs(10 150 35) ymin(0) ymax(40) combine

Interpretation: Graph 1 shows each country's predicted poverty rate
at its latest-period values, sorted ascending by GDP growth, with four
horizontal benchmark lines. Graph 2 shows country-level poverty trajectories
over time with the median overlaid in red. Graph 3 scatters the change in
GDP growth against the change in predicted poverty across countries, with
the theoretical regression slope as a dashed reference. Graph 4 renders
a heat map of predicted poverty across countries and years (requires
heatplot from SSC; falls back to a bubble scatter otherwise).

For a real panel dataset (requires internet access); note: use age as
focal IV since grade is time-invariant and dropped in FE estimation:

. webuse nlswork, clear

. xtset idcode year

. xtreg ln_wage age ttl_exp tenure, fe

. regproject age, ivmin(15) ivmax(55) ymin(0) ymax(4) combine

Generic syntax reference

Focal IV bounds only:

. regress y x1 x2 x3

. regproject x2, ivmin(5) ivmax(25) ymin(0) ymax(100)

Bounds for all IVs (positional — must match regression order):

. regress y x1 x2 x3

. regproject x2, ivmins(0 5 100) ivmaxs(10 25 500) ymax(100) combine

Author

Dr Noman Arshed

Senior Lecturer, Department of Business Analytics

Sunway Business School, Sunway University

Email: nouman.arshed@gmail.com

GitHub: https://github.com/nomanarshed/regproject

Bug reports and feature requests welcome via GitHub Issues.

Also see

Online: regress, xtreg, qreg, margins,
marginsplot, heatplot (if installed)