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

st: RE: predicitng year by year values


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: predicitng year by year values
Date   Mon, 12 Jan 2004 18:46:16 -0000

You are correct that there is a problem
with your syntax. It is illegal. 

Try something more like this: 

levels year, local(Y) 
gen predict = . 

qui foreach y of local Y {
	reg y x if year == `y' 
	predict temp 
	replace predict = temp if year == `y' 
	drop temp 
}

Nick 
[email protected] 

R.E. De Hoyos

> How can I regress several cross-sections, predict the 
> values by year and
> amend them into the main dataset?
> 
> I have an unbalanced panel and I want to run a regression 
> for each year:
> 
> bys year reg y x
> 
> The point is to save the y-hat (predicted values) emanated 
> from the year by
> year regressions into a single column. I tried the 
> -foreach- command put
> apparently there is a problem with the syntax:
> 
> foreach num of local year {
> reg y(num) x
> predict y(num)
> }

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