**************************************************************************; ******* reading in the data and creating means of each variable ******; **********************************************************************; option validvarname = v6; data readin; input obs EDUHS MEDHHIN PERCAPIT PUBWATER WOOD RESP; cards; 1 70.5 17564 9281 11.2 33.0 -7.30523 2 86.7 40076 14554 74.9 2.2 -7.03289 3 72.9 20920 9889 30.5 23.3 -7.22938 4 75.9 20925 8938 33.1 26.4 -7.08875 5 77.3 26619 11018 63.4 8.1 -7.18195 6 72.3 19408 9575 63.7 4.4 -7.44869 7 82.7 25366 11125 75.2 3.1 -7.45323 8 71.7 25032 11244 76.6 4.5 -7.40105 9 75.1 24900 10878 44.6 15.5 -7.13288 10 84.6 39188 16116 72.1 3.6 -7.61564 11 72.5 18732 8991 11.4 34.8 -6.76724 12 73.7 22227 11067 68.2 3.2 -7.23637 13 80.1 31281 12526 43.7 11.2 -7.00609 14 80.5 25891 10836 82.5 2.8 -7.30800 15 64.9 17752 8359 24.0 38.4 -7.09561 16 84.9 22908 12067 19.8 33.6 -7.47994 17 71.7 21661 10335 68.6 3.3 -7.65552 18 75.7 22250 10911 30.0 16.2 -7.18282 19 90.7 42218 17237 91.8 0.7 -7.19225 20 78.7 29071 11932 58.4 4.5 -7.10267 21 76.1 22067 10264 35.7 10.2 -7.34845 22 74.4 22421 11276 68.1 4.2 -7.20223 23 70.2 22155 10146 56.7 9.4 -7.44400 24 75.5 24764 11452 70.9 2.2 -7.39306 25 78.0 29237 12892 65.9 5.4 -7.12041 26 71.9 19773 9622 55.2 7.3 -7.47303 27 88.2 35659 18496 96.0 0.3 -7.10739 28 75.9 25846 11587 59.3 12.8 -7.18405 29 76.4 20151 9527 17.1 33.1 -6.89004 30 78.2 31308 11909 26.6 13.9 -7.27884 31 77.5 22442 10541 30.4 25.8 -7.04145 32 74.2 23157 11287 56.9 3.0 -7.36740 33 69.9 22495 9887 24.3 25.9 -7.15804 34 76.3 25368 11574 57.4 4.7 -7.26909 35 71.0 23518 11050 78.3 9.5 -6.76117 36 73.0 23411 11732 56.7 16.3 -7.18279 37 72.2 21646 10368 52.5 3.7 -7.52693 38 80.2 23478 11415 41.8 15.5 -6.99737 39 75.2 24383 10623 25.8 28.0 -7.30354 40 76.3 27706 11792 55.1 7.3 -7.33723 41 67.7 19211 9616 74.1 4.1 -7.46321 42 75.9 24689 11121 78.8 1.9 -7.33578 43 64.7 16924 7737 34.9 23.6 -7.48375 44 68.5 21707 9675 54.9 12.1 -7.30616 45 75.2 24414 11387 74.7 2.7 -7.39557 46 75.5 29549 12689 70.4 4.9 -7.37226 47 73.4 24516 10843 45.9 8.9 -7.21550 48 70.1 22689 10167 36.9 15.0 -6.98164 49 67.7 22102 9666 34.1 20.1 -7.33731 50 75.8 23763 11599 76.0 1.2 -7.32566 51 69.7 22673 10871 53.7 1.9 -7.54059 52 81.5 30491 12358 76.5 4.8 -7.67704 53 70.4 22942 10860 73.4 0.9 -7.35685 54 69.7 21238 9948 56.8 9.7 -7.12294 55 88.0 35789 16214 80.2 2.0 -7.22099 56 71.6 21909 10467 32.1 16.3 -7.05172 57 72.3 21571 10426 66.8 6.9 -7.49327 58 69.2 21191 9538 22.9 25.9 -7.30384 59 70.4 20737 10050 80.7 1.4 -7.48056 60 73.0 22559 10199 67.0 5.7 -7.04066 61 72.1 20131 9465 38.3 9.2 -6.95791 62 85.0 32043 15645 97.1 0.3 -7.11884 63 64.3 19926 8963 51.8 17.4 -7.00644 64 71.3 22827 10489 66.7 5.2 -7.31025 65 71.7 23278 10795 63.0 4.4 -7.35995 66 78.7 29596 11936 68.6 4.7 -7.10256 67 69.8 24483 11383 79.6 1.7 -7.62295 68 71.8 25910 10280 41.0 15.4 -7.43372 69 80.3 24093 11833 67.5 8.4 -7.11068 70 84.8 40798 15341 69.4 3.4 -7.19746 71 84.2 35585 13147 38.2 9.1 -6.95286 72 68.2 24957 10899 56.2 7.8 -7.39340 73 78.3 27512 11620 59.2 7.7 -7.38323 74 79.4 30571 12993 75.7 2.0 -7.23823 75 77.0 21921 9814 69.0 2.6 -7.27096 76 68.2 18740 9222 59.4 3.3 -7.39121 77 68.4 18836 8535 30.7 21.6 -7.30260 78 71.2 20746 9882 58.7 2.1 -7.78562 79 76.4 26998 11862 57.2 9.6 -7.26850 80 70.6 17333 8640 47.3 21.6 -6.95717 81 77.5 26992 11514 68.1 4.6 -7.72376 82 90.0 44122 17435 70.3 2.1 -7.12013 83 72.2 22496 10658 68.4 3.4 -7.68397 84 73.8 23081 10108 63.9 4.4 -7.38356 85 77.7 25937 11323 71.6 6.1 -7.35966 86 80.1 33456 12687 44.4 7.9 -7.23051 87 72.6 21537 10513 62.1 3.1 -7.58666 ; proc means data = readin noprint; var eduhs medhhin percapit pubwater wood resp; output out= means mean = m_eduhs m_medhh m_percap m_pubwat m_wood m_resp run; data minn; set readin; if _n_=1 then set means; drop _TYPE_ _FREQ_; samplesz = _FREQ_; run; **************************************************************************; ******* estimating the parameters for the 2 factor model for the *********; ******* 5 predictor variables eduhs medhhin percapit pubwater wood *******; **************************************************************************; proc calis cov method = ml data = minn outram=parm1 ; var eduhs medhhin percapit pubwater wood; lineqs eduhs = B11 f1 + e1, medhhin = B12 f1 + e2, percapit = f1 + e3, pubwater = B21 f2 + e4, wood = f2 + e5; std f1 = ph1, f2 = ph2, e1-e5 = th1-th5; cov f1 f2 = ph12; bounds th1-th5 >=0, ph1-ph2>=0; run; ******* Obtain the parameter estimates from the calis output data set ********; DATA parm2; set parm1; if _NAME_="B11" then B11 = _ESTIM_; if _NAME_="B12" then B12 = _ESTIM_; if _NAME_="B21" then B21 = _ESTIM_; if _NAME_="TH1" then TH1 = _ESTIM_; if _NAME_="TH2" then TH2 = _ESTIM_; if _NAME_="TH3" then TH3 = _ESTIM_; if _NAME_="TH4" then TH4 = _ESTIM_; if _NAME_="TH5" then TH5 = _ESTIM_; if _NAME_="PH1" then PH1 = _ESTIM_; if _NAME_="PH2" then PH2 = _ESTIM_; if _NAME_="PH12" then PH12 = _ESTIM_; count = 1; keep B11 B12 B21 TH1-TH5 PH1 PH2 PH12 count; retain B11 B12 B21 TH1-TH5 PH1 PH2 PH12 count 0; run; data new; set parm2; by count; if last.count; drop count; run; **************************************************************************; ******* Calculating the factor score estimates *********; **************************************************************************; PROC IML; use new; read all var{TH1 TH2 TH3 TH4 TH5} into thetac; read all var{B11 B12 B21} into betac; read all var{PH1 PH2 PH12} into phic; beta1=j(3,2,0); beta1[1,1] = betac[1]; beta1[2,1] = betac[2]; beta1[3,2] = betac[3]; use minn; read all var{EDUHS MEDHHIN PUBWATER} into X1; read all var{PERCAPIT WOOD} into X2; read all var{m_eduhs m_medhh m_pubwat} into x1bar; read all var{m_percap m_wood} into x2bar; beta0 = x1bar[1,]-(beta1*x2bar[1,]`)`; beta00 = beta0@j(nrow(x1),1); print beta0 beta1 thetac; psi1 = diag(thetac[1]//thetac[3]//thetac[4]); psi2 = diag(thetac[2]//thetac[5]); sigmauv=-psi2*beta1`; sigmavv=psi1+beta1*psi2*beta1`; v = x1 - beta00 - (beta1*x2`)`; fhat= x2 -(sigmauv*inv(sigmavv)*V`)`; temp = ID||fhat; create fhats from temp [colname={fhat1 fhat2}]; append from temp; quit; run; ******************************************************************************; ******* Performing OLS regression of resp on the factor score estimates ******; ******* Parameter estimates and s.e. for alpha0,1,2 are found in *************; ******* proc reg output under parameter estimates for ******; ******* intercep, fhat1, and fhat2 respectively; ******; ******************************************************************************; data new; merge minn fhats; keep resp fhat1 fhat2; proc reg data=new; model resp=fhat1 fhat2; run;