Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: rolling prais regression in paneld dataset


From   "Scott Merryman" <smerryman@kc.rr.com>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: rolling prais regression in paneld dataset
Date   Mon, 17 Jul 2006 09:05:25 -0500

Does -rolling- know you have panel data?

Another way to accomplish this is to use -postfile- to collect the estimated
coefficient and -predict- the residuals and predicted values for each
individual.

For example:

webuse grunfeld, clear 

tempfile results 
tempname hold 

postfile `hold'  constant coef  rho using `results'
qui {
gen predicted = .
gen residual = .
forv i = 1/10   { 
	prais invest mvalue if com == `i'
	local const = _b[_cons]
	local coef = _b[mvalue]
	local rho = e(rho)
	predict pred if com == `i'
	predict resid if  e(sample), r
	replace predicted = pred if com == `i'
	replace residual =resid if com == `i'
	drop pred resid
	post `hold' (`const') (`coef') (`rho') 
      }
 }
save predicted, replace
postclose `hold'
preserve
use `results', clear
save roll,replace
restore


Scott


> -----Original Message-----
> From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-
> statalist@hsphsun2.harvard.edu] On Behalf Of ocg2001@columbia.edu
> Sent: Sunday, July 16, 2006 12:00 PM
> To: statalist@hsphsun2.harvard.edu
> Subject: st: rolling prais regression in paneld dataset
> 
> Hi I am using Stata9's new rolling capability with prais regression
> on a panel dataset (unbalanced panal with about 10,000 individuals
> and roughly 15 years for each).
> 
> Stata-tech support helped me write a little program that collects,
> in addition to coefficients of the regression, its predicted values
> and residuals. But the program doesn't seem to work well, and I am
> not sure where the bug is, I tried recontacting tech support, but
> so far no answer. Here is my code, any help would be greately
> appreciated:
> *************************
> 
> tsset person year
> 
> program myforecast, rclass
> 	syntax [if]
> 	prais r exp `if'
> 	summ year if e(sample)
> 	local min=r(min)
> 	predict pred`min' if e(sample)
> 	predict resid`min' if e(sample), r
> 	return scalar n=r(N)
> 	return scalar rho=e(rho)
> end
> 
> 
> rolling rho=r(rho) n=r(n), window(15) ///
> 	saving(roll, replace): myforecast
> save pred, replace
> *****************************
> 
> 
> Olga Gorbachev Melloni
> Economics Ph.D. Student
> Columbia University
> www.columbia.edu/~ocg2001
> 


*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index