options crt; ? 8e8 ? Note: enter version of TSP below, to reduce the number of ? AR1 commands required. If you have TSP 4.4 dated after ? June 1998, enter the version as 4.5 . ? set version = 4.5; in qual; freq n; smpl 1,54; print ly1-ly5 lpr1-lpr5 ladr1-ladr5 lqual; smpl 30,32; print ladr1-ladr5; ? (a) smpl 2,54; dot 1-5; olsq ly. c ly.(-1) lpr. ladr. lqual dmr pjf pnd; ? (b.1) frml elast1 lreout. = ladr./(1-ly.(-1)); frml elast2 lrequal. = lqual/(1-ly.(-1)); analyz elast1 elast2; ? (b.2) enddot; smpl 2,54; ? AR1 will drop the first obs. properly dot 1-5; if (version >= 4.5); then; ar1 ly. c ly.(-1) lpr. ladr. lqual dmr pjf pnd; ? (c) else; do; ? Since there can be multiple local optima when there is a lagged ? dependent variable with AR(1), use HILU first to find the best one, ? and then use CORC to iterate to a precise solution. ? Note that this is automated in TSP 4.5 and later ar1(method=hilu) ly. c ly.(-1) lpr. ladr. lqual dmr pjf pnd; ? (c) ar1(method=corc,rstart=@rho) ly. c ly.(-1) lpr. ladr. lqual dmr pjf pnd; enddo; enddot; title 'Exercise 8, part (d) - Cross-section het and AR(1) / Kmenta'; smpl 3,54; const N,5; ? 5 individuals (regions in Canada) set T=@NOB; ? specify number of individuals and time periods list ydep ly; ? put dependent variable name here list Xs lylag lpr ladr lquals dmrs pjfs pnds; ? put RHS variable names here ? (do not include C; ? C will be inserted automatically as CC) ? ? Stack data so to that Proc Ar1het can be used. mmake(vert) mly ly1-ly5; mmake(vert) mlylag ly1(-1) ly2(-1) ly3(-1) ly4(-1) ly5(-1); mmake(vert) mlpr lpr1-lpr5; mmake(vert) mladr ladr1-ladr5; dot lqual dmr pjf pnd; mmake(vert) m. . . . . . ; enddot; set nt = N*T; smpl 1,nt; dot ly lylag lpr ladr; unmake m. . ; enddot; dot lqual dmr pjf pnd; unmake m. .s ; enddot; ? ar1het; ? call the Proc defined below title 'Exercise 8, part (e) - same as (d) but drop obs. with zeros'; smpl 3,29 35,54; ? drop obs. with zeros (also from lags) set T=@NOB; ? Perform same stacking operations as in (d), but in this smaller sample mmake(vert) mly ly1-ly5; mmake(vert) mlylag ly1(-1) ly2(-1) ly3(-1) ly4(-1) ly5(-1); mmake(vert) mlpr lpr1-lpr5; mmake(vert) mladr ladr1-ladr5; dot lqual dmr pjf pnd; mmake(vert) m. . . . . . ; enddot; set nt = N*T; smpl 1,nt; dot ly lylag lpr ladr; unmake m. . ; enddot; dot lqual dmr pjf pnd; unmake m. .s ; enddot; ? ar1het; ? call the Proc defined below ?--------------------------------------------------- ? Code from ar1het.tsp on TSP Examples web page ? ? Estimate the "Cross-sectionally Heteroskedastic and Timewise ? Autoregressive Model" on p.618-620 of Kmenta's "Elements of Econometrics", ? (1986). We'll do the balanced case just to make it easier, but it ? could also be done for the unbalanced case. ? by Clint Cummins 11/21/97 (code should run fine on TSP 4.3 or 4.4) ? ? Example of call: ?const N,5 T,160; ? specify number of individuals and time periods ?list ydep y1; ? put dependent variable name here ?list Xs x1 x2 x3; ? put RHS variable names here (do not include C; ? ? C will be inserted automatically as CC) ?ar1het; ? call the Proc defined below ?--------------------------------------------------- Proc ar1het; local y x cXs cc e id time i rho rtomr2 tmk s2u s2ui; supres smpl; ? save the y and X data in matrices, so that we may overwrite ? them in this Proc, and then restore them at the end. select 1; mmake y ydep; mmake x Xs; list cXs cc Xs; cc = 1; title 'OLS on original data'; olsq(silent) ydep cXs; e = @res; trend id 0; id = 1 + int(id/t); ? id = 1 for first T obs, 2 for second T, etc. trend(period=T) time; do i=1,n; ? loop over individuals, creating y*, X* select (id=i) & (time>1); corr(noprint) e e(-1); ? (12.26 B) set rho = @corr(2,1); ? overwrite the original y,X data with y*,X* (12.27) dot ydep cXs; genr(static) . = . - rho*.(-1); enddot; set rtomr2 = sqrt(1-rho**2); select (id=i) & (time=1); dot ydep cXs; genr . = rtomr2* . ; enddot; enddo; select 1; ? run regression on rho-transformed data title 'GLS on rho-transformed data'; olsq(silent) ydep cXs; ? compute residual variances (s2u) for each individual set tmk = T - @NCOEF; s2u = 0; do i=1,n; select id=i; mat s2ui = (@res'@res)/tmk; s2u = s2ui; enddo; ? create y**, X** select 1; dot ydep cXs; genr . = . / s2u ; enddot; title 'GLS on s2u- and rho-transformed data'; olsq ydep cXs; title 'Alternative SEs for GLS, with degree of freedom adjustment'; mat vcov = @vcov*((@nob-@ncoef)/(@nob-@ncoef-n*2)); ? rho & sig for each N tstats(names=@rnms) @coef vcov; ? restore original data unmake y ydep; unmake x Xs; endproc;