Error in sample: Range Error
Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt
-
philipgouldshefuni
- Posts: 6
- Joined: Wed Aug 25, 2010 5:14 am
Error in sample: Range Error
I am attemtping to run a bivariate DCC- Garch model in order to test correlation between two stock markets during the period 01/06/2005 and 08/27/2009. The program I am using works perfectly until I attempt to estimate the model. Here i am recieveing the error code,
Error in Sample : Range Error in "sample S1 2 243".
I have tried everything to alleviate this problem but nothing seems to be working. Is this a problem with my program or is this a problem with the range I have set or my data??
Any help with this will be greatly appreciated. The program i am using is pasted below.
'set sample range
sample s1 01/06/2005 08/27/2009
scalar pi=3.14159
'defining the return series in terms of y1 and y2
series y1=sp500
series y2=bse
'fitting univariate GARCH(1,1) models to each of the two returns series
equation eq_y1.arch(1,1,m=1000,h) y1 c
equation eq_y2.arch(1,1,m=1000,h) y2 c
'extract the standardized residual series from the GARCH fit
eq_y1.makeresids(s) z1
eq_y2.makeresids(s) z2
'extract garch series from univariate fit
eq_y1.makegarch() garch1
eq_y2.makegarch() garch2
'Caculate sample variance of series z1, z2 and covariance of z1and z2 and correlation between z1 and z2
scalar var_z1=@var(z1)
scalar var_z2=@var(z2)
scalar cov_z1z2=@cov(z1,z2)
scalar corr12=@cor(z1,z2)
'defining the starting values for the var(z1) var(z2) and covariance (z1,z2)
series var_z1t=var_z1
series var_z2t=var_z2
series cov_z1tz2t=cov_z1z2
'declare the coefficient starting values
coef(2) T
T(1)=0.2
T(2)=0.7
' ...........................................................
' LOG LIKELIHOOD for correlation part
' set up the likelihood
' 1) open a new blank likelihood object and name it 'dcc'
' 2) specify the log likelihood model by append
' ...........................................................
logl dcc
dcc.append @logl logl
'specify var_z1t, var_z2t, cov_z1tz2t
dcc.append var_z1t=@nan(1-T(1)-T(2)+T(1)*(z1(-1)^2)+T(2)*var_z1t(-1),1)
dcc.append var_z2t=@nan(1-T(1)-T(2)+T(1)*(z2(-1)^2)+T(2)*var_z2t(-1),1)
dcc.append cov_z1tz2t=@nan((1-T(1)-T(2))*corr12+T(1)*z1(-1)*z2(-1)+T(2)*cov_z1tz2t(-1),1)
dcc.append pen=(var_z1t<0)+(var_z2t<0)
'specify rho12
dcc.append rho12=cov_z1tz2t/@sqrt(@abs(var_z1t*var_z2t))
'defining the determinant of correlation matrix and determinant of Dt
dcc.append detrRt=(1-(rho12^2))
dcc.append detrDt=@sqrt(garch1*garch2)
dcc.append pen=pen+(detrRt<0)
dcc.append detrRt=@abs(detrRt)
'define the log likelihood function
dcc.append logl=(-1/2)*(2*log(2*pi)+log(detrRt)+(z1^2+z2^2-2*rho12*z1*z2)/detrRt)-10*pen
'estimate the model
sample s1 2 253
smpl s1
dcc.ml(showopts, m=500, c=1e-5)
smpl @all
'display output and graphs
show dcc.output
graph corr.line rho12
show corr
Error in Sample : Range Error in "sample S1 2 243".
I have tried everything to alleviate this problem but nothing seems to be working. Is this a problem with my program or is this a problem with the range I have set or my data??
Any help with this will be greatly appreciated. The program i am using is pasted below.
'set sample range
sample s1 01/06/2005 08/27/2009
scalar pi=3.14159
'defining the return series in terms of y1 and y2
series y1=sp500
series y2=bse
'fitting univariate GARCH(1,1) models to each of the two returns series
equation eq_y1.arch(1,1,m=1000,h) y1 c
equation eq_y2.arch(1,1,m=1000,h) y2 c
'extract the standardized residual series from the GARCH fit
eq_y1.makeresids(s) z1
eq_y2.makeresids(s) z2
'extract garch series from univariate fit
eq_y1.makegarch() garch1
eq_y2.makegarch() garch2
'Caculate sample variance of series z1, z2 and covariance of z1and z2 and correlation between z1 and z2
scalar var_z1=@var(z1)
scalar var_z2=@var(z2)
scalar cov_z1z2=@cov(z1,z2)
scalar corr12=@cor(z1,z2)
'defining the starting values for the var(z1) var(z2) and covariance (z1,z2)
series var_z1t=var_z1
series var_z2t=var_z2
series cov_z1tz2t=cov_z1z2
'declare the coefficient starting values
coef(2) T
T(1)=0.2
T(2)=0.7
' ...........................................................
' LOG LIKELIHOOD for correlation part
' set up the likelihood
' 1) open a new blank likelihood object and name it 'dcc'
' 2) specify the log likelihood model by append
' ...........................................................
logl dcc
dcc.append @logl logl
'specify var_z1t, var_z2t, cov_z1tz2t
dcc.append var_z1t=@nan(1-T(1)-T(2)+T(1)*(z1(-1)^2)+T(2)*var_z1t(-1),1)
dcc.append var_z2t=@nan(1-T(1)-T(2)+T(1)*(z2(-1)^2)+T(2)*var_z2t(-1),1)
dcc.append cov_z1tz2t=@nan((1-T(1)-T(2))*corr12+T(1)*z1(-1)*z2(-1)+T(2)*cov_z1tz2t(-1),1)
dcc.append pen=(var_z1t<0)+(var_z2t<0)
'specify rho12
dcc.append rho12=cov_z1tz2t/@sqrt(@abs(var_z1t*var_z2t))
'defining the determinant of correlation matrix and determinant of Dt
dcc.append detrRt=(1-(rho12^2))
dcc.append detrDt=@sqrt(garch1*garch2)
dcc.append pen=pen+(detrRt<0)
dcc.append detrRt=@abs(detrRt)
'define the log likelihood function
dcc.append logl=(-1/2)*(2*log(2*pi)+log(detrRt)+(z1^2+z2^2-2*rho12*z1*z2)/detrRt)-10*pen
'estimate the model
sample s1 2 253
smpl s1
dcc.ml(showopts, m=500, c=1e-5)
smpl @all
'display output and graphs
show dcc.output
graph corr.line rho12
show corr
-
startz
- Non-normality and collinearity are NOT problems!
- Posts: 3797
- Joined: Wed Sep 17, 2008 2:25 pm
Re: Error in sample: Range Error
What does EViews show for the workfile range at the top of the workfile window?
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13603
- Joined: Tue Sep 16, 2008 5:38 pm
Error in sample: Range Error
At a guess, you have a dated workfile, thus you have to use dates to set the samle
-
philipgouldshefuni
- Posts: 6
- Joined: Wed Aug 25, 2010 5:14 am
Re: Error in sample: Range Error
The range at the top of the file shows 1/6/2005 9/2/2009 -- 243. I have used weekly data through the period 1/6/2005 8/27/2009.
I have tried changing the workfile range dates and sample dates.
Could this be a problem be allviated by importing all the data as a STATA data file so the date is already attached to the other data?
I have tried changing the workfile range dates and sample dates.
Could this be a problem be allviated by importing all the data as a STATA data file so the date is already attached to the other data?
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13603
- Joined: Tue Sep 16, 2008 5:38 pm
Re: Error in sample: Range Error
No, the problem is as I stated above. You have a dated workfile, yet your command:
is trying to set the sample without using dates. You must used dates in the sample command if your workfile is dated.
You got it right in your first sample statement:
Code: Select all
sample s1 2 253
You got it right in your first sample statement:
Code: Select all
sample s1 01/06/2005 08/27/2009
-
philipgouldshefuni
- Posts: 6
- Joined: Wed Aug 25, 2010 5:14 am
Re: Error in sample: Range Error
I have tried this repeatedly but unfortuantely get the same error message.
-
startz
- Non-normality and collinearity are NOT problems!
- Posts: 3797
- Joined: Wed Sep 17, 2008 2:25 pm
Re: Error in sample: Range Error
Did you change your second sample command to use dates?
-
philipgouldshefuni
- Posts: 6
- Joined: Wed Aug 25, 2010 5:14 am
Re: Error in sample: Range Error
as in the one used to estimate the model? yes i have changed that to
sample s1 2 1/06/ etc
i have also tried
sample s1 1/06 etc
neither work i still recieve the same error message
sample s1 2 1/06/ etc
i have also tried
sample s1 1/06 etc
neither work i still recieve the same error message
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13603
- Joined: Tue Sep 16, 2008 5:38 pm
Re: Error in sample: Range Error
Why don't you tell us exactly what you have tried.
-
philipgouldshefuni
- Posts: 6
- Joined: Wed Aug 25, 2010 5:14 am
Re: Error in sample: Range Error
I have tried changing the dates in the program code, changing the observations in the program code. Changing the dates/obs in the workfile. I have attached my workfile.
- Attachments
-
- PGouldworkfile.WF1
- (41.32 KiB) Downloaded 465 times
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13603
- Joined: Tue Sep 16, 2008 5:38 pm
Re: Error in sample: Range Error
Try changing the line:
to be:
Then, tell us what happens.
Code: Select all
sample s1 2 253
Code: Select all
sample s1 01/07/2005 08/27/2009
-
philipgouldshefuni
- Posts: 6
- Joined: Wed Aug 25, 2010 5:14 am
Re: Error in sample: Range Error
I have managed to sort it out now. I have dropped the date from the workfile and merely used the number of observations. Using sample s1 2 242 now works and i have the results i needed.
Thank you very much for your time.
Philip
Thank you very much for your time.
Philip
Who is online
Users browsing this forum: No registered users and 1 guest
