/* Notes on Programming in Gauss 2006 */ 1. Elements of a progam /*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/ A. Initialization new; cls; output file=test.100 reset;output on; library pgraph; rndseed 937841; flag1 = 1; /*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/ B. Import Data #include nerlove.asc; load data = dat; @ format = year~day~......@ let x[4,2] = 1 2 3 4 5 6 7 8; a = 1~0~5~2| 3~2~9~1; /*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/ C. Program Control if flag1 == 1; ? "flag1 = " flag1: elseif flag1 == 2; ? "flag1 = " flag1: else; ? "flag1 = other": endif; maxi = 100; all_i = zeros(maxi,2); i = 1; do until i > maxi; maxi[i,.] = i~(i*2 + 1); {coeff,vc,stderrs,sigma,rsquared,e} = nols(y,x[.,i],1,0,1); ? (i~coeff'); i = i + 1; endo; /*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/ D. Procedures Example 1 proc AR1(b,u); /* computes realiatino of AR(1) using parameters b, and errors in u */ local t,x; x = zeros(rows(u),1); x[1,.] = (b[1,.]/(1-b[2,.])) + u[1,.]/((1-b[2,.]^2)^0.5); t = 2; do until t > rows(x); x[t,.] = b[1,.] + x[t-1,.]*b[2,.] + u[t,.]/((1-b[2,.]^2)^0.5); t = t + 1; endo; retp(x); endp; Example 2 proc (0) = tbl(z,b,pval); local k,tabb,sz,si,pall; . . . . endif; endp; Example 3 /* {coeff,vc,stderrs,sigma,rsquared,e} = nols(y,x,const,het,outp); const = 1 constant included het = 1~0 hetroscedastic standard errors no lags het = 1~k hetroscedastic standard errors k lags outp = 1 long output printed outp = 2 short output printed outp = 3 long output with tests outp = 4 tabular output with tests */ proc (6) = NOLS(y_y,x_x,const,het,outp); local xpxinv,coeff,e,stderrs,tstats,dftstat,tprobs,pnames,final, mask,fmt,pdummy,rsquared,vc,sigma,es,dw,nx,ry,rx,rcoeff,re,rstat, hy,hx,hcoeff,he,hstat,k,rstatall,hstatall,tlags,y,x, lags,u,xl,cx,i,snl,uxxu,j; retp(coeff,vc,stderrs,sigma,rsquared,e); endp; /*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/ 2. Special Matrices x = ones(3,2); y = zeros(5,6); z = eye(5); xx = moment(x,0); ixx = invpd(xx); ixx2 = inv(xx); h = seqa(1,1,10); d = rev(h); z = selif(h,d.>3); /*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/ 3. Random Numbers rndseed 937841; maxsamp = 100; x = rndn(maxsamp,5)~ones(maxsamp,1); u = rndn(maxsamp,1); beta = 1|2|3|4|5|6; y = x*beta + u; _title = "test of nols"; {coeff,vc,stderrs,sigma,rsquared,e} = nols(y,x,0,0,1); /*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/ 3. Libraries Here are the contents of user.lcg sim.src simplex : proc nols.src NOLS : proc llag.src lag0 : proc lead0 : proc lag : proc lead : proc cch : proc bpq.src bpq : proc niv.src NIV : proc