?++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ? LIMDEP commands for estimating the random coefficients model. + ?++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ? + ? Computes coefficient vector and asymptotic covariance matrix for + ? estimates. Also computes a chi-squared test statistic for the + ? hypothesis of this model against the classical, fixed coefficient + ? regression model + ? + ?********************************************************************** ? To Execute this as a command file instead of the screen editor, for * ? example, if using a mainframe, remove the ? in column one of the * ? commands marked with FILEFILEFILE below, and put a question mark * ? in column 1 of the commands marked with EDITEDITEDIT. Then, just * ? modify the file as noted below and OPEN;INPUT=...the file $ * ?********************************************************************** ? ? The following must be set up for the specific problem. The ? rest of the program is general and does not have to be changed. ? NAMELIST ; X = .... specification of names for RHS $ CREATE ; y = your dependent variable $ CREATE ; Index = your Index variable $ ? ?*********************************************************************** ? NO CHANGES ARE NEEDED BELOW THIS LINE EXCEPT FOR FILE/EDITOR CHANGES * ?*********************************************************************** ? ? Obtain dimensions of problem ? SILENT ? EDITEDITEDIT****** CALCULATE ; NG = max (Index) ? Number of units ; Chisq = 0 ? Test statistic for model ; K = col (X) $ Number of regressors ? ? Some matrices which will contain sums. Zero out first. ? MATRIX ; Sumv = Init (K,K,0) ; bbar = init(K,1,0) ; bb = Sumv ; Sumvi = Sumv ; Sumvib = bbar $ ? ? First pass, compute G = Sum(b(i)b(i)' - G bbar bbar' ? ? PROCEDURE ? FILEFILEFILE****** CALC ; Group=1 $ ? EDITEDITEDIT****** LABEL ; 100 $ ? EDITEDITEDIT****** INCLUDE ; New ; Index = group $ ? Group i REGRESS ; Lhs = y ; Rhs = X $ ? Regression coefficients MATRIX ; bbar = bbar & 1/NG * b ? Mean OLS slope vectors ; bb = bb & b | b' ? Sum of outer products ; Sumv = Sumv & 1/NG * Varb ? Sum Vi ; Sumvi = Sumvi & Sinv(Varb) ? Sum of inverses for b~ ; Sumvib = Sumvib & Sinv(Varb) | b $ Terms in b~ CALC ; Group = Group + 1 $ ? EDITEDITEDIT****** GO TO ; 100 ; Group <= NG $ ? EDITEDITEDIT****** ? ENDPROC ? FILEFILEFILE****** ? EXECUTE ; Silent ; Group = 1,NG $ ? FILEFILEFILE****** ? ? Assemble parts of G. Check for whether to use full or approximation ? MATRIX ; G = bb ~ NG * bbar | bbar' ? Variance of OLS vectors ; G = {1/(NG-1)} * G ~ Sumv $ ? Gamma matrix MATRIX ; Bstar = Sinv(Sumvi) | Sumvib $ ? b* ? ? Check to see if G is positive definite. If not, add back SUMV. ? We check for definiteness by looking at the sign of the smallest ? characteristic root. If it is negative, make the correction. ? MATRIX ; Groot = root(G) $ ? Characteristic roots CALCULATE ; Smlroot = Groot(K) $ ? Smallest root MATRIX ; if[smlroot < 0] G = G & Sumv $ ? Add back term is not PD. ? ? Second pass. Get weighted sum of OLS coefficients ? MATRIX ; Sumv = Init (k,k,0) ? Will be Sum inv(Vi+G) ; brcm = init (k,1,0) $ ? Will be rcm estimator ? ? PROCEDURE ? FILEFILEFILE****** CALC ; Group = 1 $ ? EDITEDITEDIT****** LABEL ; 200 $ ? EDITEDITEDIT****** ? INCLUDE ; New ; Index = group $ ? Group i REGRESS ; Lhs = y ; Rhs = X $ ? Regression MATRIX ; Vi = Nvsm(G,varb) ? inv(G + Vi) ; Sumv = Sumv & Vi ? Sum inv (G + Vi) ; brcm = brcm & Vi | b ? Sum inv (G + Vi)bi ; di = b ~ bstar ? bi - b* ; Vi = Sinv(varb) $ ? inverse of variance CALC ; Chisq = Chisq + Qfr(di,vi) $ ? Chi-squared sum of Qforms CALC ; Group = Group + 1 $ ? EDITEDITEDIT****** GO TO ; 200 ; Group <= NG $ ? EDITEDITEDIT****** ? ENDPROC ? FILEFILEFILE****** ? EXECUTE ; Silent ; Group = 1,NG $ ? FILEFILEFILE****** ? MATRIX ; Vrcm = Sinv (Sumv) ? Variance of estimator ; Brcm = Vrcm | brcm $ ? RCM slope estimator CALC ; L = K*(NG-1) $ ? Degrees of freedom CALC ; CHISQ ; CHI (Chisq,L) $