This short video shows you how to 1) estimate a bivariate regression model, 2) produce predicted values, & 3) visualize the model.
This short video shows you how to 1) estimate a bivariate regression model, 2) produce predicted values, & 3) visualize the model.
Stata Code
/*
Stata help using the margins command
Uses the GSS data
*/
/* Create a subset of the GSS data */
keep year realrinc educ
drop if educ LT 8 /* Youtube does not allow using the less than symbol. Stata requires it */
keep if year==2018
drop year
keep if !missing(realrinc, educ)
/* Estimate a model of the relationship between income & education */
regress realrinc educ /* Estimate a model */
display -25386.6 + 3543.642*12 /* Calculate Y-hat for educ=12) */
/* Calculate predicted values */
predict yhat, xb
summarize yhat if educ==12
/* Use margins to calculate the predicted values */
margins, at(educ=12)
margins, at(educ=(12 14 16))
margins,at(educ=(8(1)20))
/* Visualize the model */
marginsplot, recast(line) noci scheme(s2mono)