Hi, Tom. Thank you for the reply.
I have changed the code like you said such that I use the set instruction before the loop and compute inside the loop. I seems to work for the beta coefficients. However, I am also supposed to create the expression:
sqrt(n)*(betahat-beta)
and see whether that converges in distribution by creating a histogram for it besides the histogram for beta2.
In the code you can see that I declare a vector nbeta2 with 10000 places to accomodate for the fact that the expression above requires correct dimensions. My code is now (as you can see I have also begun to graph the histogram of beta2 but I'm not finished with that since I have been trying to graph a normal distribution in the same picture using the example on page 229 in the Reference manual; I havent got that to work quite yet):
Code: Select all
compute ndraws=10000
compute iobs=100
allocate iobs
set beta1 1 ndraws = 0.0
set beta2 1 ndraws = 1.0
declare vector nbeta2(10000)
do draws=1, ndraws
set x = %ran(2.0)
set u = %ran(1.0)
set y = beta1+beta2*x+u
linreg(noprint) y
# constant x
compute beta2(draws)=%beta(2)
compute nbeta2=(sqrt(iobs))*(%beta(2)-beta2)
end do draws
statistics beta2
density(type=histogram) beta2 1 ndraws xbeta2 fbeta2
spgraph
scatter(style=bargraph,overlay=line,ovsamescale, header="Case 1. Distribution of the beta 2 estimate with i=100")
# xbeta2 fbeta2
display(store=s) "Skewness" %skewness $
"\\Excess Kurtosis" %kurtosis
grtext(position=upright) s
spgraph(done)
However, it comes up with an error message MAT2 stating problems with the dimensions involved in the subtraction operation inside the loop. As far as I can see the problem is that %beta(2) is an 10000x1 vector but my beta2 which I have set before the loop is a scalar. Is that right and what am I doing wrong then? I would like to have a series which I can graph just like the beta estimates.
Aside from this simulation I am supposed to do the same for two other cases. On in which the x's are still normally distributed but where the u's are drawn from a t-distribution. I have attached that code as Case 2. The problem is that I get a really strange picture of the estimates of beta. It's more or less just a degenerate distribution. The only thing I can draw upon would be the book by Hamilton(1994) on page 209-209 where he says that if the x's are stochastic and the errors are non-Gaussian the unconditional distribution of beta will be non-Gaussian but that the estimator will be consistent. And I can certainly see that what I have graphed is non-Gaussian!! but certainly also non-consistent since it seems to center around 0 instead of 1.
Case 3 involves drawing the u's from a normal distribution but specifying the x series as a random walk:
x=x{1}+epsilon
I have replicated a little bit from the code of Johnp351.prg which you referred me to since I solve and express the x series as a sum of the epsilons. I do this instead of setting x=x{1}+epsilon because the programme gets confused about where to find the x series.
I attached that code as well. The problem is that i get the same consistency problem here as in case 2 since it centers around 0 instead of 1.
I know this is a lot to state in one reply and it's not like you have to do the assignment for me. If you can just check if I'm doing something terribly wrong. Let me sum up my questions.
1) In all cases, how can I generate an expression sqrt(n)*(betahat-beta) and picture it like the beta estimates.
2) In case 2, how come I get such a strange looking figure with total mass around 0 instead of 1. Hamilton writes that it will be unbiased and non-Gaussian. Non-Gaussianity seems to be fulfilled but my estimates look really biased.
3) I case 3, am I doing the code right when generating the random walk x series and how come I get a strange looking figure as in case 2? I know that Hamilton writes that I'm supposed to get biasedness with dependent series. But could I be doing something wrong?