-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdescriptive_exhibits.do
281 lines (250 loc) · 12.4 KB
/
descriptive_exhibits.do
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
/*****************************************************************
Project: World Bank Kenya Arbiter
PIs: Anja Sautmann and Antoine Deeb
Purpose: Descriptive exhibits
Author: Hamza Syed
Updated by: Didac Marti Pinto (April 2023)
******************************************************************/
//Define locals
local path "C:\Users\didac\Dropbox\Arbiter Research\Data analysis"
local current_date = c(current_date)
local datapull = "25072023" // "15062023" // "11062023" // "05102022" // "14062023"
/*******************************************************************************
NUMBER OF CASES PER MEDIATOR WITH DIFFERENT RESTRICTIONS
*******************************************************************************/
//Import data
use "`path'/Data_Clean/cases_cleaned_`datapull'.dta", clear
//Number of cases per mediator with different restrictions
*No restrictions
preserve
collapse (count) cases=id, by(mediator_id)
label variable cases "Number of cases"
summ cases
hist cases, graphregion(color(white)) width(1) start(0) color(edkblue) freq ytitle("Number of mediators") title("Number of cases per mediator") note("No restrictions on cases")
*graph save "`path'/Output/cases_per_mediator_raw_`datapull'", replace
graph export "`path'/Output/cases_per_mediator_raw_`datapull'.png", as(png) replace
forvalues i = 3/9 {
gen more_than_`i' = 1 if cases > `i'
}
collapse (sum) more_than_*
gen data_restriction = "No restriction"
tempfile no_restr
save `no_restr'
restore
* Only relevant case types - Children Custody and Maintenance, Matrimonial Property Cases and Succession (Probate & Administration - P&A)
* No cases with a data exclusion condition (issues 1 to 5)
preserve
keep if usable == 1
collapse (count) cases=id, by(mediator_id)
label variable cases "Number of cases"
summ cases
summ cases if cases >= 10
hist cases, graphregion(color(white)) width(1) start(0) color(edkblue) freq ytitle("Number of mediators") title("Number of cases per mediator") note("Only relevant case types. No cases with a data exclusion condition.")
*graph save "`path'/Output/cases_per_mediator_family_`datapull'", replace
graph export "`path'/Output/cases_per_mediator_family_`datapull'.png", as(png) replace
forvalues i = 3/9 {
gen more_than_`i' = 1 if cases > `i'
}
collapse (sum) more_than_*
gen data_restriction = "Only relevant cases. No cases with a data exclusion condition."
tempfile family
save `family'
restore
*Same as above, but also exclude pandemic and recent cases
preserve
keep if usable == 1
drop if issue == 6 | issue == 7
collapse (count) cases=id, by(mediator_id)
label variable cases "Number of cases
summ cases
summ cases if cases >= 10
hist cases, graphregion(color(white)) width(1) start(0) color(edkblue) freq ytitle("Number of mediators") title("Number of cases per mediator") note("Only relevant case types. Exclude pandemic and recent cases. No cases with a data exclusion condition.")
*graph save "`path'/Output/cases_per_mediator_family_excpand_`datapull'", replace
graph export "`path'/Output/cases_per_mediator_family_excpand_`datapull'.png", as(png) replace
forvalues i = 3/9 {
gen more_than_`i' = 1 if cases > `i'
}
collapse (sum) more_than_*
gen data_restriction = "Only relevant cases. No pandemic or recent cases. No cases with a data exclusion condition.."
tempfile family_nopandemic
save `family_nopandemic'
restore
/*Only Jan 2019 to Feb 2020
preserve
keep if ref_date >= date("01012019", "DMY") & ref_date < date("01032020", "DMY")
keep if usable == 1
collapse (count) cases=id, by(mediator_id)
label variable cases "Number of cases
summ cases
summ cases if cases >= 10
hist cases, graphregion(color(white)) width(1) start(0) color(edkblue) freq ytitle("Number of mediators") title("Number of cases per mediator") note("Family, succession and other related cases, Jan2019 to Feb2020")
graph save "`path'/Output/cases_per_mediator_family_2019-202002_`datapull'", replace
graph export "`path'/Output/cases_per_mediator_family_2019-202002_`datapull'.png", as(png) replace
restore
*Only Jan 2021 to Feb 2022
preserve
keep if ref_date >= date("01012021", "DMY") & ref_date < date("01032022", "DMY")
keep if usable == 1
collapse (count) cases=id, by(mediator_id)
label variable cases "Number of cases
summ cases
summ cases if cases >= 10
hist cases, graphregion(color(white)) width(1) start(0) color(edkblue) freq ytitle("Number of mediators") title("Number of cases per mediator") note("Family, succession and other related cases, Jan2021 to Feb2022")
graph save "`path'/Output/cases_per_mediator_family_2021-202202_`datapull'", replace
graph export "`path'/Output/cases_per_mediator_family_2021-202202_`datapull'.png", as(png) replace
forvalues i = 3/9 {
gen more_than_`i' = 1 if cases > `i'
}
collapse (sum) more_than_*
gen data_restriction = "Family, etc. Jan 2021 to Feb 2022"
tempfile family_2122
save `family_2122'
restore
*/
preserve
use `no_restr', clear
append using `family'
append using `family_nopandemic'
*append using `family_2122'
export excel using "`path'/Output/cases_per_mediator_`datapull'.xlsx", firstrow(variables) replace
restore
/*******************************************************************************
NUMBER OF CASES REFERRED MONTHLY
*******************************************************************************/
//Import data
use "`path'/Data_Clean/cases_cleaned_`datapull'.dta", clear
//Keep only relevant cases. No cases with a data exclusion condition (issues 1 to 5).
keep if usable == 1
//Number of cases referred per month
gen case = 1
egen monthly_cases = total(case), by(ref_month_year)
drop case
twoway bar monthly_cases ref_month_year, base(0) graphregion(color(white)) xtitle("month") ytitle("number of cases") title("number of cases referred per month") xlabel(#7) note("Only relevant case types. No cases with a data exclusion condition.")
*graph save "`path'/Output/number_of_cases_monthly_`datapull'", replace
graph export "`path'/Output/number_of_cases_monthly_`datapull'.png", as(png) replace
/*******************************************************************************
CASE TYPES OVER COURTSTATIONS AND YEARS
*******************************************************************************/
//Import data
use "`path'/Data_Clean/cases_cleaned_`datapull'.dta", clear
//Keep only relevant cases. No cases with a data exclusion condition (issues 1 to 5).
keep if usable == 1
//Crosstab of courtstation and casetype
tab courtstation case_type
tab2xl court_station case_type using "`path'/Output/casetype_courtstation_`datapull'", col(1) row(1) replace
//Casetypes by year
tab ref_year case_type
tab2xl ref_year case_type using "`path'/Output/casetype_year_`datapull'", col(1) row(1) replace
/*******************************************************************************
CADASTER ROLLOUT
*******************************************************************************/
/*
//Import data
use "`path'/Data_Clean/cases_cleaned_`datapull'.dta", clear
//Keep only relevant cases. No cases with a data exclusion condition (issues 1 to 5).
keep if usable == 1
//Courtstations with access to cadaster by month
preserve
collapse (first) rollout_month_year, by(courtstation)
sort rollout_month_year
gen cadaster = 1
egen monthly_cadaster = total(cadaster), by(rollout_month_year)
collapse (first) monthly_cadaster, by(rollout_month_year)
gen monthly_courts = sum(monthly_cadaster)
gen mo_diff = rollout_month_year[_n+1]-rollout_month_year
gen mo_temp = 11
gen yr_temp = 2022
gen modate_temp = ym(yr_temp, mo_temp)
replace mo_diff = modate_temp - rollout_month_year if missing(mo_diff)
expand mo_diff
drop mo_diff mo_temp yr_temp modate_temp
bys rollout_month_year: gen instance = _n
by rollout_month_year: gen date_temp = rollout_month_year[1]
gen newdate = date_temp+instance-1
format newdate %tm
drop date_temp instance rollout_month_year
rename newdate rollout_month_year
twoway bar monthly_courts rollout_month_year, base(0) graphregion(color(white)) xtitle("month") ytitle("number of court stations") title("number of court stations with access to cadaster per month") xlabel(#7)
graph save "`path'/Output/courts_with_cadaster_monthly_`datapull'", replace
graph export "`path'/Output/courts_with_cadaster_monthly_`datapull'.png", as(png) replace
drop monthly_cadaster
gen ref_month_year = rollout_month_year
tempfile courts_using_cadaster
save `courts_using_cadaster'
restore
//Courtstations using mediation per month
preserve
collapse (first) first_med_assn_month_year, by(courtstation)
sort first_med_assn_month_year
gen assignment = 1
egen monthly_assignment = total(assignment), by(first_med_assn_month_year)
collapse (first) monthly_assignment, by(first_med_assn_month_year)
gen monthly_courts_assn = sum(monthly_assignment)
gen mo_diff = first_med_assn_month_year[_n+1]-first_med_assn_month_year
gen mo_temp = 11
gen yr_temp = 2022
gen modate_temp = ym(yr_temp, mo_temp)
replace mo_diff = modate_temp - first_med_assn_month_year if missing(mo_diff)
expand mo_diff
drop mo_diff mo_temp yr_temp modate_temp
bys first_med_assn_month_year: gen instance = _n
by first_med_assn_month_year: gen date_temp = first_med_assn_month_year[1]
gen newdate = date_temp+instance-1
format newdate %tm
sort newdate
drop date_temp instance first_med_assn_month_year
rename newdate first_med_assn_month_year
twoway bar monthly_courts_assn first_med_assn_month_year, base(0) graphregion(color(white)) xtitle("month") ytitle("number of court stations") title("number of court stations using mediation per month") xlabel(#7)
graph save "`path'/Output/courts_using_mediation_`datapull'", replace
graph export "`path'/Output/courts_using_mediation_`datapull'.png", as(png) replace
restore
//Correlation between cases per month and number of courts using cadaster per month
preserve
collapse (count) cases=id, by(ref_month_year)
merge m:1 ref_month_year using `courts_using_cadaster'
replace monthly_courts = 0 if missing(monthly_courts)
drop rollout_month_year _merge
reg cases monthly_courts
restore
//Outsheeting the treatment date by courtstation and number of cases pre and post treatment
preserve
sort courtstation med_appt_date
collapse (count) cases=id (first) first_appoint=med_appt_date rollout, by(courtstation post_rollout)
reshape wide cases first_appoint rollout, i(courtstation) j(post_rollout)
rename cases0 pre_rollout_cases
rename cases1 post_rollout_cases
rename rollout0 rollout_date
replace rollout1 = rollout_date if missing(rollout1)
replace rollout_date = rollout1 if missing(rollout_date)
rename first_appoint1 first_appoint_post_rollout
drop first_appoint0 rollout1
replace pre_rollout_cases = 0 if missing(pre_rollout_cases)
replace post_rollout_cases = 0 if missing(post_rollout_cases)
gen gap_rollout_assn = first_appoint_post_rollout - rollout_date
label variable rollout_date "Rollout date of cadaster for the courtstation"
label variable pre_rollout_cases "Cases in mediation before cadaster"
label variable post_rollout_cases "Cases in mediation after cadaster"
label variable first_appoint_post_rollout "First mediator appointment date after rollout of cadaster"
label variable gap_rollout_assn "Days between rollout and first mediator appointment using cadaster"
export excel using "`path'/Output/rollout_by_courtstation_`datapull'.xlsx", firstrow(variables) replace
hist gap_rollout_assn, graphregion(color(white)) width(5) start(0) color(edkblue) freq title("Gap between rollout and first appointment post rollout") note("Bar width is 5, starting from 0")
graph save "`path'/Output/gap_rollout_assign_`datapull'", replace
graph export "`path'/Output/gap_rollout_assign_`datapull'.png", as(png) replace
restore
*/
/*******************************************************************************
OUTCOMES
*******************************************************************************/
//Import data
use "`path'/Data_Clean/cases_cleaned_`datapull'.dta", clear
//Keep only relevant cases. No cases with a data exclusion condition (issues 1 to 5).
keep if usable == 1
// Drop pandemic and recent cases
drop if issue == 6 | issue == 7
//Mean and standard deviation of outcomes by courtstation
preserve
collapse (mean) mean_days=case_days_med mean_success=success (sd) st_dev_days=case_days_med st_dev_success=success (count) cases=id (sum) successful=success (first) rollout, by(courtstation)
sort mean_days
order courtstation rollout cases successful mean_days st_dev_days mean_success st_dev_success
export excel using "`path'/Output/outcomes_courtstation_`datapull'.xlsx", firstrow(variables) replace
restore