Skip to content

Commit

Permalink
initial commit of SIR2025
Browse files Browse the repository at this point in the history
  • Loading branch information
mle2718 committed Aug 13, 2024
1 parent 275ae36 commit dcc69b4
Show file tree
Hide file tree
Showing 20 changed files with 2,026 additions and 0 deletions.
12 changes: 12 additions & 0 deletions SIR2025-2027/results/Yearly_regression2023.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
(1)
VARIABLES lnpricemt_realGDP

lnlandings -0.330***
(0.0442)
Constant 7.399***
(0.173)

Observations 20
R-squared 0.777
Standard errors in parentheses
*** p<0.01, ** p<0.05, * p<0.1
39 changes: 39 additions & 0 deletions SIR2025-2027/stata_code/analysis/01-analysis_wrapper.do
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
pause off
global vintage_string 2021_09_01

/* annual prices and revenue */
do "${analysis_code}/annual_revenue_grapher.do"


/* utilization */

do "${analysis_code}/utilization_grapher.do"


/* prices */

do "${analysis_code}/price_grapher.do"

/* predict prices 2019 and average
dont think this is needed*/

do "${analysis_code}/prices2019.do"


do "${analysis_code}/average_prices.do"

graph close _all

do "${analysis_code}/rebuild_analysis/A0_annual_price_regression.do"

do "${analysis_code}/rebuild_analysis/A1_rebuild_analysis.do"
do "${analysis_code}/rebuild_analysis/A3_rebuild_analysis_mean_ABCs.do"


/*needs to go after the rebuild_mean */
do "${analysis_code}/rebuild_analysis/A2_rebuild_annual_revenues.do"
do "${analysis_code}/rebuild_analysis/A4_rebuild_analysis_stacked.do"
do "${analysis_code}/rebuild_analysis/A5_graph_predicted_rev.do"


