Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
****&&&&& MUST RUN THE FOLLOWING BEFORE RUNNING:
****&&&& ssc install iptATE (this is case-sensitive)
****&&&& ssc install estout
****&&&& ssc install graph3d
****&&&& change directory to be the same one where the data are located
log using graph600, text replace
*expand matsize
set matsize 600
cd "C:\Users\jcohen2\Desktop\Bryan Graham Stata software\bandwidth_selection_600"
**have one set of 500 repetitions (i.e., observationsnum=500) so that we can just draw the graphs for the first repetition
local repetitions_600=1
local observationsnum=600*500
****&&&& NOTE: MUST CHANGE THE DIRECTORY BELOW DEPENDING ON THE PATH OF THE USER
cd "C:\Users\jcohen2\Desktop\Bryan Graham Stata software\bandwidth_selection_600\"
*******************************************NOW USE THIS OPTIMAL BANDWIDTH TO RUN GIPT WITH THE 500 REPETITIONS********************
forvalues j=1/`repetitions_600' {
****&&&& NOTE: MUST CHANGE THE DIRECTORY BELOW DEPENDING ON THE PATH OF THE USER
cd "C:\Users\jcohen2\Desktop\Bryan Graham Stata software\bandwidth_selection_600\data_600"
import delimited using cross_section_data600100.csv, clear
gen optimal_b=0.75
gen z=0
cd "C:\Users\jcohen2\Desktop\Bryan Graham Stata software\bandwidth_selection_600\dir_600_500reps_makegraph"
file open applic_file_600_`j' using "C:\Users\jcohen2\Desktop\Bryan Graham Stata software\bandwidth_selection_600\dir_600_500reps_makegraph\myfile_600_`j'.txt", write
****the next 2 lines create a block of 600 observations, so the first 600 have a=1, the next 600 have a=2, etc
set obs `observationsnum'
egen a = seq(), b(600)
label data data_600
local datasample= _N
gen id= _n
gen Lat=g1
gen Long=g2
gen y1=y
gen x1=x
gen x12=x^2
*d_treatnew is the treatment dummy, i.e., properties in the city (d_treat) after the storm (d_time)
gen d_treat=dtreat
gen d_time=dtime
gen d_treatnew=d_treat*d_time
keep if `j' == a
file write applic_file_600_`j' "number" _tab "b_ate" _tab "se_ate" _tab "b_trueate" _n
forvalues i = 1/600 {
gen dist`i' = ((Long-Long[`i'])^2+(Lat-Lat[`i'])^2)^0.5
gen paren`i'=exp(-0.5*(dist`i'/(optimal_b))^2)
gen w_w_`i'=(paren`i')^0.5
label variable y1 "y"
label variable x1 "x"
label variable d_treatnew "Treatment Dummy"
*create w times x
gen x1_w_w_`i' = w_w_`i'*x1
gen x12_w_w_`i' =((w_w_`i')*x1)^2
gen dum_treat_w_w_`i' =(w_w_`i')*d_treatnew
*run iptATE
cd "C:\Users\jcohen2\Desktop\Bryan Graham Stata software\bandwidth_selection_600"
iptATE y dum_treat_w_w_`i' x1_w_w_`i' x12_w_w_`i' , optroutine(e2)
cd "C:\Users\jcohen2\Desktop\Bryan Graham Stata software\bandwidth_selection_600\dir_600_500reps_makegraph"
*save coefficients and V-cov matrix
mat b_w_w_`i'=e(b)
mat v_w_w_`i'=e(V)
*note h_b and h_v is the column number where the ate is listed, in both the parameter vector and the vcov vector
scalar h_b=colnumb(b_w_w_`i', "ate:gamma")
scalar h_v=colnumb(v_w_w_`i', "ate:gamma")
*here use `i' because the ATE varies with each observation in GIPT
scalar v_ATE`i'=v_w_w_`i'[h_v,h_v]
scalar b_ate`i'=b_w_w_`i'[1,h_b]
scalar trueate`i' = trueate[`i']
*take the square root of the ate variance to get the standard error (se) of the ate
scalar se_ate`i'=(v_ATE`i')^0.5
*write b and se to txt file
file write applic_file_600_`j' ("`i'") _tab (b_ate`i') _tab (se_ate`i') _tab (trueate`i') _n
drop dist`i'
drop paren`i'
drop w_w_`i'
drop x1_w_w_`i'
drop x12_w_w_`i'
drop dum_treat_w_w_`i'
}
file close applic_file_600_`j'
save "C:\Users\jcohen2\Desktop\Bryan Graham Stata software\bandwidth_selection_600\dir_600_500reps_makegraph\data_600_`j'.dta"
label data bw_select_600_July2018_with_weights_600.dta
**********************************************
clear
import delimited "C:\Users\jcohen2\Desktop\Bryan Graham Stata software\bandwidth_selection_600\dir_600_500reps_makegraph\myfile_600_`j'.txt"
*since the id is 1 thru 600 in all iterations of myfile_`bw'_`j' but id is the actual number from the original data file in bwselect_600_July2018_with_weights_`bw'_`j'.dta we need to make the transforation in the next line
gen id=number +(600*(`j'-1))
label variable b_ate "ATE"
label variable se_ate "Standard Errors of ATE"
label variable b_trueate "True ATE"
merge 1:1 id using "C:\Users\jcohen2\Desktop\Bryan Graham Stata software\bandwidth_selection_600\dir_600_500reps_makegraph\data_600_`j'.dta"
drop _merge
export delimited "C:\Users\jcohen2\Desktop\Bryan Graham Stata software\bandwidth_selection_600\dir_600_500reps_makegraph\data_for_graph_600_`j'.csv",
*now calculate MASE, noting that since the 100 reps are all in one, calculating the ASE for all obs is the same as doing the ASE for each sample, then taking the mean of the ASEs
gen difference_600=b_ate-trueate
gen difference2_600=difference_600^2
sum difference2_600
mat ASE_mat_600_`j'=r(mean)
scalar ASE_600_`j'=ASE_mat_600_`j'[1,1]
sum difference_600
mat bias_mat_600_`j'=r(mean)
scalar bias_600_`j'=bias_mat_600_`j'[1,1]
set obs 600
drop id
drop b_ate
drop se_ate
drop b_trueate
}
scalar MASE_sum_600=0
scalar MASE_600=0
scalar bias_600=0
scalar bias_sum_600=0
forvalues j=1/`repetitions_600' {
scalar MASE_sum_600 = ASE_600_`j' + MASE_600
scalar MASE_600 = MASE_sum_600
scalar bias_sum_600 = bias_600_`j' + bias_600
scalar bias_600 = bias_sum_600
}
scalar MASE_600 = MASE_sum_600/`repetitions_600'
scalar bias_600 = bias_sum_600/`repetitions_600'
forvalues j=1/`repetitions_600' {
clear
import delimited "C:\Users\jcohen2\Desktop\Bryan Graham Stata software\bandwidth_selection_600\dir_600_500reps_makegraph\myfile_600_`j'.txt"
save "C:\Users\jcohen2\Desktop\Bryan Graham Stata software\bandwidth_selection_600\dir_600_500reps_makegraph\stata_myfile_600_`j'", replace
}
clear
use "C:\Users\jcohen2\Desktop\Bryan Graham Stata software\bandwidth_selection_600\dir_600_500reps_makegraph\stata_myfile_600_1"
save "C:\Users\jcohen2\Desktop\Bryan Graham Stata software\bandwidth_selection_600\dir_600_500reps_makegraph\myfile_600_all", replace
clear
use "C:\Users\jcohen2\Desktop\Bryan Graham Stata software\bandwidth_selection_600\dir_600_500reps_makegraph\myfile_600_all"
forvalues j=2/`repetitions_600' {
append using "C:\Users\jcohen2\Desktop\Bryan Graham Stata software\bandwidth_selection_600\dir_600_500reps_makegraph\stata_myfile_600_`j'"
save "C:\Users\jcohen2\Desktop\Bryan Graham Stata software\bandwidth_selection_600\dir_600_500reps_makegraph\myfile_600_all", replace
}
export delimited "C:\Users\jcohen2\Desktop\Bryan Graham Stata software\bandwidth_selection_600\dir_600_500reps_makegraph\all_data_600.txt", delimiter(tab)
*rename applic_file so that there won't be problems the next time this program runs
shell ren "C:\Users\jcohen2\Desktop\Bryan Graham Stata software\bandwidth_selection_600\dir_600_500reps_makegraph\myfile_600_`j'.txt" "C:\Users\jcohen2\Desktop\Bryan Graham Stata software\bandwidth_selection_600\dir_600_500reps\testfile_600_`j'.txt", replace
cd "C:\Users\jcohen2\Desktop\Bryan Graham Stata software\bandwidth_selection_600"
log close