Error messages when using Breusch-Pagan test macro

Moderators: statman, Analyst Techy, andris, Fierce, GerineL, Smash

rkarapin
Posts: 3
Joined: Wed Feb 26, 2014 7:57 pm

Error messages when using Breusch-Pagan test macro

Postby rkarapin » Wed Feb 26, 2014 8:18 pm

OS: Windows XP
SPSS version: 20
Nature of the data: 50 cases, about 30 variables, no missing data (anything else you need to know?)

I am trying to do a Breusch-Pagan-Koenker test on one of my regression models. I'm using the script provied by Marta Garcia-Granero (2002/10/28), which is widely used.

I'm encountering a series of error messages and assume that only the first one(s) are likely to be helpful. The first two are:

Run MATRIX procedure:
BP&K TESTS
==========
>Error encountered in source line # 337

>Error # 12555
>During execution of the GET statement, missing value has been encountered, but
>no MISSING subcommand is specified.
>Execution of this command stops.
>Error encountered in source line # 338

>Error # 12555
>During execution of the GET statement, missing value has been encountered, but
>no MISSING subcommand is specified.
>Execution of this command stops.
>Error encountered in source line # 339

These two messages evidently refer to these lines in the code:

get g /variables=g.
get resid /variables=resid.

Those were variables created earlier in the macro and placed in my data file (along with 5 other variables) by it. The variables are there, one value per case, with no missing values.

Apparently the macro is not finding the variables, or not finding all the values for the variables.

The GET command refers to a temporary .sav file that I've called foo.sav. That file does NOT include the g and resid variables. It only contains one row with three values in it.

So it looks like the script is creating the right variables but putting them in a place (my original data file) that the script isn't written to access; and instead it looks for them in the foo.sav file.

Maybe the script has a flaw, but that seems unlikely since many other people use it successfully. The only change I made was to the name of the output file (specifying a full path instead of just a filename.sav) because that was recommended as a way to avoid error messages. But even with the original syntax for the filename, I get the same problem -- same error messages, and the tempdata.sav file doesn't contain the variables it is seeking.

Alternatively, maybe I don't understand what's going on; that's quite possible, since I have little experience with SPSS scripts.

I'm appending the whole script (hoping it's not too much for the forum to handle) after my signature.

Thanks for any help,
Roger

-------------script follows-------------

* BREUSCH-PAGAN & KOENKER TEST MACRO *
* See 'Heteroscedasticity: Testing and correcting in SPSS'
* by Gwilym Pryce, for technical details.
* Code by Marta Garcia-Granero 2002/10/28.

* The MACRO needs 3 arguments:
* the dependent, the number of predictors and the list of predictors
* (if they are consecutive, the keyword TO can be used) .

* (1) MACRO definition (select an run just ONCE).

DEFINE bpktest(!POSITIONAL !TOKENS(1) /!POSITIONAL !TOKENS(1) /!POSITIONAL !CMDEND).
* Regression to get the residuals and residual plots.
REGRESSION
/STATISTICS R ANOVA
/DEPENDENT !1
/METHOD=ENTER !3
/SCATTERPLOT=(*ZRESID,*ZPRED)
/RESIDUALS HIST(ZRESID) NORM(ZRESID)
/SAVE RESID(residual) .
do if $casenum=1.
print /"Examine the scatter plot of the residuals to detect"
/"model misspecification and/or heteroscedasticity"
/""
/"Also, check the histogram and np plot of residuals "
/"to detect non normality of residuals "
/"Skewness and kurtosis more than twice their SE indicate non-normality ".
end if.
* Checking normality of residuals.
DESCRIPTIVES
VARIABLES=residual
/STATISTICS=KURTOSIS SKEWNESS .
* New dependent variable (g) creation.
COMPUTE sq_res=residual**2.
compute constant=1.
AGGREGATE
/OUTFILE='tempdata.sav'
/BREAK=constant
/rss = SUM(sq_res)
/N=N.
MATCH FILES /FILE=*
/FILE='tempdata.sav'.
EXECUTE.
if missing(rss) rss=lag(rss,1).
if missing(n) n=lag(n,1).
compute g=sq_res/(rss/n).
execute.
* BP&K tests.
* Regression of g on the predictors.
REGRESSION
/STATISTICS R ANOVA
/DEPENDENT g
/METHOD=ENTER !3
/SAVE RESID(resid) .
*Final report.
do if $casenum=1.
print /" BP&K TESTS"
/" ==========".
end if.
* Routine adapted from Gwilym Pryce.
matrix.
compute p=!2.
get g /variables=g.
get resid /variables=resid.
compute sq_res2=resid&**2.
compute n=nrow(g).
compute rss=msum(sq_res2).
compute ii_1=make(n,n,1).
compute i=ident(n).
compute m0=i-((1/n)*ii_1).
compute tss=transpos(g)*m0*g.
compute regss=tss-rss.
print regss
/format="f8.4"
/title="Regression SS".
print rss
/format="f8.4"
/title="Residual SS".
print tss
/format="f8.4"
/title="Total SS".
compute r_sq=1-(rss/tss).
print r_sq
/format="f8.4"
/title="R-squared".
print n
/format="f4.0"
/title="Sample size (N)".
print p
/format="f4.0"
/title="Number of predictors (P)".
compute bp_test=0.5*regss.
print bp_test
/format="f8.3"
/title="Breusch-Pagan test for Heteroscedasticity"
+ " (CHI-SQUARE df=P)".
compute sig=1-chicdf(bp_test,p).
print sig
/format="f8.4"
/title="Significance level of Chi-square df=P (H0:"
+ "homoscedasticity)".
compute k_test=n*r_sq.
print k_test
/format="f8.3"
/title="Koenker test for Heteroscedasticity"
+ " (CHI-SQUARE df=P)".
compute sig=1-chicdf(k_test,p).
print sig
/format="f8.4"
/title="Significance level of Chi-square df=P (H0:"
+ "homoscedasticity)".
end matrix.
!ENDDEFINE.



* x1 is the dependent and x2 TO x20 the predictors.

* (3) MACRO CALL (select and run).

BPKTEST PEW0813 6 AIRPOLLLN EDUC FFPRODLN LARGESTECON PARTYCONTROL ENVORG2LN.
rkarapin
Posts: 3
Joined: Wed Feb 26, 2014 7:57 pm

Re: Error messages when using Breusch-Pagan test macro

Postby rkarapin » Thu Feb 27, 2014 4:08 pm

I've now tried the White's test syntax, and get the same error message. This time, the correct variables ARE written to the temporary data file, as well as to the end of my own active data file. But the syntax doesn't seem to be able to find them, hence the missing values message.

Does that help pin down what might be the problem?

Roger

Who is online

Users browsing this forum: No registered users and 1 guest

cron