181 changes: 181 additions & 0 deletions SIR2025-2027/stata_code/analysis/annual_revenue_grapher.do
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
#delimit ;
global lbs_to_mt 2204.62;
set scheme s2mono;
local data_in "${data_intermediate}/monthly_util_herring.dta";
use `data_in', replace;
collapse (sum) landings_mt value, by(year );
keep if year<=2023;
tsset year;

/* pull in deflators */

merge m:1 year using ${data_external}\deflatorsY.dta, keep(1 3);
assert _merge==3;
drop _merge;


gen value_realGDP=value/fGDPDEF_2023;

gen pricemt=value/landings_mt;
gen pricemt_realGDP=value_realGDP/landings_mt;


replace landings_mt=landings_mt/1000;
label var landings_mt "landings 000s of mt";


local graph_subset year<=2023;

replace value=value/1000000;
replace value_realGDP=value_realGDP/1000000;

label var value_realGDP "Average Annual Value (2023M)";

label var pricemt "Average Annual Price per mt (nominal)";
label var pricemt_realGDP "Average Annual Price per mt (2023)";
label var price "Average Annual Price per pound(nominal)";
label var price_real "Average Annual Price per pound (2023)";


local graphopts tmtick(##6);
local graph_subset year<=2024 & year>=2009;


tsline pricemt pricemt_realGDP if `graph_subset', `graphopts' cmissing(n) tlabel(2009(2)2024) tmtick(##2) ymtick(##4) ytitle("Annual Average Price per metric ton") legend(order(1 "Nominal" 2 "Real 2023 dollars")) ;
graph export ${my_images}/herring_prices_real.tif, replace as(tif);


label var value "Nominal Value $M";
label var value_realGDP "Real Value 2023$M";

tsline value value_realGDP if `graph_subset', `graphopts' cmissing(n) tlabel(2009(2)2024) tmtick(##2) ytitle("Millions of USD") legend(order(1 "Nominal value" 2 "Real Value 2023 dollars")) ;
graph export ${my_images}/herring_value_real.tif, replace as(tif);


sort year;

/* get the equation for the linear fit */
reg pricemt_realGDP landings ;
// find the dependt variable
local eq `"`e(depvar)' ="';

// choose a nice display format for the constant
local eq "`eq' `: di %7.2f _b[_cons]'";

// should we add or subtract
local eq `"`eq' `=cond(_b[landings]>0, "+", "-")'"';

// we already chose the plus or minus sign
// so we need to strip a minus sign when it is there
local eq `"`eq' `:di %6.2f abs(_b[landings])' landings"';

// add the error term
local eq `"`eq' + {&epsilon}"';


tsset;
ivregress 2sls pricemt_realGDP (landings=l1.landings);

// find the dependt variable
local eq2 `"`e(depvar)' ="';

// choose a nice display format for the constant
local eq2 "`eq2' `: di %7.2f _b[_cons]'";

// should we add or subtract
local eq2 `"`eq2' `=cond(_b[landings]>0, "+", "-")'"';

// we already chose the plus or minus sign
// so we need to strip a minus sign when it is there
local eq2 `"`eq2' `:di %6.2f abs(_b[landings])' landings"';

// add the error term
local eq2 `"`eq2' + {&epsilon}"';

di "`eq2'";



local liv_cons=_b[_cons];

local liv_beta=_b[landings];



local scatter_opts ylabel(0(200)1000) ymtick(##4) xlabel(0(40)120) xmtick(##4) ytitle("Price per Metric Ton (Real 2023)") xtitle("Herring Landings ('000s of mt)") legend(off);


twoway (function y=_b[_cons] + _b[landings]*x, range(0 120)) (scatter pricemt_realGDP landings if year<=2016, mlabel(year)) (scatter pricemt_realGDP landings if year>=2017, mlabel(year)), `scatter_opts' note("`eq2'");

graph export ${my_images}/herring_price_quantity_iv_scatter.png, replace as(png);

twoway ( lfit pricemt_realGDP landings,range(0 120)) (scatter pricemt_realGDP landings if year<=2016, mlabel(year)) (scatter pricemt_realGDP landings if year>=2017, mlabel(year)), `scatter_opts' note("`eq'");

graph export ${my_images}/herring_price_quantity_scatter.png, replace as(png);













/* plot the iv- regression fit */

gen lnpricemt_realGDP=ln(pricemt_realGDP);
gen lnlandings=ln(landings);


ivregress 2sls lnpricemt_realGDP (lnlandings=l1.lnlandings);





// find the dependt variable
local eq3 `"`e(depvar)' ="';

// choose a nice display format for the constant
local eq3 "`eq3' `: di %7.2f _b[_cons]'";

// should we add or subtract
local eq3 `"`eq3' `=cond(_b[lnlandings]>0, "+", "-")'"';

// we already chose the plus or minus sign
// so we need to strip a minus sign when it is there
local eq3 `"`eq3' `:di %6.2f abs(_b[lnlandings])' lnlandings"';

// add the error term
local eq3 `"`eq3' + {&epsilon}"';


local rmse=e(rmse);
di "`eq3'";




local scatter_opts ylabel(0(200)1000) ymtick(##4) xlabel(0(40)120) xmtick(##4) ytitle("Price per Metric Ton (Real 2023)") xtitle("Herring Landings ('000s of mt)");


twoway (function y=exp(_b[_cons] + _b[lnlandings]*ln(x) + (`rmse'^2)/2), range(5 120)) (scatter pricemt_realGDP landings if year<=2016, mlabel(year)) (scatter pricemt_realGDP landings if year>=2017, mlabel(year)), `scatter_opts' note("`eq3'") legend(off);

graph export ${my_images}/herring_price_quantity_lniv_scatter.png, replace as(png);




twoway (function y=exp(_b[_cons] + _b[lnlandings]*ln(x) + (`rmse'^2)/2), range(5 120)) (function y=`liv_cons' + `liv_beta'*x, range(5 120)) (scatter pricemt_realGDP landings if year<=2016, mlabel(year)) (scatter pricemt_realGDP landings if year>=2017, mlabel(year)), `scatter_opts' note("`eq3'" "`eq2'") legend(order(1 "log fit" 2 "linear fit"));

graph export ${my_images}/herring_price_quantity_iv_both_scatter.png, replace as(png);





*/
58 changes: 58 additions & 0 deletions SIR2025-2027/stata_code/analysis/average_prices.do
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#delimit ;
global lbs_to_mt 2204.62;

local data_in "${data_intermediate}/monthly_util_herring.dta";
use `data_in', replace;
keep if nespp3==168;
keep if year>=2017 & year<=2019;

collapse (sum) landings value, by(year nespp3);
tsset nespp3 year;
gen yearcount=1;
/* pull in deflators */

merge m:1 year using ${data_external}\deflatorsY.dta, keep(1 3);
gen value_realGDP=value/fGDPDEF_2019;

gen pricemt_realGDP=value_realGDP/landings;
list if year==2019;
collapse (sum) landings value value_realGDP yearcount, by(nespp3);


gen pricemt=value/landings;
gen pricemt_realGDP=value_realGDP/landings;

replace landings=landings/1000;
label var landings "(000 mt)";


gen price=pricemt/$lbs_to_mt;
gen price_real=pricemt_realGDP/$lbs_to_mt;

/* yearly averages */
replace value=value/1000000;
replace value=value/yearcount;
label var value "Average Annual Value (M) nominal";

replace value_realGDP=value_realGDP/1000000;
replace value_realGDP=value_realGDP/yearcount;

label var value_realGDP "Average Annual Value (2019M)";

label var pricemt "Average Annual Price per mt (nominal)";
label var pricemt_realGDP "Average Annual Price per mt (2019)";
label var price "Average Annual Price per pound(nominal)";
label var price_real "Average Annual Price per pound (2019)";

/* predicted prices are
.646 L.price -1.194 Quantity +217.8
lnp=.666 L.lnp - .395 lnQ + 6.423*/


global quant 16.131;
global lnq ln($quant*1000);
gen predicted_price=.646*pricemt_real +217.8 - 1.194*$quant;
gen lnp=ln(pricemt_real);

gen lnpp=.666*lnp+ 6.423 - .395*$lnq;
gen p2=exp(lnpp);
96 changes: 96 additions & 0 deletions SIR2025-2027/stata_code/analysis/price_grapher.do
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#delimit ;
global lbs_to_mt 2204.62;



local data_in "${data_intermediate}/monthly_util_herring.dta";
use `data_in', replace;
keep if year<=2023;

collapse (sum) landings_mt value (first) frac_bait, by(year month mymonth);
/* pull in deflators */

merge m:1 year using ${data_external}\deflatorsY.dta, keep(1 3);
assert _merge==3;
drop _merge;


gen value_realGDP=value/fGDPDEF_2023;


tsset mymonth;
bysort year: egen vs=total(value);
bysort year: egen ls=total(landings_mt);

bysort year: egen vsR=total(value_realGDP);




gen pricemt=value/landings_mt;
gen pricemt_yr=vs/ls;

gen pricemt2023=value_realGDP/landings_mt;
gen pricemt_yr2023=vsR/ls;




label var ls "annual landings";
label var pricemt "monthly average nominal price";
label var pricemt_yr "annual average nominal price";

label var pricemt2023 "monthly average Real (2023) price";
label var pricemt_yr2023 "annual average Real (2023) price";


set scheme s2mono;
*drop if pricemt>=500;
drop if year>=2024;
tsfill;



local graph_subset mymonth<=monthly("2023m12","YM") & mymonth>=monthly("2016m1", "YM");
local graph_subset mymonth<=monthly("2023m12","YM") & mymonth>=monthly("2016m1", "YM");
local graphopts tmtick(##6);


replace landings=landings/1000;
label var landings "(000 mt)";

gen price=pricemt/$lbs_to_mt;
gen price_yr=pricemt_yr/$lbs_to_mt;

twoway (tsline pricemt if `graph_subset', `graphopts' cmissing(n)) (tsline pricemt_yr if `graph_subset', `graphopts'), ytitle("Price per metric ton") tlabel(, format(%tmCCYY)) name(herringprice, replace) legend(off) ttitle("");
twoway bar landings mymonth if `graph_subset', xmtick(##5) xlabel(, format(%tmCCYY)) xtitle("") name(herringlandings, replace) fysize(25);

graph combine herringprice herringlandings, cols(1) imargin(b=0 t=0);

graph export ${my_images}/herring_price_quantity.tif, replace as(tif);
graph export ${my_images}/herring_price_quantity.png, replace as(png);






twoway (tsline pricemt2023 if `graph_subset', `graphopts' cmissing(n)) (tsline pricemt_yr2023 if `graph_subset', `graphopts'), ytitle("Real (2023) Price per metric ton") tlabel(, format(%tmCCYY)) name(herringpriceR, replace) legend(off) ttitle("");

graph combine herringpriceR herringlandings, cols(1) imargin(b=0 t=0);

graph export ${my_images}/herring_price_quantity.tif, replace as(tif);
graph export ${my_images}/herring_price_quantity.png, replace as(png);



tsset year month;



xtline frac_bait;

graph export ${my_images}/herring_fraction_bait.png, replace as(png);



Loading

0 comments on commit dcc69b4

Please sign in to comment.