-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathOfficer_va_test.do
146 lines (115 loc) · 4.73 KB
/
Officer_va_test.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
/*****************************************************************
Project: World Bank Kenya Arbiter
PIs: Anja Sautmann and Antoine Deeb
Purpose: Power calculation
Author: Hamza Syed (based on Antoine's file)
Updated by: Didac Marti Pinto
******************************************************************/
*ssc install vam
//Defining locals
local path "C:\Users\didac\Dropbox\Arbiter Research\Data analysis"
local datapull = "15062023" // "01112023" //"01112023" // "15062023" // "11062023" //"05102022" // "27022023"
local min_cases = 0 // 4 //
// Import data
use "`path'\Data_Clean\cases_cleaned_`datapull'.dta", clear
// Keep only cases relevant for the VA calculations
//Case status, drop pending cases
tab case_status
drop if case_status == "PENDING"
//Keep only relevant cases
keep if usable == 1 // Keeping only relevant case types
drop if issue == 6 | issue == 7 // Dropping pandemic months and newest cases (cutoff)
//Keep only courtstations with >=10 cases
bys courtstation:gen stationcases = _N
drop if stationcases<10
//Keep only mediators with at least K total cases
if `min_cases' > 0 {
bys mediator_id: gen totalcases=_N //Total cases with relevant case types
keep if totalcases >= `min_cases'
}
******************************************************************
* Explore
******************************************************************
// Missing "appointer_user_id"
* All years
count if appointer_user_id == .
count if appointer_user_id != .
* Each year
forvalues y = 2016(1)2023 {
di "Year " `y'
count if appointer_user_id == . & appt_year == `y' //
count if appointer_user_id != . & appt_year == `y' //
}
/*
Conclusion: Significant number of missing appointer id's (around 28%). The
biggest problem is in 2019. Why? Ask Wei.
*/
// Number of different appointing mediators by courtstation
preserve
drop if appointer_user_id == .
bysort courtstation appointer_user_id: gen nvals = _n == 1
collapse (sum) nvals, by(courtstation)
restore
drop if appointer_user_id == .
bysort courtstation appointer_user_id: gen nvals = _n == 1
egen num_appointers_cs = sum(nvals), by(courtstation)
drop if num_appointers_cs == 1
//
* Bomet, Eldoret
/*
drop if appointer_user_id == .
collapse id, by(courtstation appointer_user_id appt_month_year)
sort courtstation appt_month_year
*/
******************************************************************
* VA
******************************************************************
drop if appointer_user_id == .
// Generate half-calendar-year appointment variable
gen firsthalf_year = 0 if appt_month <= 6 // First half year indicator variable
replace firsthalf_year = 1 if appt_month >=7 // Second half year indicator variable
egen appt_halfyear = group(appt_year firsthalf_year) // half-year
// Interaction appointer and date
egen appointer_halfyear=group(appointer_user_id appt_halfyear)
egen appointer_year=group(appointer_user_id appt_year)
foreach tt in "year" "halfyear" {
preserve
*local tt "halfyear"
// VA calculations
vam case_outcome_agreement, teacher(appointer_user_id) year(appt_`tt') ///
driftlimit(3) class(appointer_`tt') controls(i.appt_month_year i.casetype ///
i.courttype i.courtstation i.referralmode) tfx_resid(appointer_user_id) ///
data(merge tv)
rename tv va
// VA calculations - Mediator FE
vam case_outcome_agreement, teacher(appointer_user_id) year(appt_`tt') ///
driftlimit(3) class(appointer_`tt') controls(i.appt_month_year i.casetype ///
i.courttype i.courtstation i.referralmode i.mediator_id) tfx_resid(appointer_user_id) ///
data(merge tv)
rename tv va_medFE
collapse va va_medFE, by(appointer_user_id)
twoway (hist va if va >-1.425 & va < 1.5, freq width(.15) color(red%30) start(-1.425)) ///
(hist va_medFE if va_medFE >-1.425 & va_medFE < 1.5, freq width(.15) color(green%30) start(-1.425) ///
xtitle("Value Added") ///
legend(order(1 "VA" 2 "VA with mediator FE" )) )
graph export "`path'/Output/CAM Officers/off_VA_`tt'_mincasesmedi`min_cases'.png", as(png) replace
restore
}
/*
// Generate T and C groups.
drop if tv == .
gen group_tv = 1 if tv > 0
replace group_tv = 0 if tv <=0
hist tv, freq bin(15)
// Save
*export delimited "`path'\Output\va_groups_pull`datapull'.csv", replace
* Missing appointing CAM Officers
* Number of different appointing CAM officers in each Courtstation
* Overlap of CAM officers vs one after the other:
* Number of CAM Officers who appointed a mediator at the same time
* than another at the same courtstation
* Is there specialization of CAM Officers? Some mediators
* Number of cases per appointing mediator
* Conclusion: VA can be more accurately calculated, but we have less VA's.
* We need to drop courtstations with only 1 appointing mediator? Courtstation
* fixed effects impossible to calculate