Code: Select all
' select the original panel page
pageselect panel
' estimate the original equation with fixed effects
equation eq01.ls(cx=f) impor rd frd c
' make the residuals in stacked form
eq01.makeresid presid
' unstack into a new page page
pageunstack(page=unstack) id01 id02 @ presid
' compute the uncentered correlation and number of observations of the unstacked residuals by cross-section
do presid.cov(out=a) ucor obs
' get number of groups
scalar n = @columns(acorr)
' get vech of observations
vector t = @vech(aobs)
' adjust correlation matrix to zero out diagonals
acorr = acorr - @identity(n)
' get the vech of the correlation matrix and the squared vech
vector vcor = @vech(acorr)
vector vcor2 = @epow(vcor, 2)
' compute the scaled Breusch-Pagan LM stat (generalized slightly for unbalanced)
scalar cdlm = @inner(vcor2, t) - n*(n-1)/2
cdlm = cdlm / @sqrt(n * (n-1))
scalar cdlmpval = 2*@cnorm(-@abs(cdlm))
' compute the Pesaran CD test
vector sqrtt = @sqrt(t)
scalar cd= @inner(vcor, sqrtt)
cd = cd * @sqrt(2 / (n * (n-1)))
scalar cdpval = 2*@cnorm(-@abs(cd))[/color]
i changed the " impor rd frd c" to "g c g(-1) g(-2) @trend " and the "id01 id02" to "crossid datied" is it true?
Code: Select all
' select the original panel page
pageselect panel
' estimate the original equation with fixed effects
equation eq01.ls(cx=f) g c g(-1) g(-2) @trend
' make the residuals in stacked form
eq01.makeresid presid
' unstack into a new page page
pageunstack(page=unstack) crossid datied @ presid
' compute the uncentered correlation and number of observations of the unstacked residuals by cross-section
do presid.cov(out=a) ucor obs
' get number of groups
scalar n = @columns(acorr)
' get vech of observations
vector t = @vech(aobs)
' adjust correlation matrix to zero out diagonals
acorr = acorr - @identity(n)
' get the vech of the correlation matrix and the squared vech
vector vcor = @vech(acorr)
vector vcor2 = @epow(vcor, 2)
' compute the scaled Breusch-Pagan LM stat (generalized slightly for unbalanced)
scalar cdlm = @inner(vcor2, t) - n*(n-1)/2
cdlm = cdlm / @sqrt(n * (n-1))
scalar cdlmpval = 2*@cnorm(-@abs(cdlm))
' compute the Pesaran CD test
vector sqrtt = @sqrt(t)
scalar cd= @inner(vcor, sqrtt)
cd = cd * @sqrt(2 / (n * (n-1)))
scalar cdpval = 2*@cnorm(-@abs(cd))
