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
****&&&& change directory to be the same one where the .xlsx data are located
cd "C:\Users\jcohen2\Desktop\Bryan Graham Stata software\IPT-GWR_Application_SouthVan_Richmond_6-15-17-dumweighted\"
log using vanrich_log, text replace
clear
import excel using "C:\Users\jcohen2\Desktop\Bryan Graham Stata software\IPT-GWR_Application_SouthVan_Richmond_6-15-17-dumweighted\data_for_application.xlsx", firstrow
* run through the list of observations that have gross building area data, from Jan 2006 - Sept 2007 for application
*FOCUS ON WHETHER A PROPERTY IS IN southern part of CITY OF Vancouver (treatment) after the flood, OR other (control), USING 1 CONTROL VARIABLE (lotsize_sqft)
*y is price per square foot of building area
local datasample= _N
gen id= _n
mkmat Long, matrix(weast)
mkmat Lat, matrix(wnorth)
*set bandwidth, h:
scalar h=0.03
forvalues i = 1/`datasample' {
scalar east`i'=weast[`i',1]
scalar north`i'=wnorth[`i',1]
gen dist`i' = (((Long-east`i')^2+(Lat-north`i')^2)^0.5)
gen paren`i'=exp(-0.5*(dist`i'/h)^2)
gen w_w_`i'=(paren`i')^0.5
}
gen y=sale_price/GR_BUILDING_AREA
gen EFF_AGE=2016-EFF_YEAR
gen lotsize_sqft_thous=LotSize_Sqft/1000
gen x1=EFF_AGE*lotsize_sqft_thous
gen x2=x1^2
label variable y "sale price per square ft"
label variable x1 "[effective age]x[lotsize(thous square feet)]"
label variable x2 "([effective age]x[lotsize(thous square feet)])^2"
label variable dum_treat "Treatment Dummy"
label variable lotsize_sqft_thous "Lotsize(thous sqft)"
label variable EFF_AGE "Effective Age"
estpost sum y EFF_AGE lotsize_sqft_thous dum_treat
esttab . using descrip_stats.rtf, replace label cells("mean sd min max count") noobs title(Descriptive Statistics, Vancouver Application)
eststo clear
label variable dum_treat "ATE"
reg y dum_treat x1 x2
eststo m1
esttab . using diff_in_diff.rtf, replace label title(Difference-In-Differences Results, Vancouver Application) stats(r2 N, fmt(3 0 1) label(R-sq)) star(* 0.10 ** 0.05 *** 0.01)
eststo clear
iptATE y dum_treat x1 x2, optroutine(e2)
eststo m2
esttab . using IPT.rtf, replace label title(Inverse Probability Tilting Estimation Results, Vancouver Application) star(* 0.10 ** 0.05 *** 0.01)
mat ATE_IPT=e(b)
mat ATE_variance=e(V)
scalar var_ATE=ATE_variance[1,1]
scalar b_ATE=ATE_IPT[1,1]
scalar v_ATE=(var_ATE)^0.5
eststo clear
*create absolute value of weights
****&&&& NOTE: MUST CHANGE THE DIRECTORY BELOW DEPENDING ON THE PATH OF THE USER
file open applic_file using "C:\Users\jcohen2\Desktop\Bryan Graham Stata software\IPT-GWR_Application_SouthVan_Richmond_6-15-17-dumweighted\myfile.txt", write replace
forvalues i = 1/`datasample' {
*create w times x
gen x1_w_w_`i' = w_w_`i'*x1
gen x2_w_w_`i' =((w_w_`i')*x1)^2
gen dum_treat_w_w_`i' =(w_w_`i')*dum_treat
*run iptATE
iptATE y dum_treat_w_w_`i' x1_w_w_`i' x2_w_w_`i' , optroutine(e2)
*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")
scalar v_ATE`i'=v_w_w_`i'[h_v,h_v]
scalar b_ATE`i'=b_w_w_`i'[1,h_b]
*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
display `i', b_ATE`i', se_ATE`i'
file write applic_file ("`i'") _tab (b_ATE`i') _tab (se_ATE`i') _n
}
file write applic_file ("`i'")
file close applic_file
save vanrich_June2018_with_weights.dta, replace
label data vanrich_data_with_weights
**********************************************
clear
import delimited "C:\Users\jcohen2\Desktop\Bryan Graham Stata software\IPT-GWR_Application_SouthVan_Richmond_6-15-17-dumweighted\myfile.txt"
gen id=v1
gen b_ATE=v2
gen v_ATE=v3
label variable b_ATE "ATE"
label variable v_ATE "Standard Errors of ATE"
drop v1 v2 v3
merge 1:1 id using "C:\Users\jcohen2\Desktop\Bryan Graham Stata software\IPT-GWR_Application_SouthVan_Richmond_6-15-17-dumweighted\vanrich_June2018_with_weights.dta"
export delimited "C:\Users\jcohen2\Desktop\Bryan Graham Stata software\IPT-GWR_Application_SouthVan_Richmond_6-15-17-dumweighted\final_output_file_with_ATEs.txt", replace
estpost sum b_ATE v_ATE
esttab . using GIPT.rtf, replace label cells("mean sd min max count") noobs title(Geographically-Weighted Inverse Probability Tilting Results, bandwidth=0.03)
eststo clear
*now make table of ATE's for each observation
gen tstat=(b_ATE)/((v_ATE)^0.5)
gen stderror=(v_ATE)^0.5
gen Significance=0
replace Significance = 1 if tstat < -1.96
putdocx begin
putdocx paragraph
putdocx text ("Estimates of ATE, Standard Error, and Significance for Each Observation")
putdocx paragraph
putdocx text ("Note that a value of 1 in the 'Significance' column indicates the ATE is statistically significant for that observation")
putdocx paragraph
putdocx text ("bandwidth = 0.03")
putdocx table tbl1 = data("b_ATE stderror tstat Significance Lat Long"), varnames
putdocx save mydata.docx, replace
*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\IPT-GWR_Application_SouthVan_Richmond_6-15-17-dumweighted\runs\myfile.txt" "C:\Users\jcohen2\Desktop\Bryan Graham Stata software\IPT-GWR_Application_SouthVan_Richmond_6-15-17-dumweighted\testfile.txt", replace
log close
end