Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Epic chart #18

Open
wants to merge 3 commits into
base: interaction
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions 0_make_dataset/2_construct_regression_ready_data.do
Original file line number Diff line number Diff line change
Expand Up @@ -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)

*********************************************************
Expand Down
8 changes: 8 additions & 0 deletions 0_make_dataset/merged/2_construct_FD_interacted_variables.do
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
37 changes: 37 additions & 0 deletions 1_analysis/decile_regression/stacked.do
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
Expand All @@ -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 = ""
Expand All @@ -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


144 changes: 144 additions & 0 deletions 4_misc/outreach/electricity_decile_overlay_EPIC_top10_2021.do
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Purpose: Plot the energy overlayed version of 1A

*/

/// the 3 group version




clear all
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -172,3 +308,11 @@ foreach fuel in "electricity" {

}


*/






Binary file modified data/GMFD_TINV_clim_regsort.dta
Binary file not shown.
Binary file modified data/IEA_Merged_long_GMFD.dta
Binary file not shown.
Binary file modified data/break_data_TINV_clim.dta
Binary file not shown.
Binary file modified data/climate_data.dta
Binary file not shown.
Binary file not shown.
Binary file modified sters/FD_FGLS_income_decile_TINV_clim.ster
Binary file not shown.
Binary file not shown.
Binary file modified sters/FD_income_decile_TINV_clim.ster
Binary file not shown.
Binary file added sters/FD_income_decile_epic_TINV_clim.ster
Binary file not shown.