Code:
* Example generated by -dataex-. To install: ssc install dataex clear input int year_reported str14 type_cases_reported str4 gender_children byte number_cases 2019 "Neglect" "girl" 1 2019 "Neglect" "boy" 1 2020 "Child Marriage" "girl" 1 2020 "Physical Abuse" "boy" 1 2019 "Defilement" "girl" 2 2021 "Child Labour" "boy" 2 2020 "Physical Abuse" "girl" 4 2021 "Physical Abuse" "boy" 4 2020 "Defilement" "girl" 7 2020 "Neglect" "boy" 8 2019 "Physical Abuse" "boy" 8 2019 "Physical Abuse" "girl" 8 2021 "Physical Abuse" "girl" 13 2021 "Defilement" "girl" 15 2021 "Neglect" "girl" 18 2021 "Neglect" "boy" 18 end
DATE CREATED:02-Feb-2022
DATE UPDATED:
STATA Version: 15
PURPOSE: Surmarise and clean the data for the report for the survey
*/
clear
cap set maxvar 32767
set more off
//set the global paths for the data
global drive P:\Stata
*** define the global variables
//define the paths based on the location of data in your laptop
global DATA ${drive}\Data\Lovender
global CODES ${drive}\codes
global OUTPUT ${drive}\Output\Lovender
// import the excel file for where its saved
import excel using "${DATA}\Baseline_Assessment_Survey_results.xl sx", sheet("Baseline_Assessment_Survey_resu") firstrow clear
// Recode the Cases reported at Police station
rename Cases_policeyr_report year_reported
rename Cases_policecases_report type_cases_reported
rename Cases_policegender_report gender_children
rename Cases_policenumber_of_cases number_cases
rename Cases_officersteacher_bearer reported_teachers
rename Cases_officerspoliceofficer_bea reported_police
rename Cases_officerschief_bearer reported_chief
rename Cases_officersrelative_bearer reported_relative
rename Cases_officerssibling_bearer reported_sibling
rename Cases_officersparent_bearer reported_parent
// recode the type of cases
replace type_cases_reported = "Child Labour" if type_cases_reported=="c_lab"
replace type_cases_reported = "Child Marriage" if type_cases_reported=="c_mar"
replace type_cases_reported = "Defilement" if type_cases_reported=="def"
replace type_cases_reported = "Neglect" if type_cases_reported=="neg"
replace type_cases_reported = "Physical Abuse" if type_cases_reported=="phy"
// handle the cases
drop if number_cases==0
// recode the cases
gen cases = 1 if number_cases==1
replace cases = 2 if number_cases==2
replace cases = 4 if number_cases==4
replace cases = 7 if number_cases==7
replace cases = 8 if number_cases==8
replace cases = 13 if number_cases==13
replace cases = 15 if number_cases==15
replace cases = 18 if number_cases==18
bysort cases : gen or_test=_n
bysort cases : gen gen_test=_N
gen indvid_cases =.
**gen reported_cas = 0
set trace on
gen d =0
// create a loop to create single records of the cases
// I am getting stuck in this section of the LOOP, its not listing all 111 cases, my code is ending up with 16.
foreach y of numlist 1 2 4 7 8 13 15 18 {
disp `y'
}
forvalues j = 1/`y' {
replace indvid_cases=1
}
0 Response to Help break my aggregate data
Post a Comment