--- "Justin G. Gardner" <[email protected]> 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.
>
> I know that I can just type in two equations and generate two new
> variables, but that method is cumbersome if I have to repeat it
> several times.
>
> What will happen if I use the predict command with and if statement?
>
> reg y D X
> predict <new variable name> if D=1
>
> This method will only give me a prediction if D is actually 1? If so
> then that is not what I need.
>
When you call -predict- Stata will look for variables with the same
name as the variables you used during your last estimation command.
Stata doesn't know or care whether these variables contain the same
values as during the last estimation command. You can use that to make
out of sample predictions, like in the example below.
*--------- begin example -----------
sysuse auto, clear
reg price mpg foreign
gen byte tempfor = foreign
replace foreign = 1
predict yhatfor
replace foreign = 0
predict yhatdom
replace foreign = tempfor
drop tempfor
sum yhatfor yhatdom
*----------- end example -----------
(For more on how to use examples I sent to the Statalist, see
http://home.fsw.vu.nl/m.buis/stata/exampleFAQ.html )
Hope this helps,
Maarten
-----------------------------------------
Maarten L. Buis
Department of Social Research Methodology
Vrije Universiteit Amsterdam
Boelelaan 1081
1081 HV Amsterdam
The Netherlands
visiting address:
Buitenveldertselaan 3 (Metropolitan), room Z434
+31 20 5986715
http://home.fsw.vu.nl/m.buis/
-----------------------------------------
___________________________________________________________
The all-new Yahoo! Mail goes wherever you go - free your email address from your Internet provider. http://uk.docs.yahoo.com/nowyoucan.html
*
* 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/