/* This example of analyzing panel data is based on data and SAS code taken from SAS/ETS User's Guide, Version 6, Second Edition, Example 18.1, pp. 889-893 "Analyzing Demand for Liquid Assets". This program analyzes the demand for liquid assets, i.e. Per Capita Demand Deposits (d), Per Capita Time Deposits (t), and Per Capita S & L Association Shares (s). The data are taken from Feige, E.L.(1964), The Demand for Liquid Assets: A Temporal Cross-Section Analysis, Englewood Cliffs: Prentice-Hall. The data for seven "states" (CA,DC,FL,IL,NY,TX,WA) are selected out of 49 "states" and observed over the years 1949 - 1959. All data are transformed via natural logarithm so the demand equations are iso-elastic in form. That is, the coefficients on the income (y) and "prices" (rd,rt,rs) variables in the demand equations can be interpreted directly as elasticities. */ /* Two Approaches are used here: The Fixed Effects Approach and the Random Effects Approach (Fuller and Battese (1974)). */ /* In the Fixed Effects Approach we have to be careful to avoid the infamous "Dummy Variable Trap." This trap occurs when there are "too many" dummy variables in the estimating equation. When this occurs, Least Squares fails in the sense that the estimates cannot be calculated because the design matrix does not have sufficient column rank. In the case of one fixed effect you have to either (i) drop one of your dummy (classificatory) variables when you have an intercept in the equation or (ii) drop the intercept and include all of the dummy variables. Of course the coefficients accompanying the dummy variables are interpreted differently in the two cases. In case (i) the dummy variable coefficients become INCREMENTAL coeffients which when added to the included intercept represent the intercept of that class. In case (ii) the dummy variable coefficients are themselves the intercepts of the particular class. In the case of two fixed effects we have to remember to drop TWO variables from the equation, one for each fixed effect. For example one can (a) drop ONE dummy variable from each fixed effect (for a total of two) while retaining the intercept or (b) you can drop the intercept and drop ONE of the dummy variables from one of the fixed effects. Again the coefficients accompanying the dummy variables are interpreted differently in the two cases. (It should be noted that some investigators get around the dummy variable trap by including a "symmetry restriction" for each fixed effect while retaining the intercept. A symmetry restriction consists of forcing the coefficients of the dummy variables of a given fixed effect to add to zero. This approach is demonstrated in the companion program TSCS2.SAS along with the parametrization with the intercept included but one dummy deleted in each fixed effect.) */ /* In the data set to be analyzed below we consider two fixed effects, one for the states ("individuals") and one for the year ("time"). Here we use the approach of dropping the intercept and dropping one of the time effect dummies (d49) while retaining all of the state dummies. Thus the coefficients accompanying the state dummies represent the differences in the intercepts across different states for any given year. The coefficients accompanying the time dummies represent the differences in the intercept relative to 1949 as each year transpires. */ options pagesize=60 linesize=74 nodate; data a; input state $ year d t s y rd rt rs; label d = 'Per Capita Demand Deposits' t = 'Per Capita Time Deposits' s = 'Per Capita S & L Association Shares' y = 'Permanent Per Capita Personal Income' rd = 'Service Charge on Demand Deposits' rt = 'Interest on Time Deposits' rs = 'Interest on S & L Association Shares'; cards; CA 1949 6.2785 6.1924 4.4998 7.2056 -1.0700 0.1080 1.0664 CA 1950 6.4019 6.2106 4.6821 7.2889 -1.0106 0.1501 1.0767 CA 1951 6.5058 6.2729 4.8598 7.3827 -1.0024 0.4008 1.1291 CA 1952 6.4785 6.2729 5.0039 7.4000 -0.9970 0.4492 1.1227 CA 1953 6.4118 6.2538 5.1761 7.4200 -0.8916 0.4662 1.2110 CA 1954 6.4520 6.2971 5.3613 7.4478 -0.6951 0.4756 1.1924 CA 1955 6.4998 6.3081 5.5452 7.4838 -0.7012 0.4929 1.2387 CA 1956 6.5162 6.2897 5.7236 7.5380 -0.6292 0.5636 1.2638 CA 1957 6.4646 6.3733 5.8579 7.5822 -0.4620 0.9712 1.3686 CA 1958 6.5191 6.4552 6.0331 7.6178 -0.4050 0.9712 1.3818 CA 1959 6.5709 6.4661 6.2025 7.6797 -0.4095 0.9738 1.3980 DC 1949 6.7499 5.4806 5.8230 7.3796 -1.3432 -0.3916 1.0307 DC 1950 6.9207 5.5413 5.9454 7.4804 -1.3205 -0.4125 1.0567 DC 1951 7.0775 5.6131 6.1420 7.6094 -1.3243 -0.3901 1.1006 DC 1952 6.9810 5.5452 6.2166 7.5606 -1.3205 -0.3161 1.0902 DC 1953 6.9117 5.5530 6.2971 7.5262 -1.2483 -0.1244 1.1102 DC 1954 6.9508 5.7203 6.4394 7.5326 -1.1777 0.4055 1.1259 DC 1955 6.9726 5.7961 6.5820 7.5658 -1.1457 0.4081 1.1559 DC 1956 6.9679 5.7991 6.6670 7.5761 -1.1332 0.4688 1.1787 DC 1957 7.0211 5.9687 6.8002 7.6425 -1.0613 0.8024 1.2143 DC 1958 7.0867 6.0799 6.9197 7.6704 -1.0217 0.7419 1.2404 DC 1959 7.0630 6.0014 7.0291 7.6811 -0.8723 0.8510 1.3156 FL 1949 6.0113 4.8363 4.6347 6.9315 -1.0385 -0.0954 0.8390 FL 1950 6.0707 4.8283 4.7274 6.9147 -1.0729 -0.0440 0.8446 FL 1951 6.1506 4.8903 4.9345 6.9735 -1.0936 0.0020 0.8871 FL 1952 6.1527 4.8828 5.1180 6.9735 -1.1147 0.0507 0.9466 FL 1953 6.1399 4.9273 5.2983 7.0370 -1.0385 0.1115 0.9651 FL 1954 6.1420 4.9416 5.5094 7.0361 -0.9835 0.2374 1.0547 FL 1955 6.3008 5.0814 5.8111 7.1747 -0.9729 0.2919 1.0585 FL 1956 6.3404 5.1120 5.9480 7.1997 -0.9188 0.3961 1.1092 FL 1957 6.2748 5.3660 6.0355 7.2320 -0.8052 0.8838 1.2054 FL 1958 6.2785 5.4806 6.1026 7.2506 -0.6972 0.8973 1.2099 FL 1959 6.2577 5.4596 6.2344 7.2841 -0.6482 0.9119 1.2740 IL 1949 6.7370 5.8749 4.7536 7.2896 -1.9449 -0.1602 0.9179 IL 1950 6.7569 5.8348 4.8363 7.2917 -1.9241 -0.1661 0.8953 IL 1951 6.7878 5.8141 4.9698 7.3492 -1.9173 -0.0661 0.8957 IL 1952 6.8178 5.9402 5.1648 7.4073 -1.9379 0.0573 0.9431 IL 1953 6.8123 5.9814 5.3423 7.4448 -1.8971 0.0871 0.9944 IL 1954 6.8330 6.0259 5.5334 7.4816 -1.8079 0.1222 1.0109 IL 1955 6.8448 6.0259 5.6904 7.5038 -1.7603 0.1319 1.0217 IL 1956 6.8501 6.0568 5.8579 7.5575 -1.6983 0.3031 1.0757 IL 1957 6.8013 6.0913 5.9713 7.5909 -1.5945 0.4874 1.1490 IL 1958 6.8233 6.1399 6.0958 7.6014 -1.5418 0.5522 1.2244 IL 1959 6.7731 6.1633 6.1924 7.6183 -1.4653 0.7198 1.2519 NY 1949 7.2226 5.6021 4.2047 7.3079 -2.1893 -0.3754 0.7415 NY 1950 7.2478 5.5645 4.2627 7.3232 -2.1286 -0.3230 0.7333 NY 1951 7.2506 5.5334 4.4427 7.3563 -2.1286 -0.2294 0.7966 NY 1952 7.2591 5.6058 4.6250 7.4140 -2.1203 0.0488 0.8899 NY 1953 7.2406 5.6904 4.7707 7.4639 -2.0099 0.2159 0.9070 NY 1954 7.2549 5.7621 4.9053 7.4967 -1.9310 0.2971 0.9322 NY 1955 7.2661 5.7462 5.0039 7.5000 -1.9241 0.3407 0.9764 NY 1956 7.2556 5.8260 5.1240 7.5580 -1.7838 0.5619 1.0203 NY 1957 7.2745 5.9915 5.2417 7.6372 -1.6660 0.8024 1.0842 NY 1958 7.2814 6.1137 5.3279 7.6592 -1.6503 0.8587 1.1227 NY 1959 7.2563 6.1181 5.4072 7.6948 -1.5945 0.9247 1.1703 TX 1949 6.3509 4.2341 3.5835 6.9027 -1.9038 -0.1755 1.0134 TX 1950 6.4520 4.2627 3.7377 6.9584 -1.9173 -0.1791 1.0080 TX 1951 6.5206 4.3438 3.8918 7.0510 -1.9105 -0.2083 1.0364 TX 1952 6.5043 4.4308 4.0604 7.0699 -1.9173 0.0677 1.0578 TX 1953 6.5013 4.5951 4.2905 7.1131 -1.8326 0.1570 1.1256 TX 1954 6.5624 4.7622 4.5218 7.1585 -1.7037 0.2837 1.1291 TX 1955 6.5820 4.8442 4.7095 7.1967 -1.6555 0.3133 1.1220 TX 1956 6.5624 4.8828 4.8203 7.2138 -1.5702 0.4344 1.1210 TX 1957 6.5147 5.0689 4.9698 7.2556 -1.3863 0.7519 1.2490 TX 1958 6.5737 5.3033 5.1059 7.2841 -1.2801 0.8069 1.2276 TX 1959 6.5554 5.3519 5.2781 7.3265 -1.1940 0.8899 1.3005 WA 1949 6.0355 5.3033 4.4998 7.0440 -1.0272 -0.0651 0.7266 WA 1950 6.2166 5.3753 4.6913 7.1884 -1.0189 -0.0274 0.8016 WA 1951 6.2634 5.3936 4.8520 7.2675 -1.0079 0.0383 0.8616 WA 1952 6.2519 5.4381 4.9698 7.3005 -0.9650 0.2662 0.9373 WA 1953 6.2146 5.4596 5.1591 7.3337 -0.8819 0.2942 1.0466 WA 1954 6.2860 5.5094 5.3613 7.3790 -0.7319 0.2986 1.0526 WA 1955 6.3008 5.5835 5.5053 7.4079 -0.6368 0.5710 1.0671 WA 1956 6.2634 5.5910 5.5722 7.4122 -0.5327 0.5761 1.1023 WA 1957 6.2025 5.6595 5.6525 7.4448 -0.3842 0.8385 1.1793 WA 1958 6.2558 5.7333 5.7621 7.4697 -0.3341 0.8338 1.1957 WA 1959 6.2442 5.7557 5.8435 7.5005 -0.3147 0.9143 1.2548 ; proc sort data=a; by state year; run; /* Here is where the state and time dummy variables for the Fixed Effects Approach are constructed. */ data a; set a; if state = 'CA' then ds1=1; else ds1=0; if state = 'DC' then ds2=1; else ds2=0; if state = 'FL' then ds3=1; else ds3=0; if state = 'IL' then ds4=1; else ds4=0; if state = 'NY' then ds5=1; else ds5=0; if state = 'TX' then ds6=1; else ds6=0; if state = 'WA' then ds7=1; else ds7=0; d49 = year = 1949; d50 = year = 1950; d51 = year = 1951; d52 = year = 1952; d53 = year = 1953; d54 = year = 1954; d55 = year = 1955; d56 = year = 1956; d57 = year = 1957; d58 = year = 1958; d59 = year = 1959; label ds1 = 'State Dummy for CA' ds2 = 'State Dummy for DC' ds3 = 'State Dummy for FL' ds4 = 'State Dummy for IL' ds5 = 'State Dummy for NY' ds6 = 'State Dummy for TX' ds7 = 'State Dummy for WA' d49 = 'Time Dummy for 1949' d50 = 'Time Dummy for 1950' d51 = 'Time Dummy for 1951' d52 = 'Time Dummy for 1952' d53 = 'Time Dummy for 1953' d54 = 'Time Dummy for 1954' d55 = 'Time Dummy for 1955' d56 = 'Time Dummy for 1956' d57 = 'Time Dummy for 1957' d58 = 'Time Dummy for 1958' d59 = 'Time Dummy for 1959'; /* Print the data. */ proc print data=a; title 'Data for Liquid Asset Study'; /* Here we enter the Fixed Effects for states only in the Per Capita Demand Deposits Equation. We test for the significance of the state effects. They turn out to be significant but the sign on the rt variable is contrary to what you would expect. (It is positive whereas one would expect it to be negative.) Maybe we need to add time fixed effects as well. */ proc reg data=a; model d = y rd rt rs ds1 ds2 ds3 ds4 ds5 ds6 ds7 / noint; test ds1-ds2,ds2-ds3,ds3-ds4,ds4-ds5,ds5-ds6,ds6-ds7; title 'Fixed Effects by State Only: Per Capita Demand Deposits'; /* Run the Fixed Effects Model for Per Capita Demand Deposits. First test the significance of the State effects then test the significance of the Time effects and then test the JOINT significance of both effects. */ proc reg data=a; model d = y rd rt rs ds1 ds2 ds3 ds4 ds5 ds6 ds7 d50 d51 d52 d53 d54 d55 d56 d57 d58 d59 / noint; test ds1-ds2,ds2-ds3,ds3-ds4,ds4-ds5,ds5-ds6,ds6-ds7; test d50,d51,d52,d53,d54,d55,d56,d57,d58,d59; test ds1-ds2,ds2-ds3,ds3-ds4,ds4-ds5,ds5-ds6,ds6-ds7, d50,d51,d52,d53,d54,d55,d56,d57,d58,d59; title 'Fixed Effects by State and Year: Per Capita Demand Deposits'; /* Since the rt variable is insignificant we drop it and re-estimate. */ proc reg data=a; model d = y rd rs ds1 ds2 ds3 ds4 ds5 ds6 ds7 d50 d51 d52 d53 d54 d55 d56 d57 d58 d59 / noint; /* Here we enter the Fixed Effects for states only in the Per Capita Time Deposits Equation. We test for the significance of the state effects. They turn out to be significant. */ proc reg data=a; model t = y rd rt rs ds1 ds2 ds3 ds4 ds5 ds6 ds7 / noint; test ds1-ds2,ds2-ds3,ds3-ds4,ds4-ds5,ds5-ds6,ds6-ds7; title 'Fixed Effects by State Only: Per Capita Time Deposits'; /* Run the Fixed Effects Model by States and Time for Per Capita Time Deposits. Test the individual significances of the effects and then their joint significance. */ proc reg data=a; model t = y rd rt rs ds1 ds2 ds3 ds4 ds5 ds6 ds7 d50 d51 d52 d53 d54 d55 d56 d57 d58 d59 / noint; test ds1-ds2,ds2-ds3,ds3-ds4,ds4-ds5,ds5-ds6,ds6-ds7; test d50,d51,d52,d53,d54,d55,d56,d57,d58,d59; test ds1-ds2,ds2-ds3,ds3-ds4,ds4-ds5,ds5-ds6,ds6-ds7, d50,d51,d52,d53,d54,d55,d56,d57,d58,d59; title 'Fixed Effects by State and Year: Per Capita Time Deposits'; /* Here we want to refine the time deposits equation a little by dropping an insignificant variable (rd) and then re-estimating. */ proc reg data=a; model t = y rt rs ds1 ds2 ds3 ds4 ds5 ds6 ds7 d50 d51 d52 d53 d54 d55 d56 d57 d58 d59 / noint; /* Here we enter the Fixed Effects for states only in the Per Capita S&L Association Shares Equation. We test for the significance of the state effects. They turn out to be significant. */ proc reg data=a; model s = y rd rt rs ds1 ds2 ds3 ds4 ds5 ds6 ds7 / noint; test ds1-ds2,ds2-ds3,ds3-ds4,ds4-ds5,ds5-ds6,ds6-ds7; title 'Fixed Effects by State Only: Per Capita S&L Association Shares'; /* Run the Fixed Effects Model by States and Time for Per Capita S&L Association shares. Test the individual significances of the effects and then their joint significance. */ proc reg data=a; model s = y rd rt rs ds1 ds2 ds3 ds4 ds5 ds6 ds7 d50 d51 d52 d53 d54 d55 d56 d57 d58 d59 / noint; test ds1-ds2,ds2-ds3,ds3-ds4,ds4-ds5,ds5-ds6,ds6-ds7; test d50,d51,d52,d53,d54,d55,d56,d57,d58,d59; test ds1-ds2,ds2-ds3,ds3-ds4,ds4-ds5,ds5-ds6,ds6-ds7, d50,d51,d52,d53,d54,d55,d56,d57,d58,d59; title 'Fixed Effects by State and Year: Per Capita S & L Association Shares'; /* Here we want to refine the S&L shares equation a little by dropping insignificant variables one at a time and then re-estimating. */ proc reg data=a; model s = y rt rs ds1 ds2 ds3 ds4 ds5 ds6 ds7 d50 d51 d52 d53 d54 d55 d56 d57 d58 d59 / noint; proc reg data=a; model s = y rt rd ds1 ds2 ds3 ds4 ds5 ds6 ds7 d50 d51 d52 d53 d54 d55 d56 d57 d58 d59 / noint; /* Now we come down to the final refinement of the S&L shares equations. */ proc reg data=a; model s = y rt ds1 ds2 ds3 ds4 ds5 ds6 ds7 d50 d51 d52 d53 d54 d55 d56 d57 d58 d59 / noint; /* Estimate Random Effects models for Per Capita Demand Deposits. */ proc tscsreg data=a; model d = y rd rt rs / fuller; id state year; title 'Random Effects Model for Per Capita Demand Deposits'; /* Estimate a refinement. */ proc tscsreg data=a; model d = y rd rs / fuller; id state year; title 'Random Effects Model for Per Capita Demand Deposits'; /* Estimate Random Effects models for Per Capita Time Deposits. */ proc tscsreg data=a; model t = y rd rt rs / fuller; id state year; title 'Random Effects Model for Per Capita Time Deposits'; /* Estimate a refinement. */ proc tscsreg data=a; model t = y rt rs / fuller; id state year; title 'Random Effects Model for Per Capita Time Deposits'; /* Estimate Random Effects models for Per Capita S & L Association Shares. */ proc tscsreg data=a; model s = y rd rt rs / fuller; id state year; title 'Random Effects Model for Per Capita S & L Association Shares'; /* Estimate some refinements. */ proc tscsreg data=a; model s = y rd rt / fuller; id state year; proc tscsreg data=a; model s = y rd rs / fuller; id state year; proc tscsreg data=a; model s = y rd / fuller; id state year; /* Calculate the Hausman Test for the "Best" specification Demand Deposits equation. This involves (1) obtaining the SLOPE coefficient estimates of the Fixed Effects model and subtracting the SLOPE coefficient estimates of the Random Effects model to form a vector of the difference in the coefficient estimates of the two methods and (2) obtaining the variance-covariance matrix of this difference vector obtained by subtracting the variance-covariance matrix of the Random Effects model from the variance-covariance matrix of the Fixed Effects model. The variance-covariance matrices and coefficient estimates are provided by the following SAS statements. The chi-square statistic (a Wald test) is calculated as in equation (14-37), p. 577 in Greene's book. The null hypothesis of this test is that the random effects of the Random Effects model are NOT correlated with the explanatory variables (and thus the Random Effects estimates are more efficient than the Fixed Effects estimates) versus the alternative hypothesis that the random effects of the Random Effects model are correlated with the explanatory variables (and thus the Fixed Effects estimates are to be preferred because they are consistent whereas the Random Effects estimates are not). Getting the Chi-square statistic requires computing a quadratic form of a 3x3 matrix so we need to do our computations carefully. */ /* By the way, Proc TSCSREG AUTOMATICALLY calculates the Hausman test (when it can). If you look at the output for the TSCSREG estimation of the Per Capita Demand Deposits equation with all of the income and price variables in it, the program produces a Hausman Wald statistic of 5.5138 with probability value of 0.2385 (i.e. accept the Random Effects model). However, when you drop the the insignificant variable rt you get a Hausman Wald statistic of 8.1561 with probability value of 0.0429 (i.e. reject the Random Effects model). This last result corroborates our Proc IML calculations done below where we obtain a Hausman Wald statistic value of 8.1300544. */ /* Here we get the variance-covariance matrix of the Fixed Effects model for demand deposits and the slope coefficient estimates. */ proc reg data=a outest=covfe covout; model d = y rd rs ds1 ds2 ds3 ds4 ds5 ds6 ds7 d50 d51 d52 d53 d54 d55 d56 d57 d58 d59 / noint; title 'Fixed Effects Model for Demand Deposits - Hausman Test'; proc print data=covfe; /* Here we get the variance-covariance matrix of the Random Effects model for demand deposits and the slope coefficient estimates. */ proc tscsreg data=a outest=covvc covout; model d = y rd rs / fuller; id state year; title 'Random Effects Model for Demand Deposits - Hausman Test'; proc print data=covvc; /* Let's use PROC IML (interactive matrix language) to calculate the Hausman test Wald statistic using the coefficient estimates and variance-covariance matrices obtained above. */ title1 'Hausman Wald statistic W. See Greene, eq. (14-37), p. 577'; title2 'The null distribution of W is a chi-square with 3 df.'; proc iml; /* Define the necessary matrices. */ sigmafe = {0.01696 -0.00147 -0.00674, -0.00147 0.00457 -0.00065, -0.00674 -0.00065 0.01487}; betafe = {0.871319, -0.289273, -0.272538}; sigmavc = {0.01095 -0.00139 -0.00745, -0.00139 0.00248 -0.00228, -0.00745 -0.00228 0.01185}; betavc = {1.074999, -0.269801, -0.271511}; d = betafe - betavc; sigmadif = sigmafe - sigmavc; invdif = inv(sigmadif); /* Compute the Hausman Wald statistic and print it out. This statistic is distributed as a chi-square(3) random variable under the null hypothesis. */ w = d`*invdif*d; print w; run;