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

RE: st: plot predicted effects after regression


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: plot predicted effects after regression
Date   Mon, 10 May 2004 10:54:28 +0100

Given interest in doing this, a minute detail 
may be worth noting. 

Fooling -adjust- by supplying a -by()- variable 
which is constant (and, strictly, non-missing 
for the observations of interest) is the trick 
here which perhaps many have worked out for 
themselves. 

It doesn't really matter what the value of the -by()- 
variable is, subject to those constraints. However, 

gen all = " " 

has the best cosmetic effect on the tabular 
output of -adjust-. To spell this out, 
-adjust- is happy that the -by()- argument 
is a string variable, but not happy that 
it is missing. Setting it to a space
produces a clean table as below. 


. adjust we tu tr, by(all) gen(predict) 

--------------------------------------------------------------------------------------------------
     Dependent variable: mpg     Command: regress
       Created variable: predict 
 Covariates set to mean: weight = 3019.4595, turn = 39.648647, trunk = 13.756757
--------------------------------------------------------------------------------------------------

----------------------
      all |         xb
----------+-----------
          |    21.2973
----------------------
     Key:  xb  =  Linear Prediction

This really is minute -- especially as in these circumstances 
the -generate-d variable is what you want, not the table -- 
but some people might care, especially if they do this a lot. 

Nick 
[email protected] 

John Reynolds
 
> 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"))
> 

*
*   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