## Unconditional quantile regression

Occasional Contributor
Posts: 5

# Unconditional quantile regression

Hi.

Does anyone have ever used unconditional quantile regressions using SAS? I am referring to the regression method proposed in Firpo, Fortin and Lemieux (2009). Unconditional Quantile Regressions. Econometrica, Vol. 77. No. 3, 953-73.

If so, where can I find references/code on the application of unconditional quantile regressions?

SAS has the QUANTREG procedure. However, this refers to conditional quantiles, not to the approach that was developed by Firpo et at. (2009).

Thanks.

Contributor
Posts: 57

## Re: Unconditional quantile regression

Hi,

I had the same necessity for my work. Could not find any solution so I tried to write down the code myself.

Possibly you don't need it any longer, but just in case...I report my code it here. It seems that the UQR has been also used in health statistics: https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4282843/

The Unconditional Quantile Regression by Firpo Fortin And Lemieux (2009) can be calculated as an OLS regression of a transformation of the dependent variable. They call this transformation Recentered Influence Function (RIF).

RIF(y_i;t)=q_t+([t-1(y_i<=q_t )])/(f_y (q_t))

where y_i is the dependent variable, q_t is the t quantile of the distribution of y_i , 1(.)  is the indicator function and f_y(q_t) is the pdf of y_i evaluated at q_t.

the main problem is to estimate f_y(q_t).

The authors suggest to evaluate a kernel density at that point. In the code below, the density is estimated through proc kde, then interpolated to find the value at the target quantile. The interpolation algorithm is taken from the great blog of Rick Wicklin .

Any comment or suggestion to improve the code is very welcome.

``````*some data from http://www.economicswebinstitute.org/ecdata.htm;

