Introductory Stata 46: Contour Plot(Graphs For Interaction Effect Between Two Continuous Variables)

Опубликовано: 15 Январь 2026
на канале: Dr. Bob Wen (Stata, Economics, Econometrics)
1,272
22

We could use graphs to examine the distribution and structure of data. We could also use graphs to illustrate the estimation results. When we include an interaction term in the regression model, we obtain the interaction effect estimate. It is a good idea to interpret the effect using graphs.

Let's open the dataset for US workers. You can download the dataset from the link below.

https://drive.google.com/file/d/1kAve...

#Interaction #ContourPlot #Stata

***********************************
*46. Contour plot *
***********************************
capture log close
log using contour.log, text replace

set showbaselevels on

*Use the dataset I created for US workers
use "https://134997773-924437014403349320....", clear
describe
summarize

*OLS regression with interaction term
regress lwage c.ln_parent_income##c.age gender

*Predict wage across parent's income and age and save to a new dataset
margins, at(ln_parent_income=(7(1)13) age=(25(5)54)) saving(predictions, replace)

*use the dataset and contour plot
use predictions.dta, clear
describe

graph twoway (contour _margin _at1 _at2, levels(20) minmax), ylabel(7(1)13)

log close