Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
st: RE: Re: id-level predictions in panel data after regression
From
"Hoffman, George" <[email protected]>
To
"[email protected]" <[email protected]>
Subject
st: RE: Re: id-level predictions in panel data after regression
Date
Mon, 2 May 2011 16:55:52 -0500
Joseph Coveney-
I think I may not have clarified this correctly.
My data are structured as: id time y x
xtset id time
the regressions i'm looking for are the overall y vs x, and the id-specific y vs x
the slopes are then dy/dx, not dy/dtime
does this make any sense?
Thank you
George
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Joseph Coveney
Sent: Sunday, May 01, 2011 11:12 PM
To: [email protected]
Subject: st: Re: id-level predictions in panel data after regression
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/
*
* 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/