data temp;
infile DATALINES;
input ID	WAGE	OCCUPATION	SECTOR	UNION	EDUCATION	EXPERIENCE	AGE	SEX	MARR	RACE	SOUTH;
CARDS;
1	5.10	6	1	0	8	21	35	1	1	2	0
2	4.95	6	1	0	9	42	57	1	1	3	0
3	6.67	6	1	0	12	1	19	0	0	3	0
4	4.00	6	0	0	12	4	22	0	0	3	0
5	7.50	6	0	0	12	17	35	0	1	3	0
6	13.07	6	0	1	13	9	28	0	0	3	0
7	4.45	6	0	0	10	27	43	0	0	3	1
8	19.47	6	0	0	12	9	27	0	0	3	0
9	13.28	6	1	0	16	11	33	0	1	3	0
10	8.75	6	0	0	12	9	27	0	0	3	0
11	11.35	6	0	1	12	17	35	0	1	3	0
12	11.50	6	1	1	12	19	37	0	0	3	0
13	6.50	6	0	0	8	27	41	0	1	3	1
14	6.25	6	0	1	9	30	45	0	0	3	1
15	19.98	6	0	0	9	29	44	0	1	3	1
16	7.30	6	2	0	12	37	55	0	1	3	0
17	8.00	6	0	0	7	44	57	0	1	3	1
18	22.20	6	1	1	12	26	44	0	1	3	0
19	3.65	6	0	0	11	16	33	0	0	3	0
20	20.55	6	0	0	12	33	51	0	1	3	0
21	5.71	6	1	1	12	16	34	1	1	3	0
22	7.00	6	1	1	7	42	55	0	1	1	0
23	3.75	6	0	0	12	9	27	0	0	3	0
24	4.50	6	0	0	11	14	31	0	1	1	1
25	9.56	6	0	0	12	23	41	0	1	3	0
26	5.75	6	1	0	6	45	57	0	1	3	1
27	9.36	6	1	0	12	8	26	0	1	3	0
28	6.50	6	0	0	10	30	46	0	1	3	0
29	3.35	6	1	0	12	8	26	1	1	3	0
30	4.75	6	0	0	12	8	26	0	1	3	0
31	8.90	6	0	0	14	13	33	0	0	3	0
32	4.00	6	0	0	12	46	64	1	0	3	1
33	4.70	6	0	0	8	19	33	0	1	3	0
34	5.00	6	0	0	17	1	24	1	0	3	1
35	9.25	6	1	0	12	19	37	0	0	3	0
36	10.67	6	0	0	12	36	54	0	0	1	0
37	7.61	6	2	0	12	20	38	0	1	1	1
38	10.00	6	2	1	12	35	53	0	1	1	0
39	7.50	6	0	0	12	3	21	0	0	3	0
40	12.20	6	1	0	14	10	30	0	1	3	1
41	3.35	6	0	0	12	0	18	0	0	3	0
42	11.00	6	1	1	14	14	34	0	1	3	1
43	12.00	6	1	0	12	14	32	0	1	3	0
44	4.85	6	1	0	9	16	31	1	1	3	0
45	4.30	6	2	0	13	8	27	0	0	3	1
46	6.00	6	1	0	7	15	28	1	1	3	1
47	15.00	6	1	0	16	12	34	0	1	3	0
48	4.85	6	0	0	10	13	29	0	0	3	1
49	9.00	6	0	1	8	33	47	0	1	3	0
50	6.36	6	1	0	12	9	27	0	1	3	0
51	9.15	6	0	0	12	7	25	0	1	3	0
52	11.00	6	1	1	16	13	35	0	1	3	0
53	4.50	6	1	0	12	7	25	1	1	3	0
54	4.80	6	1	0	12	16	34	1	1	3	0
55	4.00	6	0	0	13	0	19	0	0	3	0
56	5.50	6	1	0	12	11	29	1	0	3	0
57	8.40	6	1	0	13	17	36	0	0	3	0
58	6.75	6	1	0	10	13	29	0	1	3	0
59	10.00	6	1	1	12	22	40	0	0	1	0
60	5.00	6	1	0	12	28	46	1	1	3	0
61	6.50	6	0	0	11	17	34	0	0	3	0
62	10.75	6	2	1	12	24	42	0	1	3	0
63	7.00	6	1	0	3	55	64	0	1	2	1
64	11.43	6	2	0	12	3	21	0	0	3	1
65	4.00	6	1	1	12	6	24	0	0	1	0
66	9.00	6	2	0	10	27	43	0	1	3	0
67	13.00	6	1	1	12	19	37	0	1	1	1
68	12.22	6	2	1	12	19	37	0	1	3	0
69	6.28	6	1	0	12	38	56	1	1	3	0
70	6.75	6	1	1	10	41	57	0	1	1	1
71	3.35	6	1	0	11	3	20	0	0	1	1
72	16.00	6	0	1	14	20	40	0	1	3	0
73	5.25	6	0	0	10	15	31	0	1	3	0
74	3.50	6	1	0	8	8	22	0	1	2	1
75	4.22	6	1	0	8	39	53	1	1	3	1
76	3.00	6	1	1	6	43	55	1	1	2	0
77	4.00	6	1	1	11	25	42	1	1	3	1
78	10.00	6	0	1	12	11	29	0	1	3	0
79	5.00	6	0	0	12	12	30	0	1	1	0
80	16.00	6	1	1	12	35	53	0	1	3	1
81	13.98	6	0	0	14	14	34	0	0	3	0
82	13.26	6	0	1	12	16	34	0	1	3	0
83	6.10	6	1	1	10	44	60	1	0	3	0
84	3.75	6	0	0	16	13	35	1	0	3	1
85	9.00	6	1	1	13	8	27	0	0	1	0
86	9.45	6	1	0	12	13	31	0	0	3	0
87	5.50	6	0	1	11	18	35	0	1	3	0
88	8.93	6	0	0	12	18	36	1	1	3	0
89	6.25	6	0	0	12	6	24	1	0	3	1
90	9.75	6	1	1	11	37	54	0	1	3	1
91	6.73	6	1	0	12	2	20	0	1	3	1
92	7.78	6	1	0	12	23	41	0	1	3	0
93	2.85	6	0	0	12	1	19	0	0	3	0
94	3.35	6	1	0	12	10	28	1	1	1	1
95	19.98	6	1	0	12	23	41	0	1	3	0
96	8.50	6	0	1	12	8	26	0	1	1	0
97	9.75	6	1	0	15	9	30	1	1	3	0
98	15.00	6	2	1	12	33	51	0	1	3	0
99	8.00	6	1	0	12	19	37	1	1	3	0
100	11.25	6	0	0	13	14	33	0	1	3	0
101	14.00	6	0	1	11	13	30	0	1	3	0
102	10.00	6	2	0	10	12	28	0	1	3	0
103	6.50	6	0	0	12	8	26	0	0	3	0
104	9.83	6	1	0	12	23	41	0	1	3	0
105	18.50	6	1	0	14	13	33	1	0	3	0
106	12.50	6	0	0	12	9	27	0	1	3	1
107	26.00	6	0	1	14	21	41	0	1	3	0
108	14.00	6	2	0	5	44	55	0	1	3	1
109	10.50	6	0	1	12	4	22	0	1	3	0
110	11.00	6	1	0	8	42	56	0	1	3	0
111	12.47	6	0	1	13	10	29	0	1	3	0
112	12.50	6	2	0	12	11	29	0	0	3	0
113	15.00	6	2	1	12	40	58	0	1	3	0
114	6.00	6	2	0	12	8	26	0	0	3	0
115	9.50	6	2	0	11	29	46	0	1	3	1
116	5.00	6	0	1	16	3	25	0	0	3	0
117	3.75	6	2	0	11	11	28	0	0	3	0
118	12.57	6	0	1	12	12	30	0	1	3	0
119	6.88	6	0	0	8	22	36	1	1	2	0
120	5.50	6	0	0	12	12	30	0	1	3	0
121	7.00	6	0	1	12	7	25	0	1	3	0
122	4.50	6	1	0	12	15	33	1	0	3	0
123	6.50	6	0	0	12	28	46	0	1	3	0
124	12.00	6	1	1	12	20	38	0	1	3	1
125	5.00	6	2	0	12	6	24	0	0	3	1
126	6.50	6	1	0	12	5	23	0	0	3	1
127	6.80	6	1	0	9	30	45	1	1	3	1
128	8.75	6	0	0	13	18	37	0	1	3	0
129	3.75	6	1	0	12	6	24	1	1	1	1
130	4.50	6	0	0	12	16	34	0	0	2	1
131	6.00	6	0	1	12	1	19	0	0	2	1
132	5.50	6	1	0	12	3	21	0	0	3	0
133	13.00	6	0	0	12	8	26	0	1	3	0
134	5.65	6	1	0	14	2	22	0	0	3	0
135	4.80	6	1	0	9	16	31	0	0	1	0
136	7.00	6	2	0	10	9	25	0	1	3	1
137	5.25	6	0	0	12	2	20	0	0	3	0
138	3.35	6	1	0	7	43	56	0	1	3	1
139	8.50	6	1	0	9	38	53	0	1	3	0
140	6.00	6	0	0	12	9	27	0	1	3	0
141	6.75	6	0	0	12	12	30	0	1	3	1
142	8.89	6	1	0	12	18	36	0	1	3	0
143	14.21	6	1	1	11	15	32	0	0	3	0
144	10.78	6	2	1	11	28	45	0	1	1	1
145	8.90	6	2	1	10	27	43	0	1	3	1
146	7.50	6	0	0	12	38	56	0	1	3	1
147	4.50	6	1	0	12	3	21	1	0	3	0
148	11.25	6	0	1	12	41	59	0	1	3	0
149	13.45	6	0	1	12	16	34	0	1	3	1
150	6.00	6	1	0	13	7	26	0	1	3	1
151	4.62	6	1	0	6	33	45	1	0	1	1
152	10.58	6	1	0	14	25	45	0	1	3	0
153	5.00	6	0	0	12	5	23	0	1	3	1
154	8.20	6	0	0	14	17	37	0	0	1	1
155	6.25	6	0	0	12	1	19	0	0	3	1
156	8.50	6	1	0	12	13	31	0	1	3	0
157	24.98	1	0	0	16	18	40	0	1	3	0
158	16.65	1	0	0	14	21	41	0	1	3	1
159	6.25	1	0	0	14	2	22	0	0	3	0
160	4.55	1	0	0	12	4	22	1	0	2	1
161	11.25	1	0	0	12	30	48	1	1	2	1
162	21.25	1	0	0	13	32	51	0	0	3	0
163	12.65	1	0	0	17	13	36	1	1	3	0
164	7.50	1	0	0	12	17	35	0	0	3	0
165	10.25	1	0	0	14	26	46	1	1	3	0
166	3.35	1	0	0	16	9	31	0	0	3	0
167	13.45	1	0	0	16	8	30	0	0	1	0
168	4.84	1	0	1	15	1	22	0	1	3	0
169	26.29	1	0	0	17	32	55	0	1	3	1
170	6.58	1	0	0	12	24	42	1	1	3	0
171	44.50	1	0	0	14	1	21	1	0	3	0
172	15.00	1	1	0	12	42	60	0	1	3	0
173	11.25	1	1	0	16	3	25	1	0	1	0
174	7.00	1	0	0	12	32	50	1	1	3	0
175	10.00	1	0	0	14	22	42	0	0	1	0
176	14.53	1	0	0	16	18	40	0	1	3	0
177	20.00	1	0	0	18	19	43	1	1	3	0
178	22.50	1	0	0	15	12	33	0	1	3	0
179	3.64	1	0	0	12	42	60	1	1	3	0
180	10.62	1	0	0	12	34	52	0	1	3	1
181	24.98	1	0	0	18	29	53	0	1	3	0
182	6.00	1	0	0	16	8	30	0	0	3	1
183	19.00	1	1	0	18	13	37	0	0	3	0
184	13.20	1	0	0	16	10	32	0	0	3	0
185	22.50	1	0	0	16	22	44	0	1	3	0
186	15.00	1	0	0	16	10	32	0	1	3	1
187	6.88	1	0	0	17	15	38	1	1	3	0
188	11.84	1	0	0	12	26	44	0	1	3	0
189	16.14	1	0	0	14	16	36	0	0	3	0
190	13.95	1	0	0	18	14	38	1	1	3	0
191	13.16	1	0	0	12	38	56	1	1	3	0
192	5.30	1	0	0	12	14	32	0	1	1	1
193	4.50	1	0	0	12	7	25	1	1	3	0
194	10.00	1	0	0	18	13	37	1	0	3	1
195	10.00	1	0	0	10	20	36	0	1	3	0
196	10.00	1	0	1	16	7	29	0	1	2	0
197	9.37	1	0	0	16	26	48	1	1	3	0
198	5.80	1	0	0	16	14	36	0	1	3	0
199	17.86	1	0	0	13	36	55	0	0	3	0
200	1.00	1	0	0	12	24	42	0	1	3	0
201	8.80	1	0	0	14	41	61	0	1	3	1
202	9.00	1	0	0	16	7	29	0	1	1	0
203	18.16	1	0	0	17	14	37	0	0	3	1
204	7.81	1	0	0	12	1	19	1	0	3	1
205	10.62	1	1	0	16	6	28	1	1	3	0
206	4.50	1	0	0	12	3	21	1	1	3	0
207	17.25	1	0	0	15	31	52	0	1	3	0
208	10.50	1	1	0	13	14	33	1	1	3	0
209	9.22	1	0	0	14	13	33	1	1	3	0
210	15.00	1	1	1	16	26	48	0	1	1	0
211	22.50	1	0	0	18	14	38	0	1	3	0
212	4.55	2	0	0	13	33	52	1	1	3	0
213	9.00	2	0	0	12	16	34	0	1	3	0
214	13.33	2	0	0	18	10	34	0	1	3	0
215	15.00	2	0	0	14	22	42	0	0	3	0
216	7.50	2	0	0	14	2	22	0	0	3	0
217	4.25	2	0	0	12	29	47	1	1	3	1
218	12.50	2	1	0	12	43	61	0	1	3	0
219	5.13	2	0	0	12	5	23	1	1	3	0
220	3.35	2	0	0	16	14	36	1	1	1	1
221	11.11	2	0	0	12	28	46	0	1	3	1
222	3.84	2	0	0	11	25	42	1	1	1	1
223	6.40	2	0	0	12	45	63	1	1	3	0
224	5.56	2	0	0	14	5	25	0	0	3	1
225	10.00	2	1	0	12	20	38	0	1	3	1
226	5.65	2	0	0	16	6	28	1	1	3	0
227	11.50	2	0	0	16	16	38	0	1	3	0
228	3.50	2	0	0	11	33	50	1	1	3	0
229	3.35	2	0	0	13	2	21	1	1	3	1
230	4.75	2	0	0	12	10	28	1	0	3	1
231	19.98	2	0	0	14	44	64	0	1	3	1
232	3.50	2	0	0	14	6	26	1	1	3	1
233	4.00	2	0	0	12	15	33	1	0	3	0
234	7.00	2	0	0	12	5	23	0	1	3	0
235	6.25	2	1	0	13	4	23	1	1	3	0
236	4.50	2	0	0	14	14	34	0	1	3	0
237	14.29	2	0	0	14	32	52	1	1	3	0
238	5.00	2	0	0	12	14	32	1	1	3	0
239	13.75	2	0	0	14	21	41	0	1	3	0
240	13.71	2	0	1	12	43	61	0	1	3	0
241	7.50	2	0	0	12	27	45	1	1	1	1
242	3.80	2	0	0	12	4	22	1	0	3	0
243	5.00	2	0	0	14	0	20	0	0	2	0
244	9.42	2	0	0	12	32	50	0	1	3	1
245	5.50	2	0	0	12	20	38	0	1	3	0
246	3.75	2	0	0	15	4	25	0	0	3	1
247	3.50	2	0	0	12	34	52	0	1	3	0
248	5.80	2	0	0	13	5	24	0	0	3	0
249	12.00	2	1	0	17	13	36	0	1	3	0
250	5.00	3	0	0	14	17	37	1	1	2	0
251	8.75	3	0	0	13	10	29	1	1	3	1
252	10.00	3	0	0	16	7	29	1	1	3	0
253	8.50	3	0	0	12	25	43	1	0	3	0
254	8.63	3	0	0	12	18	36	1	1	1	0
255	9.00	3	1	0	16	27	49	1	1	3	0
256	5.50	3	0	0	16	2	24	1	0	3	0
257	11.11	3	0	0	13	13	32	0	1	3	0
258	10.00	3	0	0	14	24	44	1	0	3	0
259	5.20	3	0	0	18	13	37	1	1	2	1
260	8.00	3	0	1	14	15	35	1	0	3	0
261	3.56	3	0	0	12	12	30	1	0	2	1
262	5.20	3	0	0	12	24	42	1	1	3	0
263	11.67	3	2	0	12	43	61	1	1	3	0
264	11.32	3	1	0	12	13	31	1	1	3	0
265	7.50	3	0	0	12	16	34	1	1	3	1
266	5.50	3	0	0	11	24	41	1	1	3	0
267	5.00	3	0	0	16	4	26	1	1	3	1
268	7.75	3	0	0	12	24	42	1	1	3	0
269	5.25	3	0	0	12	45	63	1	1	3	0
270	9.00	3	0	1	12	20	38	0	1	3	0
271	9.65	3	0	0	12	38	56	1	1	3	0
272	5.21	3	0	0	18	10	34	0	1	3	1
273	7.00	3	0	0	11	16	33	1	1	1	0
274	12.16	3	0	0	12	32	50	1	1	1	1
275	5.25	3	0	0	16	2	24	1	0	3	1
276	10.32	3	0	0	13	28	47	1	0	3	1
277	3.35	3	0	0	16	3	25	0	0	1	0
278	7.70	3	0	1	13	8	27	1	0	3	0
279	9.17	3	1	0	12	44	62	1	1	3	0
280	8.43	3	0	0	12	12	30	0	1	3	1
281	4.00	3	0	0	12	8	26	0	1	1	1
282	4.13	3	0	0	12	4	22	1	1	3	0
283	3.00	3	0	0	12	28	46	1	1	3	1
284	4.25	3	0	0	13	0	19	1	0	3	1
285	7.53	3	0	0	14	1	21	0	0	3	1
286	10.53	3	1	0	14	12	32	1	1	3	0
287	5.00	3	0	0	12	39	57	1	1	3	0
288	15.03	3	0	0	12	24	42	1	1	3	0
289	11.25	3	0	0	17	32	55	1	1	1	0
290	6.25	3	0	0	16	4	26	0	0	1	0
291	3.50	3	0	0	12	25	43	1	0	1	0
292	6.85	3	0	0	12	8	26	0	0	1	0
293	12.50	3	0	0	13	16	35	1	1	3	0
294	12.00	3	0	0	12	5	23	0	0	3	1
295	6.00	3	0	0	13	31	50	0	0	3	0
296	9.50	3	0	0	12	25	43	1	0	3	0
297	4.10	3	0	0	12	15	33	1	1	3	0
298	10.43	3	0	0	14	15	35	1	1	3	1
299	5.00	3	0	0	12	0	18	1	0	3	0
300	7.69	3	0	0	12	19	37	0	1	3	0
301	5.50	3	0	0	12	21	39	1	0	1	0
302	6.40	3	0	0	12	6	24	1	0	3	0
303	12.50	3	0	1	12	14	32	1	1	3	0
304	6.25	3	0	0	13	30	49	1	1	3	0
305	8.00	3	0	0	12	8	26	1	0	3	0
306	9.60	3	0	1	9	33	48	0	0	3	0
307	9.10	3	0	0	13	16	35	0	0	2	0
308	7.50	3	0	0	12	20	38	1	0	3	1
309	5.00	3	0	0	13	6	25	1	1	3	1
310	7.00	3	0	1	12	10	28	1	1	3	0
311	3.55	3	0	0	13	1	20	1	0	3	1
312	8.50	3	0	0	12	2	20	0	0	1	1
313	4.50	3	0	0	13	0	19	1	0	3	1
314	7.88	3	0	0	16	17	39	0	1	1	0
315	5.25	3	0	0	12	8	26	1	0	3	0
316	5.00	3	0	0	12	4	22	0	0	3	1
317	9.33	3	0	0	12	15	33	1	0	3	0
318	10.50	3	0	0	12	29	47	1	1	3	0
319	7.50	3	0	0	12	23	41	1	1	1	1
320	9.50	3	0	0	12	39	57	1	1	3	1
321	9.60	3	0	0	12	14	32	1	1	3	1
322	5.87	3	0	0	17	6	29	1	0	1	1
323	11.02	3	0	1	14	12	32	0	1	3	1
324	5.00	3	0	0	12	26	44	1	0	3	1
325	5.62	3	0	0	14	32	52	1	1	3	0
326	12.50	3	0	0	15	6	27	1	1	3	0
327	10.81	3	0	0	12	40	58	1	1	3	0
328	5.40	3	1	0	12	18	36	1	1	3	0
329	7.00	3	0	0	11	12	29	1	0	3	0
330	4.59	3	2	0	12	36	54	1	1	3	1
331	6.00	3	0	0	12	19	37	1	1	3	0
332	11.71	3	1	0	16	42	64	1	0	3	0
333	5.62	3	0	0	13	2	21	1	1	2	0
334	5.50	3	0	0	12	33	51	1	1	3	0
335	4.85	3	0	0	12	14	32	1	1	3	1
336	6.75	3	0	0	12	22	40	0	0	3	0
337	4.25	3	0	0	12	20	38	1	1	3	0
338	5.75	3	0	0	12	15	33	1	1	3	0
339	3.50	3	0	0	12	35	53	0	1	3	0
340	3.35	3	0	0	12	7	25	1	1	3	0
341	10.62	3	1	0	12	45	63	1	0	3	0
342	8.00	3	0	0	12	9	27	1	0	3	0
343	4.75	3	0	0	12	2	20	1	1	3	1
344	8.50	3	0	0	17	3	26	0	0	3	1
345	8.85	3	0	1	14	19	39	1	1	1	0
346	8.00	3	0	0	12	14	32	1	1	3	1
347	6.00	4	0	0	4	54	64	0	1	3	0
348	7.14	4	0	0	14	17	37	0	1	3	0
349	3.40	4	0	0	8	29	43	1	1	1	0
350	6.00	4	0	0	15	26	47	1	0	3	1
351	3.75	4	0	0	2	16	24	0	0	2	0
352	8.89	4	0	0	8	29	43	1	0	1	0
353	4.35	4	0	0	11	20	37	1	1	3	0
354	13.10	4	0	0	10	38	54	1	1	1	1
355	4.35	4	0	0	8	37	51	1	1	1	1
356	3.50	4	0	0	9	48	63	0	0	3	0
357	3.80	4	0	0	12	16	34	1	0	3	0
358	5.26	4	0	0	8	38	52	1	1	3	0
359	3.35	4	0	0	14	0	20	0	0	1	0
360	16.26	4	0	1	12	14	32	0	0	1	0
361	4.25	4	0	0	12	2	20	1	1	3	0
362	4.50	4	0	0	16	21	43	0	1	3	0
363	8.00	4	0	0	13	15	34	1	1	3	0
364	4.00	4	0	0	16	20	42	1	0	3	0
365	7.96	4	0	0	14	12	32	1	1	3	0
366	4.00	4	0	0	12	7	25	0	0	2	1
367	4.15	4	0	0	11	4	21	0	1	3	0
368	5.95	4	0	0	13	9	28	0	1	3	1
369	3.60	4	0	0	12	43	61	1	1	2	1
370	8.75	4	0	0	10	19	35	0	0	3	1
371	3.40	4	0	0	8	49	63	1	0	3	0
372	4.28	4	0	0	12	38	56	1	1	3	0
373	5.35	4	0	0	12	13	31	1	1	3	0
374	5.00	4	0	0	12	14	32	1	1	3	0
375	7.65	4	0	0	12	20	38	0	0	3	0
376	6.94	4	0	0	12	7	25	1	0	3	0
377	7.50	4	1	1	12	9	27	1	1	3	0
378	3.60	4	0	0	12	6	24	1	0	3	0
379	1.75	4	0	0	12	5	23	1	1	3	1
380	3.45	4	0	0	13	1	20	1	0	1	1
381	9.63	4	0	1	14	22	42	0	1	3	0
382	8.49	4	0	0	12	24	42	1	1	3	0
383	8.99	4	0	1	12	15	33	1	0	3	0
384	3.65	4	0	0	11	8	25	1	1	3	1
385	3.50	4	0	0	11	17	34	1	1	3	1
386	3.43	4	0	0	12	2	20	0	0	1	1
387	5.50	4	0	0	12	20	38	0	1	3	1
388	6.93	4	0	1	12	26	44	0	1	3	0
389	3.51	4	0	0	10	37	53	1	1	1	1
390	3.75	4	0	0	12	41	59	1	0	3	0
391	4.17	4	0	0	12	27	45	1	1	3	0
392	9.57	4	0	1	12	5	23	1	1	3	0
393	14.67	4	0	0	14	16	36	0	1	1	0
394	12.50	4	0	0	14	19	39	1	1	3	0
395	5.50	4	0	0	12	10	28	0	1	3	0
396	5.15	4	0	1	13	1	20	0	0	3	1
397	8.00	4	0	1	12	43	61	1	1	1	0
398	5.83	4	0	0	13	3	22	0	0	1	0
399	3.35	4	0	0	12	0	18	1	0	3	0
400	7.00	4	0	0	12	26	44	1	1	3	1
401	10.00	4	0	1	10	25	41	1	1	3	0
402	8.00	4	0	0	12	15	33	1	1	3	0
403	6.88	4	0	0	14	10	30	1	0	3	1
404	5.55	4	0	1	11	45	62	1	0	3	0
405	7.50	4	0	0	11	3	20	0	0	1	0
406	8.93	4	0	1	8	47	61	0	1	2	0
407	9.00	4	0	0	16	6	28	1	1	1	0
408	3.50	4	0	0	10	33	49	1	0	3	1
409	5.77	4	1	0	16	3	25	0	0	3	0
410	25.00	4	0	1	14	4	24	0	0	2	0
411	6.85	4	0	1	14	34	54	0	1	1	0
412	6.50	4	0	0	11	39	56	0	1	3	1
413	3.75	4	0	0	12	17	35	1	1	3	1
414	3.50	4	0	1	9	47	62	0	1	3	0
415	4.50	4	0	0	11	2	19	0	0	3	0
416	2.01	4	0	0	13	0	19	0	0	3	1
417	4.17	4	0	0	14	24	44	1	0	3	0
418	13.00	4	0	1	12	25	43	0	1	1	0
419	3.98	4	0	0	14	6	26	1	0	3	0
420	7.50	4	0	0	12	10	28	1	0	3	0
421	13.12	4	0	0	12	33	51	1	1	1	0
422	4.00	4	0	0	12	12	30	0	0	3	0
423	3.95	4	0	0	12	9	27	1	1	3	1
424	13.00	4	0	1	11	18	35	0	1	3	1
425	9.00	4	0	0	12	10	28	0	1	3	0
426	4.55	4	0	0	8	45	59	1	0	3	1
427	9.50	4	0	1	9	46	61	1	1	3	0
428	4.50	4	0	0	7	14	27	0	1	2	1
429	8.75	4	0	0	11	36	53	1	0	3	0
430	10.00	5	2	1	13	34	53	0	1	3	0
431	18.00	5	0	0	18	15	39	0	1	3	0
432	24.98	5	1	0	17	31	54	0	1	3	0
433	12.05	5	1	0	16	6	28	1	0	3	0
434	22.00	5	0	0	14	15	35	0	1	3	1
435	8.75	5	0	0	12	30	48	0	1	3	0
436	22.20	5	0	0	18	8	32	0	1	3	0
437	17.25	5	1	0	18	5	29	0	1	3	0
438	6.00	5	0	1	17	3	26	1	0	3	0
439	8.06	5	0	0	13	17	36	0	1	3	1
440	9.24	5	1	1	16	5	27	0	1	1	0
441	12.00	5	0	0	14	10	30	1	1	3	0
442	10.61	5	0	0	15	33	54	1	0	3	0
443	5.71	5	0	0	18	3	27	0	1	3	0
444	10.00	5	0	0	16	0	18	1	0	3	0
445	17.50	5	0	0	16	13	35	0	1	1	1
446	15.00	5	0	0	18	12	36	0	1	3	0
447	7.78	5	0	0	16	6	28	1	1	3	0
448	7.80	5	0	0	17	7	30	0	1	3	0
449	10.00	5	0	1	16	14	36	0	1	3	1
450	24.98	5	0	0	17	5	28	1	0	3	0
451	10.28	5	0	0	15	10	31	1	1	3	1
452	15.00	5	0	0	18	11	35	1	1	3	0
453	12.00	5	0	0	17	24	47	1	1	3	0
454	10.58	5	1	0	16	9	31	0	0	3	0
455	5.85	5	0	0	18	12	36	0	1	3	1
456	11.22	5	0	0	18	19	43	0	1	3	0
457	8.56	5	0	0	14	14	34	1	1	3	0
458	13.89	5	1	0	16	17	39	1	0	3	0
459	5.71	5	0	0	18	7	31	0	0	3	1
460	15.79	5	0	0	18	7	31	0	1	3	0
461	7.50	5	0	0	16	22	44	1	1	3	0
462	11.25	5	0	0	12	28	46	1	1	3	0
463	6.15	5	0	0	16	16	38	1	0	3	0
464	13.45	5	0	0	16	16	38	0	0	1	1
465	6.25	5	0	0	16	7	29	1	1	3	0
466	6.50	5	0	0	12	11	29	1	0	3	0
467	12.00	5	0	0	12	11	29	1	1	3	0
468	8.50	5	0	0	12	16	34	1	0	3	0
469	8.00	5	0	1	18	33	57	0	0	3	0
470	5.75	5	0	0	12	21	39	1	1	3	1
471	15.73	5	1	0	16	4	26	0	1	3	0
472	9.86	5	0	0	15	13	34	0	1	3	0
473	13.51	5	0	1	18	14	38	0	1	3	0
474	5.40	5	0	0	16	10	32	1	1	3	0
475	6.25	5	0	0	18	14	38	0	1	3	1
476	5.50	5	0	0	16	29	51	0	1	3	1
477	5.00	5	0	0	12	4	22	0	0	2	0
478	6.25	5	0	0	18	27	51	0	1	1	0
479	5.75	5	0	0	12	3	21	0	1	3	0
480	20.50	5	0	1	16	14	36	0	1	3	1
481	5.00	5	2	0	14	0	20	0	1	3	0
482	7.00	5	0	0	18	33	57	0	1	3	0
483	18.00	5	0	0	16	38	60	0	1	3	1
484	12.00	5	0	1	18	18	42	1	1	3	0
485	20.40	5	1	0	17	3	26	0	0	3	0
486	22.20	5	0	0	18	40	64	1	0	3	0
487	16.42	5	1	0	14	19	39	0	0	3	0
488	8.63	5	0	0	14	4	24	1	0	3	0
489	19.38	5	0	0	16	11	33	1	1	3	0
490	14.00	5	0	0	16	16	38	1	1	3	0
491	10.00	5	0	0	14	22	42	0	1	3	0
492	15.95	5	0	1	17	13	36	1	0	3	0
493	20.00	5	0	1	16	28	50	1	1	3	1
494	10.00	5	0	0	16	10	32	1	1	3	0
495	24.98	5	0	0	16	5	27	1	0	3	1
496	11.25	5	0	0	15	5	26	0	0	3	0
497	22.83	5	1	0	18	37	61	1	0	3	0
498	10.20	5	0	1	17	26	49	1	1	3	0
499	10.00	5	0	0	16	4	26	1	1	3	1
500	14.00	5	0	1	18	31	55	1	0	3	0
501	12.50	5	0	1	17	13	36	1	1	3	0
502	5.79	5	0	0	12	42	60	1	1	3	0
503	24.98	5	0	0	17	18	41	0	1	2	0
504	4.35	5	0	0	12	3	21	1	1	3	0
505	11.25	5	0	0	17	10	33	1	0	3	0
506	6.67	5	0	1	16	10	32	1	0	3	0
507	8.00	5	0	0	16	17	39	1	1	2	0
508	18.16	5	0	0	18	7	31	0	1	3	0
509	12.00	5	0	0	16	14	36	1	1	3	0
510	8.89	5	0	1	16	22	44	1	1	3	0
511	9.50	5	0	0	17	14	37	1	1	3	0
512	13.65	5	0	0	16	11	33	0	1	3	0
513	12.00	5	0	1	18	23	47	0	1	3	0
514	15.00	5	0	1	12	39	57	0	1	3	0
515	12.67	5	0	0	16	15	37	0	1	3	0
516	7.38	5	0	0	14	15	35	1	0	2	0
517	15.56	5	0	0	16	10	32	0	0	3	0
518	7.45	5	0	0	12	25	43	1	0	3	1
519	6.25	5	0	0	14	12	32	1	1	3	0
520	6.25	5	0	0	16	7	29	1	1	2	1
521	9.37	5	0	1	17	7	30	0	1	3	0
522	22.50	5	1	0	16	17	39	0	1	3	0
523	7.50	5	0	1	16	10	32	0	1	3	0
524	7.00	5	0	0	17	2	25	0	1	3	1
525	5.75	5	0	1	9	34	49	1	1	1	1
526	7.67	5	0	0	15	11	32	1	1	3	0
527	12.50	5	0	0	15	10	31	0	0	3	0
528	16.00	5	0	0	12	12	30	0	1	3	1
529	11.79	5	0	1	16	6	28	1	0	3	0
530	11.36	5	0	0	18	5	29	0	0	3	0
531	6.10	5	0	0	12	33	51	1	1	1	0
532	23.25	5	0	1	17	25	48	1	1	1	0
533	19.88	5	0	1	12	13	31	0	1	3	1
534	15.38	5	1	0	16	33	55	0	1	3	0
;
run;

