At 10:03 AM 3/20/2007, Justin G. Gardner wrote:
I have a linear model:
y= d*D + b*X
Where D is a dummy variable. Is there a simple way to generate a
prediction where the dummy variable is held constant? i.e. I want
to know what y would be if D was always 0, and what y would be if D
was always 1.
The -adjust- command is good for "what if" types of questions.
. webuse auto, clear
(1978 Automobile Data)
. quietly reg price mpg foreign
. predict yhat if e(sample)
(option xb assumed; fitted values)
. adjust foreign = 0 if e(sample), gen(yhat0)
---------------------------------------------------------
Dependent variable: price Command: regress
Created variable: yhat0
Variable left as is: mpg
Covariate set to value: foreign = 0
---------------------------------------------------------
----------------------
All | xb
----------+-----------
| 5639.85
----------------------
Key: xb = Linear Prediction
. adjust foreign = 1 if e(sample), gen(yhat1)
-----------------------------------------------------------
Dependent variable: price Command: regress
Created variable: yhat1
Variable left as is: mpg
Covariate set to value: foreign = 1
-----------------------------------------------------------
----------------------
All | xb
----------+-----------
| 7407.14
----------------------
Key: xb = Linear Prediction
. sum yhat*
Variable | Obs Mean Std. Dev. Min Max
-------------+--------------------------------------------------------
yhat | 74 6165.257 1571.413 1610.691 9553.97
yhat0 | 74 5639.846 1702.069 -156.6016 8375.069
yhat1 | 74 7407.138 1702.069 1610.691 10142.36
I've also used -clonevar- for such things.
. drop yhat*
. clonevar xforeign = foreign
. quietly reg price mpg xforeign
. predict yhat if e(sample)
(option xb assumed; fitted values)
. replace xforeign = 0
(22 real changes made)
. predict yhat0 if e(sample)
(option xb assumed; fitted values)
. replace xforeign = 1
(74 real changes made)
. predict yhat1 if e(sample)
(option xb assumed; fitted values)
. sum yhat*
Variable | Obs Mean Std. Dev. Min Max
-------------+--------------------------------------------------------
yhat | 74 6165.257 1571.413 1610.691 9553.97
yhat0 | 74 5639.846 1702.069 -156.6016 8375.069
yhat1 | 74 7407.138 1702.069 1610.691 10142.36
-------------------------------------------
Richard Williams, Notre Dame Dept of Sociology
OFFICE: (574)631-6668, (574)631-6463
HOME: (574)289-5227
EMAIL: [email protected]
WWW: http://www.nd.edu/~rwilliam
*
* 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/