LM test for serial correlation
Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt
-
zhenxi4875
- Posts: 7
- Joined: Sun Sep 13, 2015 10:32 am
LM test for serial correlation
Hi,
I used Eviews programming to calculate the LM test statistics for residual serial correlation. The result I calculated is different from the one provided by Eviews function. Could you please help explain to me the problem? Is it possible to find the source code of the LM test of Eviews?
rhk, rsh, rus1 rkr and rsg are returns of stock markets.
equation eq1.ls rhk rsh(-1) rus1(-1) rkr(-1) rsg(-1)
eq1.makeresids res_hk
scalar rss0_hk=eq1.@ssr
equation eq2.ls rhk rhk(-1) rsh(-1) rus1(-1) rkr(-1) rsg(-1) res_hk(-1 to -6)
scalar rss_hk=eq2.@ssr
LM=eq2.@regobs*(rss0_hk-rss_hk)/rss0_hk
LM_p=1-@cchisq(LM, !s)
The result I calculated: LM=11.28525085025668, LM_p=0.07995047663953347. While the result from the Eviews functions is
Breusch-Godfrey Serial Correlation LM Test:
F-statistic 0.217901 Prob. F(6,1032) 0.9712
Obs*R-squared 0.000000 Prob. Chi-Square(6) 1.0000
If I calculate the LM statistic from the auxiliary regression with code below:
equation eq2.ls res_hk rhk(-1) rsh(-1) rus1(-1) rkr(-1) rsg(-1) res_hk(-1 to -6)
LM=eq2.@regobs*eq2.@r2
LM_p=1-@cchisq(LM, !s)
LM=-2.19454689477545, it is impossible to get the p-value.
I used Eviews programming to calculate the LM test statistics for residual serial correlation. The result I calculated is different from the one provided by Eviews function. Could you please help explain to me the problem? Is it possible to find the source code of the LM test of Eviews?
rhk, rsh, rus1 rkr and rsg are returns of stock markets.
equation eq1.ls rhk rsh(-1) rus1(-1) rkr(-1) rsg(-1)
eq1.makeresids res_hk
scalar rss0_hk=eq1.@ssr
equation eq2.ls rhk rhk(-1) rsh(-1) rus1(-1) rkr(-1) rsg(-1) res_hk(-1 to -6)
scalar rss_hk=eq2.@ssr
LM=eq2.@regobs*(rss0_hk-rss_hk)/rss0_hk
LM_p=1-@cchisq(LM, !s)
The result I calculated: LM=11.28525085025668, LM_p=0.07995047663953347. While the result from the Eviews functions is
Breusch-Godfrey Serial Correlation LM Test:
F-statistic 0.217901 Prob. F(6,1032) 0.9712
Obs*R-squared 0.000000 Prob. Chi-Square(6) 1.0000
If I calculate the LM statistic from the auxiliary regression with code below:
equation eq2.ls res_hk rhk(-1) rsh(-1) rus1(-1) rkr(-1) rsg(-1) res_hk(-1 to -6)
LM=eq2.@regobs*eq2.@r2
LM_p=1-@cchisq(LM, !s)
LM=-2.19454689477545, it is impossible to get the p-value.
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13604
- Joined: Tue Sep 16, 2008 5:38 pm
Re: LM test for serial correlation
Check the User Guide discussion relating to pre-sample values of the residuals.
-
zhenxi4875
- Posts: 7
- Joined: Sun Sep 13, 2015 10:32 am
Re: LM test for serial correlation
Thank you for your reply!Check the User Guide discussion relating to pre-sample values of the residuals.
I have read the Eviews help for several times. Is that "EViews sets any presample values of the residuals to 0" what you mean? In this case, could you help suggest how to modify my code to get the same result as Eviews function?
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13604
- Joined: Tue Sep 16, 2008 5:38 pm
Re: LM test for serial correlation
Without the full program it is hard to say, but you need to set your residual series to zero for any observations prior to the estimation sample.
-
zhenxi4875
- Posts: 7
- Joined: Sun Sep 13, 2015 10:32 am
Re: LM test for serial correlation
Thank you!Without the full program it is hard to say, but you need to set your residual series to zero for any observations prior to the estimation sample.
Attached please see the workfile and the full program.
To set the prior residual into zero, I used command X=@nan(X,0). But it could not work for a lag order X(-1 to -6)=@nan(X(-1 to -6),0). Could you help advise how to set the NA into zero for this case and see how to modify the code to get the same result as Eviews' LM test function?
- Attachments
-
- grangera.wf1
- (192.95 KiB) Downloaded 305 times
-
- single_eq_a.prg
- (859 Bytes) Downloaded 319 times
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13604
- Joined: Tue Sep 16, 2008 5:38 pm
Re: LM test for serial correlation
Just use
Code: Select all
res_hk=@nan(res_hk,0)
-
zhenxi4875
- Posts: 7
- Joined: Sun Sep 13, 2015 10:32 am
Re: LM test for serial correlation
oh yes, I can use res_hk=@nan(res_hk,0) before I start the auxiliary regression.
However, the LM statistic I calculate is -2.19454689477568, not matching to the Eviews result. Could you help have a look? If possible, could you show the source code of LM test of Eviews to me so that I can figure it out?
However, the LM statistic I calculate is -2.19454689477568, not matching to the Eviews result. Could you help have a look? If possible, could you show the source code of LM test of Eviews to me so that I can figure it out?
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13604
- Joined: Tue Sep 16, 2008 5:38 pm
Re: LM test for serial correlation
Check that the regressors in the auxiliary regression are correct.
-
zhenxi4875
- Posts: 7
- Joined: Sun Sep 13, 2015 10:32 am
Re: LM test for serial correlation
I confirm the regressors in the auxiliary regression is correct as per the attached code.
I am new to the programming of Eviews. My intention was to conduct LM test for lag order from 1 to 6, so I use the for loop.
In the attached code, the @nan could not be used with lag order, so I generate 6 residual series with zero presample for the case of lag order 6. Could you help have a look at my code? I have been waiting in front of the computer for the whole day.
I am new to the programming of Eviews. My intention was to conduct LM test for lag order from 1 to 6, so I use the for loop.
In the attached code, the @nan could not be used with lag order, so I generate 6 residual series with zero presample for the case of lag order 6. Could you help have a look at my code? I have been waiting in front of the computer for the whole day.
- Attachments
-
- grangera.wf1
- (192.95 KiB) Downloaded 270 times
-
- single_eq_a.prg
- (1.04 KiB) Downloaded 293 times
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13604
- Joined: Tue Sep 16, 2008 5:38 pm
Re: LM test for serial correlation
You only need to use @nan once:
Then use res_hk as the dependent variable, and lags of it as the regressors.
Also, double check that the regressors match those used in the EViews output.
Code: Select all
'restricted version
equation eq1.ls rhk rsh(-1 to -!m0) rus1(-1 to -!m0) rkr(-1 to -!m0) rsg(-1 to -!m0)
eq1.makeresids res_hk
smpl @all
res_hk = @nan(res_hk,0)
smpl 1/02/2003 12/29/2006
scalar rss0_hk=eq1.@ssr
Also, double check that the regressors match those used in the EViews output.
-
zhenxi4875
- Posts: 7
- Joined: Sun Sep 13, 2015 10:32 am
Re: LM test for serial correlation
Thank you for your explanation.
I apologized that I had a mistake in the code I uploaded to you. I didn't include rhk(-1) as regressor in the restricted regression. I did the test again with res_hk as dependent variable and compare to the Eviews output with the same setting. The LM test results are still different.
Results from my code: LM=7.39201784454314, p-value=0.2861091527043986.
Eviews output:
Breusch-Godfrey Serial Correlation LM Test:
F-statistic 0.402596 Prob. F(6,1031) 0.8776
Obs*R-squared 0.000000 Prob. Chi-Square(6) 1.0000
Test Equation:
Dependent Variable: RESID
Method: Least Squares
Date: 09/15/15 Time: 03:20
Sample: 1/02/2003 12/29/2006
Included observations: 1042
Presample missing value lagged residuals set to zero.
Variable Coefficient Std. Error t-Statistic Prob.
RHK(-1) -0.400550 0.354108 -1.131154 0.2583
RSH(-1) 0.002066 0.023076 0.089517 0.9287
RUS1(-1) 0.006175 0.041142 0.150085 0.8807
RKR(-1) 0.002253 0.028117 0.080133 0.9361
RSG(-1) -0.003888 0.045222 -0.085976 0.9315
RESID(-1) 0.403567 0.353922 1.140272 0.2544
RESID(-2) -0.003696 0.037174 -0.099438 0.9208
RESID(-3) 0.002095 0.031322 0.066885 0.9467
RESID(-4) -0.005384 0.031266 -0.172185 0.8633
RESID(-5) 0.010939 0.031355 0.348869 0.7273
RESID(-6) -0.014347 0.031344 -0.457738 0.6472
R-squared -0.002612 Mean dependent var 0.000644
Adjusted R-squared -0.012336 S.D. dependent var 0.009148
S.E. of regression 0.009205 Akaike info criterion -6.527704
Sum squared resid 0.087353 Schwarz criterion -6.475460
Log likelihood 3411.934 Hannan-Quinn criter. -6.507887
Durbin-Watson stat 1.999986
I apologized that I had a mistake in the code I uploaded to you. I didn't include rhk(-1) as regressor in the restricted regression. I did the test again with res_hk as dependent variable and compare to the Eviews output with the same setting. The LM test results are still different.
Results from my code: LM=7.39201784454314, p-value=0.2861091527043986.
Eviews output:
Breusch-Godfrey Serial Correlation LM Test:
F-statistic 0.402596 Prob. F(6,1031) 0.8776
Obs*R-squared 0.000000 Prob. Chi-Square(6) 1.0000
Test Equation:
Dependent Variable: RESID
Method: Least Squares
Date: 09/15/15 Time: 03:20
Sample: 1/02/2003 12/29/2006
Included observations: 1042
Presample missing value lagged residuals set to zero.
Variable Coefficient Std. Error t-Statistic Prob.
RHK(-1) -0.400550 0.354108 -1.131154 0.2583
RSH(-1) 0.002066 0.023076 0.089517 0.9287
RUS1(-1) 0.006175 0.041142 0.150085 0.8807
RKR(-1) 0.002253 0.028117 0.080133 0.9361
RSG(-1) -0.003888 0.045222 -0.085976 0.9315
RESID(-1) 0.403567 0.353922 1.140272 0.2544
RESID(-2) -0.003696 0.037174 -0.099438 0.9208
RESID(-3) 0.002095 0.031322 0.066885 0.9467
RESID(-4) -0.005384 0.031266 -0.172185 0.8633
RESID(-5) 0.010939 0.031355 0.348869 0.7273
RESID(-6) -0.014347 0.031344 -0.457738 0.6472
R-squared -0.002612 Mean dependent var 0.000644
Adjusted R-squared -0.012336 S.D. dependent var 0.009148
S.E. of regression 0.009205 Akaike info criterion -6.527704
Sum squared resid 0.087353 Schwarz criterion -6.475460
Log likelihood 3411.934 Hannan-Quinn criter. -6.507887
Durbin-Watson stat 1.999986
- Attachments
-
- single_eq_a.prg
- (914 Bytes) Downloaded 327 times
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13604
- Joined: Tue Sep 16, 2008 5:38 pm
Re: LM test for serial correlation
In cases where there obs*R^2 version fails (i.e. produces a negative statistic), EViews just sets it to zero.
-
startz
- Non-normality and collinearity are NOT problems!
- Posts: 3798
- Joined: Wed Sep 17, 2008 2:25 pm
Re: LM test for serial correlation
Apropos of Gareth's last point, are you sure you don't want a constant in the original regression?
-
zhenxi4875
- Posts: 7
- Joined: Sun Sep 13, 2015 10:32 am
Re: LM test for serial correlation
Dear EViews Gareth and startz,
Thank you for your patient and clarification!
Without an intercept, the result of my code is different from Eviews output (this is clarified by Gareth). By including an intercept, the results are the same. I really appreciate your help!
Thank you for your patient and clarification!
Without an intercept, the result of my code is different from Eviews output (this is clarified by Gareth). By including an intercept, the results are the same. I really appreciate your help!
Who is online
Users browsing this forum: No registered users and 2 guests
