Hi, I'm currently doing an introductory econometrics class.
In this assignment we have to do 1000 simulations on three different sample sizes.
This is done via two for-loops (Ts = column vector containing the three sample sizes):
where the AR_gen function is made previous in the do.file:
The do.file starts with the 'mata' command and ends with 'end'.
When i run the do.file it instantly reports back 'unexpected end of line', but it seems that everything before the loop has been processed.
It saved all the zero-matrices i made to store the betas, tstats, DW and R2 in.
Im quite a novice at both Mata and econometrics and I just can't figure out where i made a mistake or why mata doesn't try to iterate the actions in the loops
Any help appreciated
In this assignment we have to do 1000 simulations on three different sample sizes.
This is done via two for-loops (Ts = column vector containing the three sample sizes):
Code:
for(j=1; j<=length(Ts);j++) { // select the current sample size T = Ts[1,j] //loop for the replications for(i=1; i<=M; i++) { // random number generation y = AR_gen(1,T) x = AR_gen(1,T) //OLS regression X = J(T,1,1), x aux_ols = luinv(cross(X,X)*cross(X,y) beta[i,j] = aux_ols[2,1] // tstat err = y-X*aux_ols RSS = cross(err,err) sigma = luinv(cross(X,X))*RSS/(T-2) tstat[i,j] = beta[i,j]/sqrt(sigma[2,2]) // R2 TSS = cross(y-mean(y)*J(T,1,1),y-mean(y)*J(T,1,1)) R2[i,j] = 1- RSS/TSS // DW DW[i,j] = cross(err[2::T,1]-err[1::T-1,1],err[2::T,1]-err[1::T-1,1])/RSS } }
Code:
function AR_gen(phi, T) { c = J(T+1,1,0) eps = rnormal(T,1,0,1) c[1,1] = 0 // 0, 0.S/(1-phi) for (i = 1; i<=T; i++) { c[i+1,1] = phi*c[i,1]+eps[i,1] } v = c[2::T+1,1] return(v) }
When i run the do.file it instantly reports back 'unexpected end of line', but it seems that everything before the loop has been processed.
It saved all the zero-matrices i made to store the betas, tstats, DW and R2 in.
Im quite a novice at both Mata and econometrics and I just can't figure out where i made a mistake or why mata doesn't try to iterate the actions in the loops
Any help appreciated
Comment