Skip to content
Snippets Groups Projects
Commit bb06a5c4 authored by Eddie Yu's avatar Eddie Yu
Browse files

Long Diff Estimate: deleted preserve-restore code in order to speed regression

parent df422a54
No related branches found
No related tags found
No related merge requests found
......@@ -132,7 +132,7 @@ gen wgt=base_emp/(r(N) * r(mean))
winsor wgt, p(.01) gen(wgt_w)
sum pr_link_i $pr_wgt if base_emp > 0, d
// replace pr_link_i = pr_link_i/(r(p75)-r(p25)) // this line only changes
replace pr_link_i = pr_link_i/(r(p75)-r(p25)) // this line only changes
sum pr_link_al $pr_wgt if base_emp > 0, d
replace pr_link_al = pr_link_al/(r(p75)-r(p25))
......@@ -148,7 +148,7 @@ destring industry_code, replace
* keeping variables and saving
keep emp_growth pr_link_i year wgt pid industr fips_state base_emp
keep emp_growth pr_link_a pr_link_i year wgt pid industr fips_state base_emp
save "$data/Replication Data/figure6_data_A", replace
......
......@@ -29,6 +29,60 @@ replace bin_pr_link = `idx' + 1 if pr_link_i > 4
tab bin_pr_link, summ(pr_link_i) // 40% of sample has PR exposure = 0
// Regressions
keep if year == 1990 | year == 1995 | year == 2012
xi i.year|pr_link_i , noomit
drop _IyeaXp*1995
xi i.year*i.bin_pr_link, noomit
drop _IyeaXbin_*_1
drop _IyeaXbin_1995_*
local loopvalues = "2/10"
forval i = `loopvalues' {
label var _IyeaXbin_2012_`i' "Bin `i'"
}
local loopvalues = "2/10"
forval i = `loopvalues' {
label var _IyeaXbin_2012_`i' "Bin `i'"
}
forval i = `loopvalues' {
eststo bin_`i': reghdfe emp_growth _IyeaX* [aw=wgt] if bin_pr_link == 1 | bin_pr_link == `i', a(i.pid i.year#i.industr ) cl(fips_state indust ) nocons
lincom _IyeaXbin_2012_`i'
estadd local beta_pr = string(r(estimate), "%8.3fc")
estadd local se_pr = "(" + string(r(se), "%8.3fc") + ")"
estadd local p_pr = "[" + string(r(p), "%8.3fc") + "]"
estadd local ci_pr = "[" + string(r(lb), "%8.3fc") + "," + string(r(ub), "%8.3fc") + "]"
estadd local lb_pr = string(r(lb), "%8.3fc")
estadd local ub_pr = string(r(ub), "%8.3fc")
summ pr_link_i if bin_pr_link == `i', d
estadd local avg_pr_link = string(r(mean), "%8.3fc")
estadd local beta_pr_scaled = string( _b[_IyeaXbin_2012_`i'] / r(mean), "%8.3fc")
estadd local iqr_adj_pr_link = string(r(mean)/$iqr, "%8.3fc")
estadd local beta_pr_scaled_iqr = string( _b[_IyeaXbin_2012_`i'] / (r(mean)/$iqr ), "%8.3fc")
}
esttab bin_* using sun_shapiro_pr_cutbins_longdiff.tex, drop(*) stats(beta_pr se_pr p_pr ci_pr avg_pr_link iqr_adj_pr_link beta_pr_scaled beta_pr_scaled_iqr N, ///
labels("Long Diff Estimate" "s.e." "p-val" "95\% CI" ///
"Mean PR Exposure" "Mean PR Exposure (IQR adjusted)" "Estimate / Mean PR Exposure" "Estimate / IQR adjusted PR Exposure")) ///
mlabels(, nodepvars) ///
nostar nonotes nonum nogap replace label nocons collabels(none) varwidth(40)
********************************************************************************
* JUNK CODE BELOW
********************************************************************************
* create sample of regression to run DiD w/ TWFE
forval v = 2/10 {
gen reg_sample`v' = 0
......@@ -36,6 +90,9 @@ forval v = 2/10 {
tab bin_pr_link if reg_sample`v' == 1 // check if we have totally unaffected & each group
}
* iqr
sum pr_link_i if base_emp > 0, d
scalar iqr = r(p75)-r(p25)
// Graphs
......@@ -61,8 +118,8 @@ forval i = 2/10 {
summ pr_link_i if pr_link_i > 0, d
estadd local avg_pr_link = string(r(mean), "%8.3fc")
estadd local beta_pr_scaled = string( _b[_IyeaXpr__2012] / r(mean), "%8.3fc")
estadd local iqr_adj_pr_link = string(r(mean)/(r(p75)-r(p25)), "%8.3fc")
estadd local beta_pr_scaled_iqr = string( _b[_IyeaXpr__2012] / (r(mean)/(r(p75)-r(p25))), "%8.3fc")
estadd scalar iqr_adj_pr_link = string(r(mean)/iqr, "%8.3fc")
estadd local beta_pr_scaled_iqr = string( _b[_IyeaXpr__2012] / iqr_adj_pr_link, "%8.3fc")
// est save ster/emp_reg_`i', replace
restore
}
......
......@@ -14,27 +14,106 @@ cd "$output/Work2024"
use "$data/Replication Data/figure6_data_A.dta", clear
summ pr_link_i if base_emp > 0, d
global iqr = r(p75)-r(p25) // iqr = 1 because it is already standardized in figure6_clean_pr_link_raw.do
di $iqr
* Create Decile bins of PR Exposure
xtile bin_pr_link = pr_link_i, nq(10)
* create bin1, bin2, ..., bin10 where bin1 is totally unaffected group
* Check if bin1's PR exposure = 0
tab bin_pr_link, summ(pr_link_i) // 40% of sample has PR exposure = 0
tab bin_pr_link, summ(pr_link_i) // 25% of sample has PR exposure = 0
* create sample of regression to run DiD w/ TWFE
forval v = 3/10 {
gen reg_sample`v' = 0
replace reg_sample`v' = 1 if bin_pr_link == `v' | bin_pr_link == 1
tab bin_pr_link if reg_sample`v' == 1 // check if we have totally unaffected & each group
}
// * create sample of regression to run DiD w/ TWFE
// forval v = 3/10 {
// gen reg_sample`v' = 0
// replace reg_sample`v' = 1 if bin_pr_link == `v' | bin_pr_link == 1
// tab bin_pr_link if reg_sample`v' == 1 // check if we have totally unaffected & each group
// }
// Graphs
// Regressions
keep if year == 1990 | year == 1995 | year == 2012
xi i.year|pr_link_i , noomit
drop _IyeaXp*1995
xi i.year*i.bin_pr_link, noomit
drop _IyeaXbin_*_1
drop _IyeaXbin_1995_*
local loopvalues = "3/10"
forval i = `loopvalues' {
label var _IyeaXbin_2012_`i' "Bin `i'"
}
forval i = `loopvalues' {
eststo bin_`i': reghdfe emp_growth _IyeaX* [aw=wgt] if bin_pr_link == 1 | bin_pr_link == `i', a(i.pid i.year#i.industr ) cl(fips_state indust ) nocons
lincom _IyeaXbin_2012_`i'
estadd local beta_pr = string(r(estimate), "%8.3fc")
estadd local se_pr = "(" + string(r(se), "%8.3fc") + ")"
estadd local p_pr = "[" + string(r(p), "%8.3fc") + "]"
estadd local ci_pr = "[" + string(r(lb), "%8.3fc") + "," + string(r(ub), "%8.3fc") + "]"
estadd local lb_pr = string(r(lb), "%8.3fc")
estadd local ub_pr = string(r(ub), "%8.3fc")
summ pr_link_i if bin_pr_link == `i', d
estadd local avg_pr_link = string(r(mean), "%8.3fc")
estadd local beta_pr_scaled = string( _b[_IyeaXbin_2012_`i'] / r(mean), "%8.3fc")
estadd local iqr_adj_pr_link = string(r(mean)/$iqr, "%8.3fc")
estadd local beta_pr_scaled_iqr = string( _b[_IyeaXbin_2012_`i'] / (r(mean)/$iqr ), "%8.3fc")
}
esttab bin_* using sun_shapiro_pr_bin_longdiff.tex, drop(*) stats(beta_pr se_pr p_pr ci_pr avg_pr_link iqr_adj_pr_link beta_pr_scaled beta_pr_scaled_iqr N, ///
labels("Long Diff Estimate" "s.e." "p-val" "95\% CI" ///
"Mean PR Exposure" "Mean PR Exposure (IQR adjusted)" "Estimate / Mean PR Exposure" "Estimate / IQR adjusted PR Exposure")) ///
mlabels(, nodepvars) ///
nostar nonotes nonum nogap replace label nocons collabels(none) varwidth(40)
********************************************************************************
* All-in-one regression [START]
********************************************************************************
eststo emp_1: reghdfe emp_growth _IyeaX* [aw=wgt], a(i.pid i.year#i.industr ) cl(fips_state indust ) nocons
forval i = `loopvalues' {
summ pr_link_i if pr_link_i > 0 & _Ibin_pr_li_`i'==1
estadd local avg_pr_exp_`i' = string(r(mean), "%8.3fc")
estadd local beta_pr_scaled_`i' = string( _b[_IyeaXbin_2012_`i'] / r(mean), "%8.3fc")
estadd local beta_pr_scaled_iqr_`i' = string( _b[_IyeaXbin_2012_`i'] / $iqr, "%8.3fc")
}
// bys reg_sample*: summ pr_link_i if pr_link_i > 0 & reg_sample`i', d
// estadd summ, iqr
//eststo emp_1: reghdfe emp_growth _IyeaX* reg_sample* [aw=wgt], a(i.pid ///
// i.year#i.industr#reg_sample4 i.year#i.industr#reg_sample5 i.year#i.industr#reg_sample6 ///
// i.year#i.industr#reg_sample7 i.year#i.industr#reg_sample8 i.year#i.industr#reg_sample9 ///
// i.year#i.industr#reg_sample10) cl(fips_state indust ) nocons
esttab emp_1, drop(*) stats(avg_pr_exp_3 beta_pr_scaled_3 beta_pr_scaled_iqr_3 ///
avg_pr_exp_4 beta_pr_scaled_4 beta_pr_scaled_iqr_4 )
esttab emp_1, keep(_IyeaXbin_2012_*) nostar noobs ///
cells(b(fmt(3)) se(fmt(3) par) p(fmt(3) par([ ]))) /// // ci(fmt(3) par([ , ])))
mlabel("2012 Estimate") label replace
esttab emp_1, keep(_IyeaXbin_2012_4) stats() nostar noobs ///
cells(b(fmt(3)) se(fmt(3) par) p(fmt(3) par([ ])) ci(fmt(3) par([ , ]))) ///
mlabel("2012 Estimate") append
********************************************************************************
* All-in-one regression [END]
********************************************************************************
forval i = 3/10 {
preserve
// local i = 3
......
......@@ -25,7 +25,8 @@ foreach var in pre post {
}
summ pr_link_i if base_emp > 0, d
scalar iqr = r(p75)-r(p25)
* Create Decile bins of PR Exposure
xtile bin_pr_link = pr_link_i, nq(10)
......@@ -60,8 +61,8 @@ forval i = 3/10 {
summ pr_link_i if pr_link_i > 0, d
estadd local avg_pr_link = string(r(mean), "%8.3fc")
estadd local beta_pr_scaled = string( _b[PR_post] / r(mean), "%8.3fc")
estadd local iqr_adj_pr_link = string(r(mean)/(r(p75)-r(p25)), "%8.3fc")
estadd local beta_pr_scaled_iqr = string( _b[PR_post] / (r(mean)/(r(p75)-r(p25))), "%8.3fc")
estadd local iqr_adj_pr_link = string(r(mean)/iqr, "%8.3fc")
estadd local beta_pr_scaled_iqr = string( _b[PR_post] / r(mean)/iqr, "%8.3fc")
// est save ster/emp_reg_long_`i', replace
restore
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment