Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
Nahla Betelmal <nahlaib@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
st: predict and resid in a nested loop |

Date |
Wed, 31 Jul 2013 17:43:42 +0100 |

Dear Statalist, I am trying to get the fitted values and residuals from cross-sectional regression in a nested loop ( regression per industry and year). I tried four ways according to my search in previous threads, but obviously I am missing something! In the first two loops I got the error message : f already defined r(110); In the third one I got the error message: varlist not allowed r(101); (I also put the & sign between i and y, but same error) In the last one I got the error message : invalid '1989' r(198); gen fitted=. gen resi =. forval y=1989/2012 { forval i= 1/55 { reg DV IV_1 IV_2 IV_3 if industry== `i' & year==`y' predict f predict r, resid replace fitted= f if industry== `i' & year==`y' replace resi = r if industry== `i' & year==`y' } } f already defined r(110); forval y=1989/2012 { forval i= 1/55 { reg DV IV_1 IV_2 IV_3 if industry== `i' & year==`y' predict f if industry== `i' & year==`y' predict r if industry== `i' & year==`y', resid } } f already defined r(110); gen fitted=. gen resi =. forval y=1989/2012 { forval i= 1/55 { reg DV IV_1 IV_2 IV_3 if industry== `i' & year==`y' predict f `i' `y' predict r `i' `y', resid replace fitted= f if industry== `i' & year==`y' replace resi = r if industry== `i' & year==`y' } } varlist not allowed r(101); gen fitted=. gen resi =. forval y=1989/2012 { forval i= 1/55 { reg DV IV_1 IV_2 IV_3 if industry== `i' & year==`y' predict f if `i' `y' predict r if `i' `y', resid replace fitted= f if industry== `i' & year==`y' replace resi = r if industry== `i' & year==`y' } } invalid '1989' r(198); Thank you, your help is highly appreciated Nahla Betelmal * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/faqs/resources/statalist-faq/ * http://www.ats.ucla.edu/stat/stata/

**Follow-Ups**:**Re: st: predict and resid in a nested loop***From:*Nick Cox <njcoxstata@gmail.com>

- Prev by Date:
**st: installation in Amazon EC2** - Next by Date:
**st: Kappa PABAK** - Previous by thread:
**st: installation in Amazon EC2** - Next by thread:
**Re: st: predict and resid in a nested loop** - Index(es):