Introductory Stata 41: Graphs For Two Continuous Variables (scatterplots)

preview_player
Показать описание
From today, let's take a look at how to draw graphs for two continuous variables. When we have two continuous variables, and we want to know whether they are correlated, we can draw scatter plots of a continuous variable against the other continuous variable and see the relationship between them. We often draw scatterplots before running a regression model.

Let's continue to use the dataset for the US workers. You can download the dataset here.

********************
*41. Scatter Plots *
********************
capture log close

set showbaselevels on

*Use the dataset I created for US workers
describe
summarize

*scatter plots
graph twoway (scatter lwage ln_parent_income)

help marker options

*use marker symbol options
graph twoway (scatter lwage ln_parent_income, msymbol(s))

graph twoway (scatter lwage ln_parent_income, msymbol(oh))

*use marker color options
graph twoway (scatter lwage ln_parent_income, msymbol(o) mcolor(blue%30))

*use marker size options
graph twoway (scatter lwage ln_parent_income, msymbol(o) mcolor(blue%30) msize(small))

graph twoway (scatter lwage ln_parent_income, msymbol(p))

*scatterplots by groups
graph twoway (scatter lwage ln_parent_income, msymbol(o) mcolor(blue%30) msize(small) by(gender, col(1)))

*multiple scatterplots with two y axes
graph twoway (scatter lwage ln_parent_income) (scatter schooling ln_parent_income)

graph twoway (scatter lwage ln_parent_income, yaxis(1)) (scatter schooling ln_parent_income,yaxis(2))

graph twoway (scatter lwage ln_parent_income, yaxis(1) msymbol(o) mcolor(blue%30) msize(small)) (scatter schooling ln_parent_income,yaxis(2) msymbol(T) mcolor(orange%30) msize(small))

*multiple scatterplots with two x axes
graph twoway (scatter lwage ln_parent_income, xaxis(1) msymbol(o) mcolor(blue%30) msize(small)) (scatter lwage schooling,xaxis(2) msymbol(T) mcolor(orange%30) msize(small)), legend(order(1 "against log parent income" 2 "against schooling"))

log close

#Scatter #TwoYAxes #TwoXAxes
Рекомендации по теме
Комментарии
Автор

Great! Can you also explain same graph by using stata drop down menus.

Thanks from Pakistan 🇵🇰

syedshujaathussainzaidi