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

st: RE: Nick: RE: Programing question


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: Nick: RE: Programing question
Date   Tue, 15 Apr 2003 12:53:26 +0100

Fernando Penalva wrote, modulo deprecated MIME/HTML, 

I don't know how to run a regression 
of Y on X for each FIRMID and ENDDATE so that 
each regression uses as observations the current 
observation and the previous 60 within the FIRMID group. 
On top of that I want to store the coefficient on X 
for each regression.

>>> Stata 8 assumed (Statalist default). 

A very rough guess: 

sort firmid enddate 

ssc inst levels 
levels firmid, local(ids) 

gen coef = . 
gen obsno = _n 

qui foreach id of local ids { 
	su obsno if firmid == `id', meanonly 
	local j1 = r(min) + 59  
	local j2 = r(max) 
	forval j = `j1' / `j2' { 
		local i = `j' - 59 
		regress Y X if inrange(obsno,`i',`j') 
		replace coef = _b[X] in `j' 
	}
} 

Note that the coefficients will be autocorrelated 
in a way that inhibits some further analyses. 
	
Nick 
[email protected] 

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