PROCEDURE Writing

Use this forum to post questions about syntax problems or general programming issues. Questions on implementing a particular aspect of econometrics should go in "Econometrics Issues" below.
HypatiaCU
Posts: 12
Joined: Mon Nov 12, 2012 6:02 pm

PROCEDURE Writing

Unread post by HypatiaCU »

Hi

I am trying to write a procedure, but it doesn't work out well. If I put the code directly into the program it works fine, it doesn't work as a SRC file. I never write a procedure before. I think there is something I missed at the beginning. I don't know how to use 'local' or 'option'. Are those coding necessary?

Code: Select all

PROCEDURE ENGELT3 X1 X2 X3 START END
*TYPE SERIES X1 X2 X3
LOCAL SERIES X1 X2 X3  

TYPE INTEGER START END
local series test DX1 DX2 DX3 ERX LAMBDA 
*
system(model=bootvar1)
var X1 X2 X3
lags 1 to 3
det constant
end(system)
estimate(residuals=residsvarx1, coefficients=Ax1,noprint)
* 

set ERX start end = X2 - residsvarx1(2)
*
STATS x1 start end
COMPUTE meanx1=%mean
set dx1 start end = x1- meanx1
STATS x2 start end
COMPUTE meanx2=%mean
set dx2 start end = x2- meanx2
STATS x3 start end
COMPUTE meanx3=%mean
set dx3 start end = x3- meanx3
*
make Xtbig start+2 end numobs numvars
#dx1 dx2 dx3 dx1{1} dx2{1} dx3{1} dx1{2} dx2{2} dx3{2}
*
compute Abig=%zeros(9,9)
do i=1,3
compute Abig(i,1)=Ax1(1,i)
compute Abig(i,2)=Ax1(4,i)
compute Abig(i,3)=Ax1(7,i)
compute Abig(i,4)=Ax1(2,i)
compute Abig(i,5)=Ax1(5,i)
compute Abig(i,6)=Ax1(8,i)
compute Abig(i,7)=Ax1(3,i)
compute Abig(i,8)=Ax1(6,i)
compute Abig(i,9)=Ax1(9,i)
end do i
do i=4,9
compute Abig(i,i-3)=1
end do i
*disp Abig
compute I9=%identity(9)
compute IA_inv=INV(I9-Abig)
*
compute e2=%zeros(1,9)
compute e2(1,2)=1
*
compute Rbig=TR(e2*Abig*IA_inv*TR(Xtbig))
*disp Rbig
*
make Xqt start+2 end
#dx1
*
compute nLambda=Rbig+Xqt
*
set Lambda start+2 end = -nLambda(t-3,1)
*
linreg(noprint, title="Regression (VAR1), Table 5") Lambda
# constant erx{-1}
linreg(noprint, robust,optimalweights,lags=6,lwindow=newey) Lambda
# constant erx{-1}
*
END PROCEDURE

when i run it I use for example:

SOURCE ENGELT3.SRC
@ENGELT3 qcan var1realcan iusacan 1979:07 2009:10

i get some results but those results do not make sense. Start from
set ERX start end = X2 - residsvarx1(2)
ERX is not constructed correctly

Thank you,
Hypatia
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: PROCEDURE Writing

Unread post by TomDoan »

What you posted can't work as you replaced the TYPE instruction for X1 X2 X3 with LOCAL. Assuming you were actually running the correct code, the only thing I see wrong is that you are not using the <<start>> and <<end>> on the ESTIMATE.
Post Reply