data temp1;
set temp;
lwage=log(wage);
age2=age*age;
run;

*calculate the density;
proc kde data=temp1;
univar lwage/out=kde;
run;

*calculate and transpose the percentiles;
proc univariate data=temp1 noprint;
var lwage;
output out=p pctlpre=P_
pctlpts=1 to 99 by 1;
run;
proc transpose data=p out=pt(rename=(col1=value));
run;

data pt(drop=_name_ _label_);
set pt;
retain percentile;
if _n_=1 then percentile=1;
else percentile+1;
run;

*interpolate the density to evaluate it at the percentiles value;

proc iml;
start Last(x); /* Helper module: return last element in a vector */
return( x[nrow(x)*ncol(x)] );
finish;
/* Interpolate such that (x,y) is on line segment between (x1,y1) and (x2,y2) */
start LinInterpPt(x1, x2, y1, y2, x);
m = (y2-y1)/(x2-x1);     /* slope */
return( m#(x-x1) + y1 ); /* point-slope formula */
finish;

/* Linear interpolation: simple version */
start LinInterp1(x, y, v);
/* Given column vectors (x, y), interpolate values for column vector v.
Assume: 1. no missing values in x, y, or v
2. the values of x are unique and sorted
3. each element of v is in the interval [minX, maxX) */
fv = j(nrow(v),1); /* allocate return vector */
do i = 1 to nrow(v);
k = Last( loc(x <= v[i] )); /* largest x less than v[i] */
fv[i] = LinInterpPt(x[k], x[k+1], y[k], y[k+1], v[i]);
end;
return( fv );
finish;

/* test it on some data */
*xy = {0 1,  1 2,  2 4,  4 0 };
*v = {0.1, 1.1, 0.5, 2.7, 3}; /* interpolate at these points */

use kde(keep=value density);
read all var _ALL_ into xy;
close kde;

use pt;
read all var _ALL_ into v;
close pt;

fv = LinInterp1(xy[,1], xy[,2], v[ ,1]);

v2=insert(v, fv, 0, 3);

*print xy;
print v fv v2;

/** create SAS data set from a matrix **/
create pt2 from v2[colname={"value" "percentile" "density"}];
append from v2;
close pt2;

quit;

proc transpose data=pt2 out=p2 prefix=P_;
id percentile;
var value density;
run;

*add the values of the 10,50,90 percentiles and the density evaluated at them to the dataset;
*calculate the the rif transformation;

data temp2;
set temp1;
if _n_ eq 1 then do;
set p2(where=(_NAME_='value') keep=_NAME_ P_10 P_50 P_90);
set p2(where=(_NAME_='density') keep=_NAME_ P_10 P_50 P_90 rename=(P_10=D_10 P_50=D_50 P_90=D_90));
end;
under10=(lwage le P_10);
under50=(lwage le P_50);
under90=(lwage le P_90);
RIF10=P_10+(0.1-under10)/D_10;
RIF50=P_50+(0.5-under50)/D_50;
RIF90=P_90+(0.9-under90)/D_90;

label RIF10='P10'
RIF50='P50'
RIF90='P90'
;
run;

*perform the RIF-OLS regression;
ods graphics off;
ods output ParameterEstimates (persist) = parmrif  fitstatistics (persist) = fitrif nobs(persist) = nobsrif;
proc reg data=temp2 ;
model rif10=sex age age2 education;
model rif50=sex age age2 education;
model rif90=sex age age2 education;
run;
quit;
ods output close;
ods graphics on;
``````

Discussion stats