diff --git a/0_make_dataset/2_construct_regression_ready_data.do b/0_make_dataset/2_construct_regression_ready_data.do index 2ece8e97e..4255f5812 100644 --- a/0_make_dataset/2_construct_regression_ready_data.do +++ b/0_make_dataset/2_construct_regression_ready_data.do @@ -167,6 +167,19 @@ drop largegpid_electricity largegpid_other_energy //Generate dummy variable by income decile and group tab gpid, gen(ind) + +// Ashwin: you can check how the dummies for the groups are generated here +// Group the data into 3 groups: +// group1: decile 1-6 +// group2: decile 7-8 +// group3: decile 9-10 +gen indepic1 = 0 +gen indepic2 = 0 +gen indepic3 = 0 +replace indepic2 = 1 if (ind7 == 1 | ind8 == 1) +replace indepic3 = 1 if (ind9 == 1 | ind10 == 1) +replace indepic1 = 1 if (indepic2 == 0 & indepic3 == 0) + tab largegpid, gen(largeind) ********************************************************* diff --git a/0_make_dataset/merged/2_construct_FD_interacted_variables.do b/0_make_dataset/merged/2_construct_FD_interacted_variables.do index 0d492b231..577175798 100644 --- a/0_make_dataset/merged/2_construct_FD_interacted_variables.do +++ b/0_make_dataset/merged/2_construct_FD_interacted_variables.do @@ -88,6 +88,14 @@ forval lg = 1/10 { } } +** Ashwin: generating the variables here. it parallels the lines above +** do the same for the indepic version +forval lg = 1/3 { + forval i=1/4 { + gen double FD_Iepic`lg'temp`i'_GMFD = ( temp`i'_GMFD * indepic`lg' ) - ( L1.temp`i'_GMFD * L1.indepic`lg' ) + } +} + ** First difference temp x year x income spline forval lg=1/2 { diff --git a/1_analysis/decile_regression/stacked.do b/1_analysis/decile_regression/stacked.do index d0032dc21..cca101b60 100644 --- a/1_analysis/decile_regression/stacked.do +++ b/1_analysis/decile_regression/stacked.do @@ -32,6 +32,13 @@ forval pg=1/2 { } } +** Ashwin: the epic plot version +forval pg=1/2 { + forval lg=1/3 { + qui gen DumIncGepic`lg'F1P`pg' = (indepic`lg'- L1.indepic`lg') * indf1 * indp`pg' + } +} + * income decile x temp local income_decile_temp_r = "" @@ -44,6 +51,17 @@ forval pg = 1/2 { } } +** Ashwin: the epic plot version +local income_decile_epic_temp_r = "" + +forval pg = 1/2 { + forval lg = 1/3 { + forval k = 1/2 { + local income_decile_epic_temp_r = "`income_decile_epic_temp_r' c.indp`pg'#c.indf1#c.FD_Iepic`lg'temp`k'_GMFD" + } + } +} + * precip local precip_r = "" @@ -67,3 +85,22 @@ qui gen weight = 1/omega reghdfe FD_load_pc `income_decile_temp_r' `precip_r' DumInc* [pw=weight], absorb(i.flow_i#i.product_i#i.year#i.subregionid) cluster(region_i) estimates save "$root/sters/FD_FGLS_income_decile_`model'", replace + + +drop resid weight omega + +** Ashwin: epic plot version +* run first stage regression +reghdfe FD_load_pc `income_decile_epic_temp_r' `precip_r' DumIncGepic*, absorb(i.flow_i#i.product_i#i.year#i.subregionid) cluster(region_i) residuals(resid) +estimates save "$root/sters/FD_income_decile_epic_`model'", replace + +* calculating weigts for FGLS +drop if resid==. +bysort region_i: egen omega = var(resid) +qui gen weight = 1/omega + +* run second stage FGLS regression +reghdfe FD_load_pc `income_decile_epic_temp_r' `precip_r' DumIncGepic* [pw=weight], absorb(i.flow_i#i.product_i#i.year#i.subregionid) cluster(region_i) +estimates save "$root/sters/FD_FGLS_income_decile_epic_`model'", replace + + diff --git a/4_misc/outreach/electricity_decile_overlay_EPIC_top10_2021.do b/4_misc/outreach/electricity_decile_overlay_EPIC_top10_2021.do index 88d360c45..077d82a86 100644 --- a/4_misc/outreach/electricity_decile_overlay_EPIC_top10_2021.do +++ b/4_misc/outreach/electricity_decile_overlay_EPIC_top10_2021.do @@ -4,6 +4,9 @@ Purpose: Plot the energy overlayed version of 1A */ +/// the 3 group version + + clear all @@ -39,6 +42,139 @@ use "$root/data/GMFD_`model'_regsort.dta", `clear' +foreach fuel in "electricity" { + set scheme s1color + + ****** Set Model Specification Locals ****************************************** + + local model = "$model" + + ****** Set Plotting Toggles **************************************************** + + // plotting color and color name for title + + * electricity + local electricity_col "dknavy" + local electricity_colTT "Blue" + + * other energy + local other_energy_col "dkorange" + local other_energy_colTT "Orange" + + ******************************************************************************** + *Step 1: Load Data and Clean for Plotting + ******************************************************************************** + + use "$root/data/GMFD_`model'_regsort.dta", clear + + //Set up locals for plotting + local obs = 35 + abs(-5) + 1 + + //clean data for plotting + drop if _n > 0 + set obs `obs' + + replace temp1_GMFD = _n - 6 + + foreach k of num 1/2 { + rename temp`k'_GMFD temp`k' + replace temp`k' = temp1 ^ `k' + } + + ******************************************************************************** + * Step 2: Plot Plot Plot + ******************************************************************************** + local graphic "" + local graphic_noSE "tw " + + + + // loop over income deciles + forval lg=1/3 { + + // set up plotting locals + local SE "" + local noSE "" + local colorGuide "" + + foreach var in `fuel' { + + // assign product index + if "`var'" == "electricity" { + local pg = 1 + } + else if "`var'" == "other_energy" { + local pg=2 + } + + * construct local variable that holds dose response + + local line = "" + local add = "" + + forval k = 1/2 { + + local line = "`line'`add'_b[c.indp`pg'#c.indf1#c.FD_Iepic`lg'temp`k'] * (temp`k' - 20^`k')" + local add " + " + + } + * use ster to estimate dose response + + + * Ashwin: you probably only need to look at these few lines for generating the predicted y + estimates use "$root/sters/FD_FGLS_income_decile_epic_`model'" + predictnl yhat`lg'_`var' = `line', se(se`lg'_`var') ci(lower`lg'_`var' upper`lg'_`var') + label variable yhat`lg'_`var' "group `lg'" + } + + ** Ashwin: and here for a simple plot + colorpalette blue, intensity(0.4(.3)1) + graph twoway line yhat1_electricity yhat2_electricity yhat3_electricity temp1, /// + lcolor(`r(p1)' `r(p2)' `r(p3)' ) /// + yline(0, lwidth(vthin)) xlabel(-5(10)35, labsize(vsmall)) /// + ylabel(, labsize(vsmall) nogrid) + + graph export "$root/figures/fig_1A_product_overlay_for_EPIC_top10_2021_3group_income_decile_`model'.pdf", replace +} + + + + +/* + +clear all +set more off +macro drop _all + +global REPO "/home/liruixue/repos/" +/////////////// SET UP USER SPECIFIC PATHS ////////////////////////////////////////////////////// + +* path to energy-code-release repo: + +global root "${REPO}/energy-code-release-2020" + +///////////////////////////////////////////////////////////////////////////////////////////////// + +******Set Script Toggles******************************************************** + +// What model do you want? TINV_clim or TINV_clim_EX +global model "TINV_clim" + + +local model = "$model" + +******************************************************************************** +*Step 1: Load Data +******************************************************************************** + +use "$root/data/GMFD_`model'_regsort.dta", `clear' + +******************************************************************************** +* Step 2: Prepare Regressors and Run Regression +******************************************************************************** + + + foreach fuel in "electricity" { set scheme s1color @@ -172,3 +308,11 @@ foreach fuel in "electricity" { } + + */ + + + + + + diff --git a/data/GMFD_TINV_clim_regsort.dta b/data/GMFD_TINV_clim_regsort.dta index 5ffec6a7b..6544c8caf 100644 Binary files a/data/GMFD_TINV_clim_regsort.dta and b/data/GMFD_TINV_clim_regsort.dta differ diff --git a/data/IEA_Merged_long_GMFD.dta b/data/IEA_Merged_long_GMFD.dta index db5183f9b..74ea00cfa 100644 Binary files a/data/IEA_Merged_long_GMFD.dta and b/data/IEA_Merged_long_GMFD.dta differ diff --git a/data/break_data_TINV_clim.dta b/data/break_data_TINV_clim.dta index 0aa94daa8..d0e0925a2 100644 Binary files a/data/break_data_TINV_clim.dta and b/data/break_data_TINV_clim.dta differ diff --git a/data/climate_data.dta b/data/climate_data.dta index 1541aec6a..acb8389b5 100644 Binary files a/data/climate_data.dta and b/data/climate_data.dta differ diff --git a/figures/fig_1A_product_overlay_for_EPIC_top10_2021_3group_income_decile_TINV_clim.pdf b/figures/fig_1A_product_overlay_for_EPIC_top10_2021_3group_income_decile_TINV_clim.pdf new file mode 100644 index 000000000..0a005b261 Binary files /dev/null and b/figures/fig_1A_product_overlay_for_EPIC_top10_2021_3group_income_decile_TINV_clim.pdf differ diff --git a/sters/FD_FGLS_income_decile_TINV_clim.ster b/sters/FD_FGLS_income_decile_TINV_clim.ster index b56de8e7f..9d2402073 100644 Binary files a/sters/FD_FGLS_income_decile_TINV_clim.ster and b/sters/FD_FGLS_income_decile_TINV_clim.ster differ diff --git a/sters/FD_FGLS_income_decile_epic_TINV_clim.ster b/sters/FD_FGLS_income_decile_epic_TINV_clim.ster new file mode 100644 index 000000000..18a2c6f6b Binary files /dev/null and b/sters/FD_FGLS_income_decile_epic_TINV_clim.ster differ diff --git a/sters/FD_income_decile_TINV_clim.ster b/sters/FD_income_decile_TINV_clim.ster index 7221b95de..c9327ee66 100644 Binary files a/sters/FD_income_decile_TINV_clim.ster and b/sters/FD_income_decile_TINV_clim.ster differ diff --git a/sters/FD_income_decile_epic_TINV_clim.ster b/sters/FD_income_decile_epic_TINV_clim.ster new file mode 100644 index 000000000..a671b796e Binary files /dev/null and b/sters/FD_income_decile_epic_TINV_clim.ster differ