Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[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" <>
To   <>
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)


*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index