Page 1 of 1

how to modify the CD test code

Posted: Mon Sep 12, 2011 8:18 am
by smseco
how i can modify the following code for perform the CD test for a panel data variable named "g" in eviews7?

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))

Re: how to modify the CD test code

Posted: Mon Sep 12, 2011 8:22 am
by EViews Gareth
Did it work?

Re: how to modify the CD test code

Posted: Mon Sep 12, 2011 9:43 am
by EViews Glenn
I"m not quite clear as to what you are trying to do. Are you trying to test on G instead of the residuals of an equation?

Re: how to modify the CD test code

Posted: Tue Sep 13, 2011 3:14 am
by smseco
Thanks for reply.
yes, it works. But i'm not sure about the validity of results.

pesaran (2004, pp. 21-23) intruduced a procedure to performing CD for "percapita output":
"We computed CD statistics both for countries within a given region, as well as
across countries from different regions, over the periods 1971-2000 and 1981-
2000. For each country, i, we first computed OLS residuals from regressions of
its log per capita output (yit) on an intercept, a linear trend, yi,t−1 and yi,t−2.
Using these residuals we then computed the various CD statistics summarized
in Table A."
I need to perform a similar "cross section dependence test" for a variable named G.

Re: how to modify the CD test code

Posted: Tue Sep 13, 2011 7:17 am
by smseco
and here is the panel workfile.

Re: how to modify the CD test code

Posted: Tue Sep 13, 2011 10:09 am
by EViews Glenn
Looks about right. The way to think about it is that the first regression that we have can be replaced by whatever you wnat. Get the residuals and then the remaining part does the actual test.

Re: how to modify the CD test code

Posted: Tue Jun 18, 2013 3:04 am
by katrin
Hi,
is there a possibility to perfom the pesaran cd test for pooled data? I've tried and failed until now. Can I perhaps modify the above code, or do I need something different?

I've got 15 cross-section identifiers and about 50 periods.
Many thanks

Re: how to modify the CD test code

Posted: Tue Jun 18, 2013 10:33 am
by EViews Glenn
Put your series in a group (say PRESID) and then run only the bottom part of the program starting at the line

Code: Select all

' compute the uncentered correlation and number of observations of the unstacked residuals by cross-section do presid.cov(out=a) ucor obs

Re: how to modify the CD test code

Posted: Wed Jun 19, 2013 10:20 pm
by katrin
Thanks for your reply.
It works :)