Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: plot predicted effects after regression


From   "John Reynolds" <[email protected]>
To   <[email protected]>
Subject   RE: st: plot predicted effects after regression
Date   Sun, 9 May 2004 18:01:41 -0400

Nick wrote:
-------------------------------------
You can use -adjust-: you just need to talk your way past the requirement
for a -by()- option (unless that is part of what you want).
Here is a silly example:
. sysuse auto
. regress mpg weight headroom turn trunk length displacement
. gen all = 1
. adjust headroom turn trunk length displacement, by(all) gen(predict)
. scatter predict weight
-------------------------------------

Thanks for posting the command and example, I frequently have a need to plot
predicted values as well.  I took your mpg example and extended it to other
scenarios that arise in my work, i.e., nonlinear and conditional
associations.  Also, I made the chart a line graph rather than a scatter
plot as a personal preference.

* 1. Linear effect of weight on mpg.
sysuse auto
gen all = 1
regress mpg weight headroom turn trunk length displacement
adjust headroom turn trunk length displacement, by(all) gen(predict)
line predict weight, sort ytitle(Predicted MPG)

* 2. Curvilinear effect of weight, modeled w/ a parabola
gen weightsq=weight*weight
regress mpg weight weightsq headroom turn trunk length displacement
adjust headroom turn trunk length displacement, by(all) gen(predict2)
line predict2 weight, sort ytitle(Predicted MPG)

* 3. Effect of weight conditional on foreign vs. domestic mfr
gen fweight=foreign*weight
regress mpg weight foreign fweight headroom turn trunk length displacement
adjust headroom turn trunk length displacement, by(all) gen(predict3)
twoway (line predict3 weight if foreign==0, sort clpat(solid)) (line
predict3 weight if foreign==1, sort clpat(dash)), ytitle(Predicted MPG)
legend(order(1 "Domestic" 2 "Foreign"))

Good stuff!

John Reynolds, PhD
Department of Sociology
Florida State University
Tallahassee, FL 32306-2270
email: [email protected]
web: http://garnet.acns.fsu.edu/~jreynold

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index