FUNCTION KPMEDF (IL,ID,N,P) C++ C++ IL= ARRAY CONTAINING INCOME INTERVAL LIMITS C++ ID= ARRAY CONTAINING NUMER WITHIN THE INCOME INTERVAL C++ N = NUMBER OF INCOME INTERVALS C++ P = PERCENTILE FOR WHICH YOU WISH AN ESTIMATE IE. 50 FOR MEDIAN C++ KPMEDF= ESTIMATE OF PERCENTILE CUTOFF C++ IMPLICIT INTEGER(A-W) LOGICAL DEBUG DIMENSION ID(N),IL(N) REAL P,XP,XN,SX1 DEBUG=.FALSE. C++ C++ PRINTING DEBUG INPUT VARIABLES C++ IF(DEBUG) THEN DO 1 I=1,N PRINT *,' I,IL,ID,N,P= ',I,IL(I),ID(I),N,P 1 CONTINUE ENDIF C++ SX=0 SX1=0. KPMEDF=0. IF(P.LE.0 .OR. P.GE.100) RETURN IF (ID(1))2,50,2 2 XP = ID(1)*(100.-P)/100. DO 30 I=2,N SX = SX + ID(I) SX1=ID(I)-SX+XP C++ C++ MORE DEBUG PRINTING C++ IF(DEBUG)PRINT *,' I,IL,ID,SX,SX1,XP= ',I,IL(I),ID(I),SX,SX1,XP C++ C++ FINDING THE INTERVAL CONTAINING THE PERCENTILE CUTOFF C++ IF (XP-SX)4,10,30 C++ C++ LINEAR INTERPOLATION ON INTERVALS .LE. \$2,500 WIDTH C++ 4 IF(IL(I)-IL(I-1).LE.2500.OR.IL(I-1).LE.0) THEN KPMEDF = SX1/ID(I)*(IL(I)-IL(I-1))+IL(I-1)+.5 C++ C++ DEBUG PRINTING C++ IF(DEBUG) PRINT *,' KPMEDF= ',KPMEDF C++ C++ PARETO INTERPOLATION ELSEWHERE (\$2,500+ WIDTH) C++ ELSE XT2 = ID(1)-SX XT1 = XT2+ID(I) IF (XT2.LE.0) XT2=.001*ID(1) XN = ALOG10(XP/XT1)/ALOG10(1.*XT2/XT1)* * ALOG10(1.*IL(I)/IL(I-1)) KPMEDF = IL(I-1)*10.**XN+.5 ENDIF C++ RETURN 10 KPMEDF = IL(I) RETURN 30 CONTINUE 50 KPMEDF = 0 RETURN END