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" <>
To   <>
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. 

*   For searches and help try:

© Copyright 1996–2015 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index