* * SWAMY.RPF * Swamy random coefficients estimator for panel data * * From User's Guide, Example from Section 12.6. * cal(panelobs=20) 1935 all 10//1954:1 open data grunfeld.dat data(format=prn,org=cols) * * The @SWAMY procedure does the analysis below. * @swamy invest # constant firmvalue cstock * compute nindiv=10 compute ncoeff=3 * dec vect[symm] xxmats(nindiv) dec vect[vect] betas(nindiv) dec vect sigmas(nindiv) dec symm delta(ncoeff,ncoeff) dec symm xxgls(ncoeff,ncoeff) dec vect betagls(ncoeff) dec integer k * * First pass, run OLS regressions over each individual. Save %xx, %beta * and %seesq. Also accumulate the sum of the coefficients and their * outer product. * compute delta=%const(0.0) compute betagls=%const(0.0) do i=1,nindiv linreg(noprint) invest i//1 i//20 # constant firmvalue cstock compute xxmats(i)=%xx compute betas(i)=%beta compute sigmas(i)=%seesq ewise delta(j,k)=delta(j,k)+%beta(j)*%beta(k) compute betagls=betagls+%beta end do i * * Estimate the covariance matrix of beta's * ewise delta(j,k)=1.0/(nindiv-1)*\$ (delta(j,k)-(1.0/nindiv)*betagls(j)*betagls(k)) * * Second pass. Compute the GLS covariance matrix. While we're at it, * replace xxmats with the precision. * compute xxgls=%const(0.0) do i=1,nindiv compute xxmats(i)=inv(delta+sigmas(i)*xxmats(i)) compute xxgls=xxgls+xxmats(i) end do i compute xxgls=inv(xxgls) * * Final pass. Compute the grand coefficient matrix * compute betagls=%const(0.0) do i=1,nindiv compute betagls=betagls+xxgls*xxmats(i)*betas(i) end do i linreg(create,coeffs=betagls,covmat=xxgls,form=chisquared) invest # constant firmvalue cstock