Monte - Carlo experiment Help?

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt

tomdavies5
Posts: 1
Joined: Thu Jan 02, 2014 1:02 pm

Monte - Carlo experiment Help?

Postby tomdavies5 » Thu Jan 02, 2014 1:11 pm

This is my program, with x10 being an imported file of random numbers, 10 observation (!n=10)
When i try to increase !s = .... it gives me the error message
"21 is not a valid index for vector-series-coefficient B1 HAT in "B1Hat(21) = EQ.@COEFS(1)""
I need to beable to run the program at ever larger values of !s but this is stopping me from doing it, any help?
Here is my program
!n=10
!s=2000
if !n>!s then
!r=!n
else
!r=!s
endif
cd "H:\mc_exe"
workfile project u 1 !r
smpl 1 !n
'read the explanatory variable from the file generated by mc_genx.prg into a series called x
read(skipcol=1,skiprow=2) x10.csv x1 x2

vector(3) b 'create a vector to store the true value of intercept and slope
b(1)=1 'true value of intercept
b(2)=2 'true value of the slope
b(3)=3
scalar sigma=10 'true value of sigma
scalar sigmasq=sigma^2 'true value of sigma square

series ey=b(1)+b(2)*x1+b(3)*x2 'the expected mean of y
series intpt=1 'the intercept
group xg intpt x1 x2 'create a group called xg with intpt and xs as columns
stom(xg,xm) 'transform xg into the explanatory variable matrix x
matrix varb=sigmasq*@inverse(@transpose(xm)*xm)'the true variance-covariance matrix of beta_hat
scalar sdb1=varb(1,1)^0.5 'the true standard deviation of the intercept estimator
scalar sdb2=varb(2,2)^0.5 'the true standard deviation of the slope estimator
scalar sdb3=varb(3,3)^0.5

scalar df=!n-3 'degrees of freedom
scalar a=0.05 'set the level of significance
'calculate the critical values for the t-distribution
scalar tlb=@qtdist(a/2,df) 'the t critical value, 2.5% quantile if a=0.05
scalar tub=@qtdist(1-a/2,df) 'the t critical value, 97.5% quantile if a=0.05
'change the range of the work file and initialize the series to store the estimated values
smpl 1 !s
series b1hat=0 'this is to store the estimated values of intercept
series seb1hat=0 'this is to store the estimated standard error of the intercept estimator
series b2hat=0 'this is to store the estimated values of slope
series seb2hat=0 'this is to store the estimated standard error of the slope estimator
series b3hat=0
series seb3hat=0
series sigmahat=0 'this is to store the estimated values of sigma
series sigmasqhat=0 'this is to store the estimated values of sigma square
scalar t1err=0 'this is to store how many Type I errors committed
series b1hatwl=0 'this is to store the estimated values of intercept
series seb1hatwl=0 'this is to store the estimated standard error of the intercept estimator
series b2hatwl=0 'this is to store the estimated values of slope
series seb2hatwl=0 'this is to store the estimated standard error of the slope estimator
series b3hatwl=0
series seb3hatwl=0
series sigmahatwl=0 'this is to store the estimated values of sigma
series sigmasqhatwl=0 'this is to store the estimated values of sigma square
scalar t1err=0 'this is to store how many Type I errors committed
smpl 1 !n
series y=0 'initialize the dependent variable
'the for loop for simulations, do it !s times
for !i=1 to !s
smpl 1 !n
y=ey+@nrnd*x2^0.5 'generate the dependent variable
equation eq.ls y c x1 x2 'create an equation call eq and run the ols
equation eqwl.ls y/x2^0.5 1/x2^.5 x1/x2^0.5 x2/x2^0.5
smpl 1 !s
b1hat(!i) = eq.@coefs(1) 'store the intercept estimate
seb1hat(!i)=eq.@stderrs(1) 'store the intercept estimated standard deviation
b2hat(!i) = eq.@coefs(2) 'store the slope estimate
seb2hat(!i)=eq.@stderrs(2) 'store the slope estimated standard deviation
b3hat(!i) = eq.@coefs(3)
seb3hat(!i)=eq.@stderrs(3)
sigmahat(!i)=eq.@se 'store the estimated standard deviation of regression
b1hatwl(!i)=eqwl.@coefs(1)
seb1hatwl(!i)=eqwl.@stderrs(1)
b2hatwl(!i)=eqwl.@coefs(2)
seb2hatwl(!i)=eqwl.@stderrs(2)
b3hatwl(!i)=eqwl.@coefs(3)
seb3hatwl(!i)=eqwl.@stderrs(3)
sigmahatwl(!i)=eqwl.@se
sigmasqhat(!i)=sigmahat(!i)^2
sigmasqhatwl(!i)=sigmahatwl(!i)^2 'store the estimated variance of regression
next

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13604
Joined: Tue Sep 16, 2008 5:38 pm

Re: Monte - Carlo experiment Help?

Postby EViews Gareth » Thu Jan 02, 2014 5:44 pm

Use vectors to store your results rather than series


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests