Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


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

st: Re: id-level predictions in panel data after regression


From   "Joseph Coveney" <jcoveney@bigplanet.com>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: Re: id-level predictions in panel data after regression
Date   Mon, 2 May 2011 13:12:04 +0900

George Hoffman wrote:

On a related topic to my graphing query (which was answered so expertly and
expeditiously by eric booth): 
I have panel data, multiple observations per id, and wish to generate within-id
linear fits.
	xtreg y x, fe  
will produce an average within-id regression, and following it by 
	predict p, xb
will generate the average within-id predictor. But I want an id-specific
predictor for each id.

	xtmixed y x || id:, cov(unstruc)
will produce a multilevel id-level regression, and
	predict ypred, fit level(id)
will produce fits within id's, but each fir has the same slope.

There must be a way to get a set of id-specific predictors based on independent
id-level regression (?)

--------------------------------------------------------------------------------

To do that, you need to put the slope variable into your random effects
equation, too.

Joseph Coveney

version 11.2

clear *
set more off
set seed `=date("2011-05-02", "YMD")'
set obs 200

generate double intercept_u = rnormal()
generate double slope_u = rnormal()
forvalues time = 1/5 {
    generate double observation`time' = 1 + intercept_u + ///
        `time' * slope_u + rnormal()
}
generate int cluster = _n
reshape long observation, i(cluster) j(time)
xtmixed observation c.time || cluster: time, covariance(unstructured)
predict double observation_hat, fitted level(cluster)

graph twoway scatter observation time if cluster == 1 || ///
    line observation_hat time if cluster == 1 || ///
    scatter observation time if cluster == 2 || ///
    line observation_hat time if cluster == 2, legend(off)

exit


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   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   |   Site index