Hi everyone,
I really have a quick question about the command -ivregress 2sls-. I am bit confused about the right way of using it. Are those two loops identical, or not?
I put in bold green the main changes between loops.
Thank you very much for your help.
Edit: I noticed that results could be different. If I am not mistaken, the first loop tries to do something like:
But I do not understand why. Thanks.
Best,
Michael
I really have a quick question about the command -ivregress 2sls-. I am bit confused about the right way of using it. Are those two loops identical, or not?
Code:
eststo clear
foreach var_pop in d_log_pop d_pop {
foreach tech in wind solar {
foreach region in ccaa nat {
foreach fe in com_id prov_code {
local ss_var = "ss_`tech'_`region'"
local d_cap = "d_power_`tech'"
local fe_short = cond("`fe'" == "com_id", "cid", "pid")
local tag = "`var_pop'_`tech'_`region'_`fe_short'"
* Special-case installation capacity
if "`region'" == "nat" {
local cap_var = "new_inst_cap_`tech'_pen"
}
else if "`region'" == "ccaa" {
local cap_var = "new_inst_cap_`tech'_ccaa"
}
* Potential variable by tech
if "`tech'" == "solar" {
local potential_var_std = "com_pv_potential_std"
}
else if "`tech'" == "wind" {
local potential_var_std = "com_wind_power_dens_std"
}
* Run IV via ivreghdfe, absorbing FE + year
ivregress 2sls `var_pop' (`d_cap' = `ss_var') `cap_var' `potential_var_std' i.`fe' i.year, robust
eststo iv_`tag'
* Tag stored result with checkmarks for Year FE and respective FE
estadd local yearfe "\ding{51}"
estadd local comarcafe = cond("`fe'" == "com_id", "\ding{51}", "")
estadd local provincefe = cond("`fe'" == "prov_code", "\ding{51}", "")
}
}
}
}
Code:
eststo clear
foreach var_pop in d_log_pop d_pop {
foreach tech in wind solar {
foreach region in ccaa nat {
foreach fe in com_id prov_code {
local ss_var = "ss_`tech'_`region'"
local d_cap = "d_power_`tech'"
local fe_short = cond("`fe'" == "com_id", "cid", "pid")
local tag = "`var_pop'_`tech'_`region'_`fe_short'"
* Special-case installation capacity
if "`region'" == "nat" {
local cap_var = "new_inst_cap_`tech'_pen"
}
else if "`region'" == "ccaa" {
local cap_var = "new_inst_cap_`tech'_ccaa"
}
* Potential variable by tech
if "`tech'" == "solar" {
local potential_var_std = "com_pv_potential_std"
}
else if "`tech'" == "wind" {
local potential_var_std = "com_wind_power_dens_std"
}
* Run IV via ivreghdfe, absorbing FE + year
ivregress 2sls `var_pop' (`d_cap' = `ss_var' `cap_var' `potential_var_std') i.`fe' i.year, robust
eststo iv_`tag'
* Tag stored result with checkmarks for Year FE and respective FE
estadd local yearfe "\ding{51}"
estadd local comarcafe = cond("`fe'" == "com_id", "\ding{51}", "")
estadd local provincefe = cond("`fe'" == "prov_code", "\ding{51}", "")
}
}
}
}
I put in bold green the main changes between loops.
Thank you very much for your help.
Edit: I noticed that results could be different. If I am not mistaken, the first loop tries to do something like:
Code:
regress `d_cap' `ss_var' `cap_var' `potential_var_std' i.`fe' i.year, r predict double d_cap_hat, xb
Code:
regress `var_pop' d_cap_hat `cap_var' `potential_var_std' i.`fe' i.year, robust
Best,
Michael
Comment