clear sysuse auto * example histogram histogram length, /// base graphing command xscale(r(130 245) lcolor()) /// x-axis scaling yscale(r(-.001 .02) lcolor()) /// y-axis scaling /// scaling on axes plotregion(fcolor(white) lcolor(gs10) lwidth(med)) /// plot coloration and outline graphregion(fcolor(white)) /// background coloration xlabel(135 145 155 165 175 185 195 205 215 225 235 245, /// x-axis label #s labcolor(gs4) tlcolor() tlwidth(thin) labsize(small) nogrid) /// x-axis labels coloration ylabel(0.000 "0.000" 0.005 "0.005" 0.010 "0.010" 0.015 "0.015" 0.020 "0.020", /// y-axis label #s labcolor(gs4) tlcolor() tlwidth(thin) labsize(small) nogrid) /// y-axis labels coloration xtitle("Length (inches)", color(black)) /// x-axis title ytitle("Density", color(black)) /// y-axis title bcolor(white) bl(black) /// setting bar color title(" ") * baseline code annotation that can be applied to all graphs xscale(r(# #) lcolor(color)) /// x-axis scaling yscale(r(# #) lcolor(color)) /// y-axis scaling plotregion(fcolor(color) lcolor(color) lwidth(__)) /// plot coloration and outline graphregion(fcolor(white)) /// background coloration xlabel(# "label" # "label", /// x-axis label #s labcolor(color) tlcolor(color) tlwidth(__) labsize(__) nogrid) /// x-axis labels coloration ylabel((# "label" # "label", /// y-axis label #s labcolor(color) tlcolor(color) tlwidth(__) labsize(__) nogrid) /// y-axis labels coloration xtitle(" ", color(color)) /// x-axis title ytitle(" ", color(color)) /// y-axis title bcolor(color) blcolor(color) /// setting bar color title(" ") * where: # = whatever number you like, color = whatever color you choose, and * __ = width or size *approximating a rugplot reg price length margins, at(length=(150(10)230)) marginsplot, /// base graphing command level(95) /// confidence intervals plotregion(fcolor(white) lcolor(gs10) lwidth(med)) /// plot coloration and outline graphregion(fcolor(white)) /// background coloration xlabel(, /// x-axis label #s labcolor(gs4) tlcolor() tlwidth(thin) labsize(small) nogrid) /// x-axis labels coloration ylabel(4000 "$4,000" 6000 "$6,000" 8000 "$8,000" 10000 "$10,000", /// y-axis label #s labcolor(gs4) tlcolor() tlwidth(thin) labsize(small) nogrid) /// y-axis labels coloration xtitle("Length (inches)", color(black)) /// x-axis title ytitle("Car price ($)", color(black)) /// y-axis title recastci(rspike) /// confidence interval display options ci1opts(lcolor(black)) /// confidence interval color plot1opts(mcolor(white) mlcolor(black) lcolor(black)) /// plot colors title(" ") /// master graph title addplot(hist length, /// adding and overlaying distribution of length blcolor(black) fcolor(black) /// bar line and fill colors discrete /// tells stata to graph actual distribution of length yaxis(2) /// calls for 2nd y-axis, which we'll suppress yscale(alt lcolor() axis(2)) /// 2nd y-axis scaling ylabel(0 " " 20 " " 40 " " 60 " " 80 " " 100 " ", /// minimizing the height of histogram labcolor() axis(2) tlcolor(black) tlwidth(thin) labsize(small) tl(0)) /// label options for 2nd axis, removes ticks / labels ytitle(" ", axis(2)) /// no title on 2nd axis legend(order( 2 "Predicted price" 3 "Car lengths"))) *overlaying histogram reg price length margins, at(length=(150(10)230)) marginsplot, /// base graphing command level(95) /// confidence intervals plotregion(fcolor(white) lcolor(gs10) lwidth(med)) /// plot coloration and outline graphregion(fcolor(white)) /// background coloration xlabel(, /// x-axis label #s labcolor(gs4) tlcolor() tlwidth(thin) labsize(small) nogrid) /// x-axis labels coloration ylabel(4000 "$4,000" 6000 "$6,000" 8000 "$8,000" 10000 "$10,000", /// y-axis label #s labcolor(gs4) tlcolor() tlwidth(thin) labsize(small) nogrid) /// y-axis labels coloration xtitle("Length (inches)", color(black)) /// x-axis title ytitle("Car price ($)", color(black)) /// y-axis title recastci(rspike) /// confidence interval display options ci1opts(lcolor(black)) /// confidence interval color plot1opts(mcolor(white) mlcolor(black) lcolor(black)) /// plot colors title(" ") /// master graph title addplot(hist length, /// adding histogram marginsplot graph blcolor(gs10) fcolor(gs10) /// bar line and fill colors percent /// histogram bins in "percent" rather than "discrete" (actual) yaxis(2) /// calls for 2nd y-axis yscale(alt lcolor() axis(2)) /// scaling on 2nd y-axis ylabel(0 "0%" 20 "20%" 40 "40%" 60 " " 80 " " 100 " ", /// labels on 2nd y-axis labcolor() axis(2) tlcolor(black) tlwidth(thin) labsize(small)) /// label options on 2nd y-axis ytitle(" ", axis(2)) /// telling Stata to remove title on 2nd y-axis legend(order( 2 "Predicted price" 3 "Car lengths"))) * coefplot example * first recode vars to 0 to 1 to make plots clean foreach x in length weight mpg displacement foreign { sum `x' gen `x'01 = (`x'-r(min))/(r(max)-r(min)) } reg price length01 weight01 mpg01 displacement01 foreign01 est store price coefplot price, /// coefplot package drop(_cons) /// drop the constant, coefplot will always auto-plot level(95) /// confidence interval level plotregion(fcolor(white) lcolor(gs10) lwidth(med)) /// plot coloration and outline graphregion(fcolor(white)) /// background coloration xlabel(-10000 "-$10,000" 0 "$0" 10000 "$10,000" 20000 "$20,000", /// x-axis label #s labcolor(gs4) tlcolor() tlwidth(thin) labsize(small) nogrid) /// x-axis labels coloration ylabel(, /// y-axis label #s labcolor(gs4) tlcolor() tlwidth(thin) labsize(small) nogrid) /// y-axis labels coloration xtitle("Marginal effect, min-to-max", color(black)) /// x-axis title ytitle(, color(black)) /// y-axis title title(" ") /// graph title " " = not title xline(0, lp(dash) lcolor(red)) /// red dashed line at 0 mcolor(white) mlcolor(black) /// point estimate color options ciopts(lcolor(black)) /// CI color options coeflabels( length01 = "Length" weight01 = "Weight" mpg01 = "MPG" displacement01 = "Displacement" foreign01 = "Foreign") /// re-labeling legend(off)