/* PANEL DATA ESTIMATION -- AN APPLICATION TO MURDER RATES */ /* Load Data and Define Variables */ load path = c:\gauss8.0\classes\econ5360\data\; load data[154,7] = murder.txt; stateno = data[2:154,1]; murder = data[2:154,3]; executions = data[2:154,4]; unemp = data[2:154,5]; T = 3; n = 51; y = murder; xmat = ones(n*T,1)~executions~unemp; k = cols(xmat); /* ***************** */ /* Pooled Regression */ /* ***************** */ b = inv(xmat'*xmat)*(xmat'*y); residp = y - xmat*b; eep = residp'*residp; varb = (eep/(n*T-k))*inv(xmat'*xmat); tstat = b ./ diag(sqrt(varb)); print "Pooled OLS Estimates tstats"; print b~tstat; print; /* *********************** */ /* Fixed-Effects Estimator */ /* *********************** */ /* LSDV Approach */ D = zeros(n*T,n); for ii(1,n,1); D[.,ii] = (stateno .== ii); endfor; xmat1 = xmat[.,2:3]~D; k = k - 1; /* FE Estimatior */ bfe = inv(xmat1'*xmat1)*(xmat1'*y); residfe = y - xmat1*bfe; eefe = residfe'*residfe; varbfe = (eefe/(n*T-n-k))*inv(xmat1'*xmat1); tfe = bfe ./ diag(sqrt(varbfe)); print "FE Estimates tstats"; print bfe~tfe; print; /* Calculate F Statistic for Group Specific Effects */ F = ((eep - eefe)/(n-1))/(eefe/(n*T-n-k)); print "F statistic for significance of group specific effects = " F; print; /* ************************ */ /* Random Effects Estimator */ /* ************************ */ /* Calculate Estimate of Var(eps) */ Md = eye(n*T) - D*inv(D'*D)*D'; ystar = Md*y; xstar = Md*xmat[.,2:3]; bfe1 = inv(xstar'*xstar)*(xstar'*ystar); resid1 = ystar - xstar*bfe1; s2e = (resid1'*resid1)/(n*T-n-k); /* Calculate Estimate of Var(mu) */ Md1 = D*inv(D'*D)*D'; ystar = Md1*y; xstar = Md1*xmat; resid2 = ystar - xstar*b; s2star = (resid2'*resid2)/(n-k-1); s2u = s2star/T - s2e/T; /* Feasible GLS */ theta = 1 - (sqrt(s2e)/(sqrt(T*s2u + s2e))); Mdtheta = eye(n*T) - theta*Md1; ystar = Mdtheta*y; xstar = Mdtheta*xmat; bre = inv(xstar'*xstar)*(xstar'*ystar); residre = ystar - xstar*bre; s2re = (residre'*residre)/(n*T-k-1); varbre = s2re*inv(xstar'*xstar); tre = bre ./ diag(sqrt(varbre)); print "RE Estimates tstats"; print bre~tre; print; /* ************ */ /* Hausman Test */ /* ************ */ W = (bfe[1:2] - bre[2:3])'*inv(varbfe[1:2,1:2] - varbre[2:3,2:3])*(bfe[1:2] - bre[2:3]); print "Hausman statistic = " W;