-
Notifications
You must be signed in to change notification settings - Fork 0
/
LORENZ.fjg
140 lines (127 loc) · 4.2 KB
/
LORENZ.fjg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
LORENZ CURVES June/98 - R6: April/12
*/
COM [STRING] %%LORENZ = 'LORENZ - Version R6: April/12'
PROC LORENZ Y TBEGP TENDP OUTGINI OUTLX OUTLY OUTGLY OUTALY OUTLYSE
TYPE SER Y *OUTLX *OUTLY *OUTGLY *OUTALY *OUTLYSE
TYPE INT TBEGP TENDP
TYPE REAL *OUTGINI
*
LOCAL INTEGER TBEG TEND I J
LOCAL REAL G
LOCAL SERIES S W P SMPL LX LY TY TP
LOCAL VECTOR Q L LSE
LOCAL STRING STR
*
OPTION SWITCH PRINT 1
OPTION SWITCH GRAPH 1
OPTION SWITCH SAMPLE 0
OPTION SWITCH REVERSE 0
OPTION SWITCH SE 0
OPTION INTEGE REPLICAS 100
OPTION VECTOR QUANTIL
OPTION SERIES WEIGHT
OPTION SERIES SMPLL
* Globals
COM %MEAN = %NA, %NOBS = 0
INQUIRE(SERIES=Y) TBEG>>TBEGP TEND>>TENDP
IF %DEFINED(SMPLL)
SET SMPL TBEG TEND = %IF(SMPLL<>0.AND.%VALID(Y),1,0)
ELSE
SET SMPL TBEG TEND = %VALID(Y)
IF %DEFINED(WEIGHT)
SET P TBEG TEND = WEIGHT
ELSE
SET P TBEG TEND = 1.
SAM(SMPL=SMPL) Y TBEG TEND S 1
SAM(SMPL=SMPL) P TBEG TEND W 1
INQ(SER=S) * %NOBS
IF SAMPLE
{
* Lorenz Curves at sample points
ORDER S 1 %NOBS W
SET TY 1 %NOBS = S*W
ACC(SCALE) TY 1 %NOBS TY 1
ACC(SCALE) W 1 %NOBS TP 1
SET(FIRST=0.) LX 1 %NOBS+1 = TP{1}
SET(FIRST=0.) LY 1 %NOBS+1 = TY{1}
COM J = %NOBS-1, STR = 'sample points'
CLE TY TP
}
ELSE
{
IF %DEFINED(QUANTIL)
{
DIM L(%ROWS(QUANTIL))
EWI L(I) = %IF(QUANTIL(I)<=0.OR.QUANTIL(I)>=1,0,1)
COM Q = %SORT(%COMPRESS(QUANTIL,L)), J = %ROWS(Q), STR = 'user defined points'
}
ELSE
{
IF %NOBS.LT.20 ; COM J = 3, STR = '25%-quantiles (quartiles)'
ELSE IF %NOBS.LT.50 ; COM J = 9, STR = '10%-quantiles (deciles)'
ELSE IF %NOBS.LT.200; COM J = 19, STR = '5%-quantiles (veintiles)'
ELSE ; COM J = 99, STR = '1%-quantiles (percentiles)'
DIM Q(J)
EWI Q(I) = I/(J+1.)
}
IF .NOT.%DEFINED(WEIGHT)
{
IF REVERSE==0
{
COM L = %LORENZ(S,Q)
IF SE; COM LSE = %LORENZ_BOOTSE(S,Q,REPLICAS)
}
ELSE
COM L = %RLORENZ(S,Q)
}
ELSE
{
IF REVERSE==0
{
COM L = %WLORENZ(S,W,Q)
IF SE; COM LSE = %WLORENZ_BOOTSE(S,W,Q,REPLICAS)
}
ELSE
COM L = %RWLORENZ(S,W,Q)
}
SET(FIRST=0.) LX 1 J+2 = %IF(T==J+2,1,%IF(REVERSE==0,Q(T-1),L(T-1)))
SET(FIRST=0.) LY 1 J+2 = %IF(T==J+2,1,%IF(REVERSE==1,Q(T-1),L(T-1)))
IF SE==1.AND.REVERSE==0
SET(FIRST=0.) TP 1 J+2 = %IF(T==J+2,0,LSE(T-1))
}
COM %MEAN = %M(S,W), G = %GININUMINT(LX,LY)
SET TY 1 J+2 = LY*%MEAN
CLE P
SET P 1 J+2 = (LY - LX)*%MEAN
IF PRINT
{
DIS 'Lorenz curve on Series' %L(Y) 'estimated at '+STR %IF(%DEFINED(WEIGHT),'weighted by '+%LABEL(WEIGHT),'')
DIS 'Observations' %NOBS @+5 '(' @-1 TEND-TBEG+1 'Total -' (TEND-TBEG+1)-%NOBS 'Skipped/Missing)'
DIS 'Sample period: From' %DATELABEL(TBEG) 'to' %DATELABEL(TEND)
IF SE==1.AND.SAMPLE==0.AND.REVERSE==0; DIS 'Bootstrap Standard Errors in brackets:' REPLICAS 'replications'
DIS 'Gini index ' G @41 'Welfare Gini index' %MEAN*(1-G)
DIS 'Sample mean ' %MEAN
DIS
DIS ' Abcisa (%) Ordinate (%)' %IF(SE==1.AND.SAMPLE==0.AND.REVERSE==0,'Standard Error','') ' Generalized' @+8 'Absoluta'
DO I = 1,J+2
IF SE==1.AND.SAMPLE==0.AND.REVERSE==0
DIS @3 ###.## LX(I)*100 @+9 LY(I)*100 @+8 '(' @-1 TP(I)*100 @-1 ')' @+3 * TY(I) @+3 P(I)
ELSE
DIS @3 ###.## LX(I)*100 @+9 LY(I)*100 @+5 * TY(I) @+3 P(I)
END DO I
DIS;DIS
}
IF GRAPH
SCA(HMAX=1.0,HMIN=0.0,VMAX=1.0,VMIN=0.0,STYLE=LINES,VLABEL='Cumulative income', $
HLABEL='Cumulative population',HEADER='Lorenz Curve',SUBHEAD=%L(Y)) 2
# LX LX 1 J+2 1
# LX LY 1 J+2 1
IF %DEFINED(OUTGINI); COM OUTGINI = G
IF %DEFINED(OUTLX) ; SET OUTLX 1 J+2 = LX
IF %DEFINED(OUTLY) ; SET OUTLY 1 J+2 = LY
IF %DEFINED(OUTGLY) ; SET OUTGLY 1 J+2 = TY
IF %DEFINED(OUTALY) ; SET OUTALY 1 J+2 = P
IF %DEFINED(OUTLYSE); SET OUTLYSE 1 J+2 = TP
CLE S W SMPL LX LY TY TP P
END PROC LORENZ