version 13 clear all macro drop _all set linesize 80 cap log close set more off *============= PEARSON CORRELATION =========== gl root "C:\DROPBOX\Dropbox\TESTS_COLOMBIA" gl directory "$root\DATA\CLEANDATA\v4_tests\idb_portal\tests_bogota.dta" gl code "$root\DATA\CODE\v4_analysis_tests\idb_portal\pearson\bs_se" gl out "$root\DATA\CODE\v4_analysis_tests\idb_portal\pearson\bs_se" gl core "$root\DATA\CODE\v4_analysis_tests\idb_portal\core" log using "$code/bayley_mac_pearson_12mths.log", replace gl col_vars r_b_st_cog_kd r_b_st_lr_kd r_b_st_le_kd r_b_st_mf_kd r_b_st_mg_kd // variables Bayley gl flag_all flag_all_b_mac //define flag with all data between tests gl flag_col b_flag_outlier //define col_vars outlier gl flag_row mac_flag_outlier //define row_vars outlier ********Definir dataset de trabajo******* use "$directory", replace //open dataset keep if $flag_all == 1 //keep useful data, deleting outliers and missed *keep if $flag_row == 0 keep if $flag_col == 0 keep if battery == 2 //replace with corresponding battery (1=batB, 2=batA) g age_cat = 1 if b_age_mth >=6 & b_age_mth <=14 replace age_cat = 2 if b_age_mth >=15 & b_age_mth <=23 replace age_cat = 3 if b_age_mth >=24 & b_age_mth <=32 replace age_cat = 4 if b_age_mth >=33 & b_age_mth <=42 g estrato_flag =estrato replace estrato_flag =3 if estrato ==4 g strata =. foreach x in 1 2 3 4 { foreach y in 1 2 3 { qui replace strata =`y'`x' if age_cat ==`x' & estrato_flag ==`y' } } tempfile dataset save `dataset', replace //****************Bayley vs Mac: 8-18 months u `dataset', clear gl row_vars r_mac_st_lr_kd r_mac_st_le_kd foreach y of glo col_vars { foreach x of glo row_vars { bootstrap corr =r(rho), reps(1000) seed(1978) level(95) nodots nowarn strata(strata): corr `y' `x' if b_age_mth>=8 & b_age_mth<=18 mat `y'_`x' =r(table)' } } foreach y of glo col_vars { mat mac_`y' =(`y'_r_mac_st_lr_kd \ `y'_r_mac_st_le_kd) } mat mac_818 =(mac_r_b_st_cog_kd \ mac_r_b_st_lr_kd \ mac_r_b_st_le_kd \ mac_r_b_st_mf_kd \ mac_r_b_st_mg_kd) di "****************8-18 months number of observations************** di e(N) //****************Bayley vs Mac: 19-30 months u `dataset', clear gl row_vars r_mac_st_le_kd foreach y of glo col_vars { foreach x of glo row_vars { bootstrap corr =r(rho), reps(1000) seed(1978) level(95) nodots nowarn strata(strata): corr `y' `x' if b_age_mth>=19 & b_age_mth<=30 mat `y'_`x' =r(table)' } } foreach y of glo col_vars { mat mac_`y' =(`y'_r_mac_st_le_kd) } mat mac_1930 =(mac_r_b_st_cog_kd \ mac_r_b_st_lr_kd \ mac_r_b_st_le_kd \ mac_r_b_st_mf_kd \ mac_r_b_st_mg_kd) di "****************19-30 months number of observations************** di e(N) //*****Convert Matrices to Datasets foreach x in 818 1930 { svmat mac_`x' keep mac_`x'1-mac_`x'6 drop if _n >=40 ren mac_`x'1 b ren mac_`x'2 se ren mac_`x'3 z ren mac_`x'4 pvalue ren mac_`x'5 ll ren mac_`x'6 ul save "$out\mac_`x'.dta", replace }