*********************************************************************************

*********************************************************************************

*Commercial Fishing Benefits Model_05.02.14;

*Author: Matthew LaPenta, Kathryn Sayles, and Ryan Stapler, Abt Associates Inc.;

*Created: 1/31/2008;

*Updated: 5/02/2014;

*Purpose: This is a SAS program that calculates commercial fishing benefits

under the final rule and other options considered. Benefits arfe reported in

1,000s of dollars.

*********************************************************************************

*********************************************************************************

;

*SPECIFY INPUT AND OUTPUT

FILES**************************************************;

*file locations;

%let d=s; *(C, H, or S drive);

%let facloc=&d.:\Projects\Tyche\WA 4-05 (316b)\Benefits

Estimation\Final_05.02.14\;

%let mainloc=&facloc.Existing_facilities\Com\;

%let inloc=&mainloc.Inputs\;

%let outloc=&mainloc.Outputs\;

libname outloc "&outloc";

*input files;

%let fac_input=Facility_Inputs_and_Weights_01.25.14.xls;

%let input=Commercial_Benefits_Inputs_05.08.13.xls;

%let input2=IE_outputs_25JAN14_adjusted_for_state_regs.xls;

*output files;

%let output=ComBenOutputs_&sysdate..xls;

%let SumTables=ComBenTablesSum_&sysdate..xls;

*SET DISCOUNTING AND COMPLIANCE

ASSUMPTIONS**************************************;

%let d0=2013; *(d0 is the base year for discounting);

%let t0=2014; *(t0 is promulgation year -i.e., 1st year with costs);

%let yrsc=51; *(yrsc is the annualization period);

%let ie_year=2017; *(all years prior to ie_year include installation of

impingement tech only. this is no longer relevant within the

code, set to

2017 to deactivate for model runs (the 1st compliance year is

2018);

%let ie_year_1=2018; *(define minimum year for installation of

entrainment tech);

*Note: consumer surplus not analyzed so these specifications are no longer used

in the analysis;

%let Elast_saltwater=-1.89;

%let Elast_shrimp=-.63;

%let Elast_crabs=-1.31;

*%let ieunits=1;

%let firsttable=8;

%macro cyr;

cydata.tmn1 as cyr_base,

cydata.tmn1 as cyr_tmn1,

cydata.tmn2 as cyr_tmn2,

cydata.tmn3 as cyr_tmn3

%mend;

*select option controls below;

%macro optionmac0(var);

if &var=1 then do;

*define abbreviated option names;

if option_name="option.tmn1" then

option="tmn1";

else if option_name="option.tmn2"

then option="tmn2";

else if option_name="option.tmn3"

then option="tmn3";

end;

if &var=2 then do;

Page 1
*select baseline option;

if option_name ="option.tmn1";

end;

%mend;

%macro optionmac00;

%step5schedule(baseline,cyr_base,base);

%step5schedule(tmn1x,cyr_tmn1,tmn1);

%step5schedule(tmn2x,cyr_tmn2,tmn2);

%step5schedule(tmn3x,cyr_tmn3,tmn3);

data Step5idata;

length option $50.0;

set s8i_baseline s8i_baseline_0 s8i_tmn1x s8i_tmn1x_0 s8i_tmn2x

s8i_tmn2x_0 s8i_tmn3x s8i_tmn3x_0

;

run;

%mend;

%macro optionmac11;

%step6schedule(baseline,cyr_base,base);

%step6schedule(tmn1x,cyr_tmn1,tmn1);

%step6schedule(tmn2x,cyr_tmn2,tmn2);

%step6schedule(tmn3x,cyr_tmn3,tmn3);

data Step5tdata;

length option $50.0;

set s8t_baseline s8t_baseline_0 s8t_tmn1x s8t_tmn1x_0 s8t_tmn2x

s8t_tmn2x_0 s8t_tmn3x s8t_tmn3x_0

;

run;

%mend;

*select benfits schedule (st5) and IM&E data option (st4);

%macro optionmac1;

case

when st5.option="baseline" and

st4.option="baseline" then "baseline"

when st5.option="baseline_0" and

st4.option="baseline" then "baseline_0"

when st5.option="tmn1x"

and st4.option="tmn1" then "tmn1"

when st5.option="tmn1x_0" and

st4.option="tmn1" then "tmn1_0"

when st5.option="tmn2x"

and st4.option="tmn2" then "tmn2"

when st5.option="tmn2x_0" and

st4.option="tmn2" then "tmn2_0"

when st5.option="tmn3x"

and st4.option="tmn3" then "tmn3"

when st5.option="tmn3x_0" and

st4.option="tmn3" then "tmn3_0"

else "delete"

end as optionname

%mend;

%macro optionmac2; *select option, IM&E variable, IM&E variable percentage

factor;

%undiscsurplus(baseline,reduction,rpercent);

%undiscsurplus(tmn1,reduction,rpercent);

%undiscsurplus(tmn2,reduction,rpercent);

%undiscsurplus(tmn3,reduction,rpercent);

%mend;

%macro optionmac2a; *select option, IM&E variable, IM&E variable percentage

factor;

if optionname in("baseline","tmn1","tmn2","tmn3");

if optionname="baseline" then sortx=1;

else if optionname="tmn1" then sortx=2;

Page 2
else if optionname="tmn2" then sortx=3;

else if optionname="tmn3" then sortx=4;

%mend;

%macro optionmac3; *perform macro for each option for which a regional table is

presented;

%summarybyoption(baseline_0,tmn1_0,tmn1_0);

%summarybyoption(baseline_0,tmn2_0,tmn2_0);

%summarybyoption(baseline_0,tmn3_0,tmn3_0);

%mend;

%macro optionmac4;

if option="baseline" then do; sort1=1;

option="baseline"; end;

else if option="tmn1" then do; sort1=2;

option="tmn1"; end;

else if option="tmn2" then do; sort1=3; option="tmn2";

end;

else if option="tmn3" then do; sort1=4;

option="tmn3"; end;

%mend optionmac4;

%let speciesoptions=baseline^tmn1^tmn2^tmn3;

%let titleoptions=baseline^tmn1^tmn2^tmn3;

%let regionoptions=tmn1_0^tmn2_0^tmn3_0;

%let speciesnum=4;*(all options incl. baseline) select number of species-tables

per region (number in speciesoptions list above);

%let rnum=3;*(all options minus baseline) select number of region-summary-tables

per region (number in regionoptions list above);

%let nby=7;*(sum of two above) select number of tables for each region , sum of

speciesnum and rnum;

%let natoptions=baseline_0^tmn1_0^tmn2_0^tmn3_0;*list options presented in

national tables;

%let natnum=4;*number of national tables in natoptions list;

*list regional table titles;

%let TableTitles=

baseline^tmn1^tmn2^tmn3;

*list national table titles;

%let nattitles=

Baseline Elimination (w/o Consumer Surplus)

tmn1^tmn2^tmn3;

*DEFINE MACROS FOR IMPORTING AND EXPORTING

DATA**********************************;

*macro to import from excel;

%macro import(infile,insheet,out);

PROC IMPORT OUT= WORK.&out

DATAFILE= "&infile"

DBMS=EXCEL REPLACE;

SHEET="&insheet.$";

GETNAMES=YES;

MIXED=NO;

SCANTEXT=YES;

USEDATE=YES;

SCANTIME=YES;

RUN;

%mend;

*macro to export to excel;

%macro export(datafile,outfile,sheet);

PROC EXPORT DATA= &datafile

OUTFILE= &outfile

DBMS=EXCEL replace;

SHEET=&sheet;

RUN;

%mend;

* import landings data;

Page 3
%import(&inloc.&input,Recent_Landings,p1);

data p2 dropped;

set p1;

if year~=.;

*define the north atlantic region;

if

state="Massachusetts" |

state="Connecticut" |

state="Rhode Island" |

state="New Hampshire" |

state="Maine"

then Region="NA";

*define the mid-atlantic region;

else if

state="New York" |

state="New Jersey" |

state="Maryland" |

state="Delaware" |

state="Virginia"

then Region="MA";

*define the california region;

else if state="California"

then Region="CA";

*define the gulf of mexico region;

else if state="Florida West Coast" |

state="Alabama" |

state="Mississippi" |

state="Louisiana" |

state="Texas"

then region="GM";

*define the great lakes region;

else if state="Michigan" |

state="Ohio" |

state="Minnesota" |

state="Wisconsin"

then region="GL";

*define the south atlantic region;

else if state="North Carolina" |

state="South Carolina" |

state="Georgia" |

state="Florida East Coast"

then region="SA";

else output dropped; *the data set, dropped, contains data from

states not considered;

if region~=" " then output p2; *here we output the landings and

price data that we will use;

run;

*import cpi data to adjust prices to 2011$;

%import(&facloc.&fac_input,CPI,cpi);

*join cpi data and landings data and adjust;

proc sql;

create table p3 as select

p2.region,

p2.state,

p2.year,

p2.species as AFSSpecies, /*species as defined in landings data*/

p2.pounds,

p2.dollars,

cpi.cpi,

p2.dollars*cpi.cpi as adjusteddollars

from p2 as p2 left join cpi on

p2.year=cpi.year;

quit;

*import mapping of various species definitions;

%import(&inloc.&input,SpeciesValueMap,smap);

Data smap; set smap; if iespecies="" then delete; RUN;

Page 4
*join species map with landings data;

proc sql;

create table p4 as select

s.*,

p.*

from smap as s left join p3 as p

on s.valspecies=p.AFSSpecies;

quit;

*drop species that are double counted;

proc sort data=p4 out=p5; by year region state AFSSpecies; run;

data p6 temp;

set p5;

by year region state AFSSpecies;

if first.AFSSpecies then output p6; *keep one of each species

type;

else output temp; *output double-couted species;

run;

*generate dataset of pounds of harvest, business as usual (BAU) gross revenues,

and BAU prices, by region and species;

proc sql;

create table p7 as select

region label="Region Abbreviation",

cfspecies label="Commercial Fishing Species Market Group",

sum(pounds)/5 as pounds format=comma30.0 label="average annual

lbs",

sum(adjusteddollars)/5 as dollars2011 format=dollar30.0

label="average annual 2011$",

sum(adjusteddollars)/sum(pounds) as price2011 format=dollar30.2

label="average dockside price 2011$"

from p6 where afsspecies~=" " group by region,cfspecies;

quit;

*generate dataset of pounds of harvest, BAU gross revenues,

and BAU prices, by region for Species without Specific data: cfspecies =

"blank";

proc sql;

create table p8 as select

region label="Region Abbreviation",

"blank" as cfspecies format=$50. label="Commercial Fishing

Species Market Group",

sum(pounds)/5 as pounds format=comma30.0 label="average annual

lbs",

sum(adjusteddollars)/5 as dollars2011 format=dollar30.0

label="average annual 2011$",

sum(adjusteddollars)/sum(pounds) as price2011 format=dollar30.2

label="average dockside price 2011$"

from p6 where afsspecies~=" " group by region;

quit;

*generate final dataset of pounds of harvest, BAU gross revenues,

and BAU prices, by region and species;

data step1data;

set p7 p8;

run;

*import and manipulate historic landings data;

%import(&inloc.&input,Historic_Landings,hl);

*drop subtotal rows, define region variable;

data hl_2 hl_dropped;

set hl;

if year~=.;

*define the north atlantic region;

if

state="Massachusetts" |

state="Connecticut" |

state="Rhode Island" |

state="New Hampshire" |

state="Maine"

Page 5
then Region="NA";

*define the mid-atlantic region;

else if

state="New York" |

state="New Jersey" |

state="Maryland" |

state="Delaware" |

state="Virginia"

then Region="MA";

*define the california region;

else if state="California"

then Region="CA";

*define the gulf of mexico region;

else if state="Florida West Coast" |

state="Alabama" |

state="Mississippi" |

state="Louisiana" |

state="Texas"

then region="GM";

*define the great lakes region;

else if state="Michigan" |

state="Ohio" |

state="Minnesota" |

state="Wisconsin"

then region="GL";

*define the south atlantic region;

else if state="North Carolina" |

state="South Carolina" |

state="Georgia" |

state="Florida East Coast"

then region="SA";

else output hl_dropped; *the data set, dropped, contains data

from states not considered;

if region~=" " then output hl_2; *here we output the landings and

price data that we will use;

run;

proc sql;

create table hl_3 as select

hl_2.region,

hl_2.state,

hl_2.year,

hl_2.species as AFSSpecies, /*species as defined in landings

data*/

hl_2.pounds

from hl_2;

quit;

*join species map with historic landings data (the landings data species

definitions are mapped to the I&E species definitions);

proc sql;

create table hl_4 as select

s.*,

p.*

from smap as s left join hl_3 as p

on s.valspecies=p.AFSSpecies

where p.region~="";

quit;

*calculate the sum according to cfspecies;

proc sql; create table hl_5 as select

a.cfspecies,

a.region,

a.year,

sum(pounds) as pounds

from hl_4 as a group by cfspecies,region,year;

quit;

*estimate an average harvest among all years with data for each cfspecies/region;

Proc sql;

create table hl_6 as select

a.cfspecies,

Page 6
a.year,

a.region,

a.pounds,

mean(pounds) as average_pounds_30yr,

max(pounds) as max_pounds_30yr

from hl_5 as a group by cfspecies, region;

quit;

proc sql;

create table hl_6_5yr as select

a.cfspecies,

a.year,

a.region,

a.pounds,

mean(pounds) as average_pounds_5yr,

max(pounds) as max_pounds_5yr

from hl_5 as a

where year>2006

group by cfspecies, region;

quit;

*calculate the 90th percentile for reported harvest;

proc univariate data=hl_6 noprint;

var pounds;

by cfspecies region;

output out=hl_7 p90=p90_30yr;

run;

proc sort data=hl_6 out=hl_6a nodupkey; by cfspecies region; RUN;

proc sort data=hl_6_5yr out=hl_6_5yr_a nodupkey; by cfspecies region; RUN;

*merge percentiles back in with the harvest data;

proc sql;

create table hl_8 as select

a.cfspecies,

a.region as re,

a.average_pounds_30yr,

a.max_pounds_30yr,

b.*

from hl_6a as a left join hl_7 as b

on a.cfspecies=b.cfspecies and a.region=b.region;

quit;

*merge in the 5yr averages at the level of iespecies as well;

proc sql;

create table hl_9 as select

a.cfspecies,

a.re,

a.average_pounds_30yr,

a.max_pounds_30yr,

a.p90_30yr,

b.average_pounds_5yr,

b.max_pounds_5yr

from hl_8 as a left join hl_6_5yr_a as b

on a.cfspecies=b.cfspecies and a.re=b.region;

quit;

*Get NB Ratio data and join it with the revnenue/price data;

*The NB ratio is the ratio by which the change in gross revenue can be multiplied

to

obtain the change in producer surplus;

*Import data;

%import(&inloc.&input,NBRatio,r1);

*drop unneeded vars;

data r2 (keep=region species_econ ABT_NB_Ratio);

set r1;

if species_econ="dungeness" then species_econ="dungeness.crab";

if species_econ="non.ris.com" | species_econ="non.ris.rec.com" |

species_econ="other.com" | species_econ="other.rec.com"

then do species_econ="other.com.species";

end;

if region="" then delete;

Page 7
RUN;

proc sort data=r2 out=r2 nodupkey; by region species_econ; RUN;

*sort data and drop duplicate observations;

proc sort data=r2 out=r3; by region species_econ ABT_NB_Ratio; run;

data r4 error1; *in this data step, we want to keep only unique species-NBRatio

observations;

set r3;

by region species_econ ABT_NB_Ratio;

if first.ABT_NB_Ratio then rat=1;

if first.species_econ then spe=1;

if first.region then reg=1;

*(A) drop duplicate obervations;

if rat=1 and spe~=1 and species_econ="anchovies" and

region="calif" then delete;

*(B) Look for duplicate obervations that need to be

dropped;

else if rat=1 and spe~=1 then do;

put "r4 data step error caused by region:" region

"and species: " species_econ;

output error1;

end;

if rat=1 and spe=1 then output r4;

else if rat=1 | spe=1 then output error1;

run;

*drop extra variables;

data r5 (keep=re region species_econ ABT_NB_Ratio);

set r4;

length re $3.;

*recode the region variable;

if region="calif" then re="CA";

else if region="greatlakes" then re="GL";

else if region="gulfmexico" then re="GM";

else if region="midatlantic" then re="MA";

else if region="northatlantic" then re="NA";

else if region="southatlantic" then re="SA";

else put "data step generating r5 has an error";

label re="Region Abbreviation"

region="region (short)"

species_econ="I&E Species Name"

ABT_NB_Ratio="Net Benefits Ratio";

run;

*get map between "I&E species" and "Commercial Fishery Species";

proc sort data=smap out=smap2; by cfspecies iespecies; run;

data smap3;

set smap2;

by cfspecies iespecies;

if first.iespecies;

run;

*Add "Commercial Fishery Species" variable to NB Ratio data;

proc sql;

create table r6 as select

r5.re,

r5.region,

smap3.cfspecies label="Commercial Fishing Species Market Group",

r5.species_econ,

r5.ABT_NB_Ratio

from r5 left join smap3 on

r5.species_econ=smap3.iespecies

order by re,cfspecies,species_econ;

quit;

*drop observations without "Commercial Fishery Species" ;

data step2data;

set r6;

if cfspecies~=" ";

Page 8
*Use generic price for GL sculpins because landings data are not

available;

if re="GL" and species_econ="sculpins" then cfspecies="blank";

run;

*Combine Price and Ratio Data;

proc sql;

create table D1 as select

st2.*,st1.pounds,st1.price2011,st1.dollars2011

from step2data as st2 left join step1data as st1 on

st1.cfspecies=st2.cfspecies

and st1.region=st2.re

order by st2.region,st2.species_econ;

quit;

*Perform Data Check;

data PriceIsMissing;

set d1;

if price2011=.;

put "Error in PriceIsMissing datasetp for species = "

species_econ

" No Landings data for these species, in the

region: " region;

run;

*Use Average Price Data where species specific price is not available;

data Step3data;

set D1;

run;

*Import I&E Data;

%import(&facloc.&input2,BNB_IMP,I);

%import(&facloc.&input2,BNB_ENT,E);

%import(&facloc.&input2,BNB_IE,ei);

%import(&facloc.&input2,REDUCTIONS_DETAIL,reductions_detail)

%macro iore(lm);

data &lm.1 (keep=option option_name region species_econ lossmode

com_loss);

length option $8.;

set &lm.;

if metric ="yf.lbs"

and comrec_type ="com.types"

and species_econ ~="zz.all.species"

and region

~="zz.allregions";

%optionmac0(1);

rename benefit_value_regional=com_loss;

run;

data &lm.2 (keep=option option_name region species_econ lossmode

com_loss);

length region $20. option $8.;

set &lm.;

if metric ="yf.lbs"

and comrec_type ="com.types"

and species_econ ~="zz.all.species"

and region

~="zz.allregions";

%optionmac0(2);

option="baseline";

rename baseline_value_regional=com_loss;

run;

Page 9
data &lm.3;

set &lm.2 &lm.1;

if species_econ="other.com" then

species_econ="other.com.species";

run;

%mend;

%iore(i);

%iore(e);

%iore(ei);

data ie2 (drop=option_name);

set i3 e3;

if species_econ="dungeness" then species_econ="dungeness.crab";

if option ="." then delete;

if species_econ="non.ris.com" | species_econ="non.ris.rec.com" |

species_econ="other.com" | species_econ="other.rec.com"

then do species_econ="other.com.species";

end;

run;

*Add "Commercial Fishery Species" variable to IM&E data;

proc sql;

create table ie3 as select

ie2.*,

smap3.cfspecies

from ie2 left join smap3 on

ie2.species_econ=smap3.iespecies;

quit;

*Calculate total IM&E eliminations and reductions by Option, Region, and

CFspecies;

proc sql;

create table ie4 as select

option,region,cfspecies,

sum(com_loss) as treduction

from ie3 group by option,region,cfspecies;

quit;

*Calculate shares of total eliminations and reduction by:

lossmode (impingment or entrainment)

and IM&E Species (CFspecies may include more than one IM&E Species);

proc sql;

create table ie5 as select

ie4.option,ie4.region,

ie3.species_econ,

ie4.cfspecies,

ie3.lossmode,

ie3.com_loss/ie4.treduction as rpercent,

ie4.treduction

from ie4 left join ie3 on

ie3.option=ie4.option and

ie3.region=ie4.region and

ie3.cfspecies=ie4.cfspecies;

quit;

*combine IM&E data with prices data;

proc sql;

create table Step4Data as select

ie5.option label="Regulatory Option",

ie5.region,

ie5.cfspecies,

ie5.species_econ,

ie5.lossmode label="Type of Losses: impingement or entrainment",

ie5.rpercent format=percent15.2 label="LossMode/IE Species Share

of Reductions",

ie5.treduction as reduction

format=comma20.0 Label="option/region/CFSpecies

Reductions (LBS)",

Page 10
st3.ABT_NB_Ratio,

st3.pounds as oldlbs Label="BAU Average Annual LBS",

st3.price2011 Label="BAU Average Dockside Price 2011$",

st3.dollars2011 Label="BAU Gross Dockside Revenues 2011$"

from ie5 left join step3data as st3

on ie5.region=st3.region and ie5.species_econ=st3.species_econ

where ie5.rpercent>0;

quit;

Data step4data;

format re $4.;

set step4data;

if region="calif" then do re="CA"; end;

if region="greatlakes" then do re="GL"; end;

if region="gulfmexico" then do re="GM"; end;

if region="midatlantic" then do re="MA"; end;

if region="northatlantic" then do re="NA"; end;

if region="southatlantic" then do re="SA"; end;

RUN;

Data test;

set Step4Data;

if ABT_NB_ratio~="." then delete;

RUN;

*/Calculate Benefits Schedule By Option;*/

*Import facility data with both facility id's;

%import(&facloc.&fac_input,IDMAP,f1);

*Import data with weights;

%import(&facloc.&fac_input,ID_AND_WEIGHT,ID_AND_WEIGHT);

*Import data with region and flow;

%import(&facloc.&fac_input,flowdata,f3);

*Import data with compliance dates;

%import(&facloc.&fac_input,complianceyear,cydata);

*Get ID for joining datasets;

proc sql;

create table f4 as select

id.plntcode,

w.id as facility,

w.ps_wgt as Weighting_Factor

from f1 as id right join ID_AND_WEIGHT as w on id.surveyid=w.id;

quit;

*Drop double counted plants;

proc sort data=f4 out=f5; by plntcode; run;

data f6;

set f5;

by plntcode;

if (not first.plntcode | not last.plntcode) and

Weighting_Factor=0 then delete;

run;

*join flow and weight data;

proc sql;

create table f7 as select

f6.*,

f3.Benefits_Region,f3.AverageFlow

from f6 full join f3 on f6.plntcode=f3.EIA_Code where f3.EIA_Code~=.;

quit;

*recode region variable;

data f8 (keep=region AverageFlow Weighting_Factor PLNTCODE facility);

set f7;

format region $14.;

if Benefits_Region="CN" | Benefits_Region="CS" |

Benefits_Region="CAL" | Benefits_Region="HI" then region="California";

else if Benefits_Region="GL"

then region="Great Lakes";

else if Benefits_Region="INL"

Page 11
then region="Inland";

else if Benefits_Region="MA"

then region="Mid-Atlantic";

else if Benefits_Region="Mex"

then region="Gulf of Mexico";

else if Benefits_Region="NA"

then region="North Atlantic";

else if Benefits_Region="SA"

then region="South Atlantic";

else if Benefits_Region="PNW" then delete;

else if Benefits_Region="VI" then delete;

run;

*combine and format data with average flow, region, wgt, and compliance year;

proc sql;

create table s2a as select

f8.plntcode,f8.AverageFlow as

avgflow,f8.Region,f8.Weighting_Factor as newweight,

cydata.base_newtech as base_newtech,

cydata.tmn1_newtech as tmn1_newtech,

cydata.tmn2_newtech as tmn2_newtech,

cydata.tmn3_newtech as tmn3_newtech,

%cyr

from f8 full join cydata on cydata.id=f8.facility;

quit;

proc sql;

create table s2 as select

s2a.*

from s2a;

quit;

Data s2;

set s2;

if region="" then delete;

RUN;

Proc sort data=s2 out=s2;

by region;

RUN;

**************************************************************************

*THIS MACRO CALCULATES BENEFITS SCHEDULE FOR FACILITIES ASSIGNED IM TECH

note: the distinction based on ie_year is no longer relevant within the

model code.

Incorporates the biological lag and the lag in compliance;

%macro step5schedule(opt,cyr,opt_short);

*generate benefits schedule;

data s3i;

set s2;

where region~="Virgin Islands";

array flowy_(60) flowy_1-flowy_60;

array bio(60) bio_1-bio_60;

array bschd(60) bschd_1-bschd_60;

do i=1 to 60;

if "&opt"="baseline" then do;

flowy_(i)=avgflow;

if region="Inland" |

region="Great Lakes" | region="Gulf of Mexico" then do; *benefits begin in first

year for these regions;

if i=1 then bio(i)=.1;

if i=2 then bio(i)=.2;

if i=3 then bio(i)=.8;

if i=4 then bio(i)=.9;

if i=5 then bio(i)=.95;

if i=6 then bio(i)=1;

if i>6 and i<=46 then

bio(i)=1;

if i=47 then bio(i)=.9;

if i=48 then bio(i)=.8;

if i=49 then bio(i)=.2;

Page 12
if i=50 then bio(i)=.1;

if i=51 then bio(i)=.05;

if i>51 then bio(i)=0;

end;

else do; *benefits begin a year

later for other regions (midatlantic, california, northatlantic, southatlantic);

if i=1 then bio(i)=0;

if i=2 then bio(i)=.1;

if i=3 then bio(i)=.2;

if i=4 then bio(i)=.8;

if i=5 then bio(i)=.9;

if i=6 then bio(i)=.95;

if i=7 then bio(i)=1;

if i>7 and i<=46 then

bio(i)=1;

if i=47 then bio(i)=.9;

if i=48 then bio(i)=.8;

if i=49 then bio(i)=.2;

if i=50 then bio(i)=.1;

if i=51 then bio(i)=.05;

if i>51 then bio(i)=0;

end;

end;

else do;

if &cyr.>&ie_year_1. then

delete;

if region="Inland" |

region="Great Lakes" | region="Gulf of Mexico" then do;

*benefits begin

in first year for these regions;

x=i-&cyr.+&t0.;

*e.g., if i=1 and cyr = 2011 and first year of rule is 2011 then x=1 in 2011;

if

x<=0 then flowy_(i)=0; *x=1 in first year of compliance;

else

flowy_(i)=avgflow*&opt_short._newtech;

if _n_=1 then put

"Not BASELINE";

if

x<=0 then bio(i)=0;

else if x=1

then bio(i)=.1;

else if x=2

then bio(i)=.2;

else if x=3

then bio(i)=.8;

else if x=4

then bio(i)=.9;

else if x=5

then bio(i)=.95;

else if x=6

then bio(i)=1;

else if x=7

then bio(i)=1;

else if x=8

then bio(i)=1;

else if x=9

then bio(i)=1;

else if x>=9

and i<=46 then bio(i)=1;

else if i=47

then bio(i)=.9;

else if i=48

then bio(i)=.8;

else if i=49

then bio(i)=.2;

else if i=50

Page 13
then bio(i)=.1;

else if i=51

then bio(i)=0.05;

else if i>51

then bio(i)=0;

end;

else do;

*benefits begin

in second year for these regions;

x=i-&cyr.+&t0.;

*e.g., if i=1 and cyr = 2011 and first year of rule is 2011 then x=1 in 2012;

if

x<0 then flowy_(i)=0;*x=1 in second year of compliance;

else

flowy_(i)=avgflow*&opt_short._newtech;

if _n_=1 then put

"Not BASELINE";

if

x<=0 then bio(i)=0;

else if x=1

then bio(i)=0;

else if x=2

then bio(i)=.1;

else if x=3

then bio(i)=.2;

else if x=4

then bio(i)=.8;

else if x=5

then bio(i)=.9;

else if x=6

then bio(i)=.95;

else if x=7

then bio(i)=1;

else if x=8

then bio(i)=1;

else if x=9

then bio(i)=1;

else if x=10

then bio(i)=1;

else if x>=10

and i<=46 then bio(i)=1;

else if i=47

then bio(i)=.9;

else if i=48

then bio(i)=.8;

else if i=49

then bio(i)=.2;

else if i=50

then bio(i)=.1;

else if i=51

then bio(i)=0.05;

else if i>51

then bio(i)=0;

end;

end;

bschd(i)=(flowy_(i)*bio(i));

end;

format reg $30.;

if region="California"

then reg="calif";

else if region="Great Lakes"

then reg="greatlakes";

else if region="Gulf of Mexico"

then reg="gulfmexico";

else if region="Inland"

then reg="inland";

Page 14
else if region="Mid-Atlantic"

then reg="midatlantic";

else if region="North Atlantic"

then reg="northatlantic";

else if region="South Atlantic"

then reg="southatlantic";

run;

*calculate total average flow by region;

proc sql;

create table s5i as select

s3i.*,

sum(avgflow*newweight*&opt_short._newtech) as totalavgflow

/*group flag*/

from s3i group by region;

quit;

*generate flow and benefits schedule variables (for each facility) as percentages

to total regional average flow;

data s6i (drop=bio_1-bio_60 flowy_1-flowy_60);

set s5i;

array flowy_(60) flowy_1-flowy_60;

array bschd(60) bschd_1-bschd_60;

do i=1 to 60;

if totalavgflow=0 then flowy_(i)=0;

else if totalavgflow~=0 then

flowy_(i)=newweight*flowy_(i)/totalavgflow;

if totalavgflow=0 then bschd(i)=0;

else if totalavgflow~=0 then

bschd(i)=newweight*bschd(i)/totalavgflow;

end;

run;

*sort data by region;

proc sort data=s6i out=s7i; by region; run;

*generate benefits schedule variable for region, e.g., 1 = full benefits, .5 =

50% of full benefits;

data s8i_&opt (keep=option region reg rbschd_1-rbschd_60);

retain option region reg rbschd_1-rbschd_60;

set s7i;

by region;

option="&opt";

array bschd(60) bschd_1-bschd_60;

array rbschd(60) rbschd_1-rbschd_60;

do i=1 to 60;

if first.region then rbschd(i)=bschd(i);

else rbschd(i)+bschd(i);

end;

if last.region;

run;

*repeat for alternative presentation of options;

data s8i_&opt._0 (keep=option region reg rbschd_1-rbschd_60);

retain option region reg rbschd_1-rbschd_60;

set s7i;

by region;

option="&opt._0";

array bschd(60) bschd_1-bschd_60;

array rbschd(60) rbschd_1-rbschd_60;

do i=1 to 60;

if first.region then rbschd(i)=bschd(i);

else rbschd(i)+bschd(i);

end;

if last.region;

run;

%mend;

***********************************************************************

Page 15
THIS MACRO CALCULATES BENEFITS SCHEDULE FOR FACILITIES ASSIGNED TOWERS

note: the distinction based on ie_year is no longer relevant in the

model code.

Incorporates the biological lag and the lag in compliance;

%macro step6schedule(opt,cyr,opt_short);

*generate benefits schedule;

data s3t;

set s2;

where region~="Virgin Islands";

array flowy_(60) flowy_1-flowy_60;

array bio(60) bio_1-bio_60;

array bschd(60) bschd_1-bschd_60;

do i=1 to 60;

if "&opt"="baseline" then do;

flowy_(i)=avgflow;

if region="Inland" |

region="Great Lakes" | region="Gulf of Mexico" then do;*benefits begin in first

year for these regions;

if i=1 then bio(i)=.1;

if i=2 then bio(i)=.2;

if i=3 then bio(i)=.8;

if i=4 then bio(i)=.9;

if i=5 then bio(i)=.95;

if i=6 then bio(i)=1;

if i>6 and i<=46 then

bio(i)=1;

if i=47 then bio(i)=.9;

if i=48 then bio(i)=.8;

if i=49 then bio(i)=.2;

if i=50 then bio(i)=.1;

if i=51 then bio(i)=.05;

if i>51 then bio(i)=0;

end;

else do; *benefits begin a year

later for other regions (midatlantic, california, northatlantic, southatlantic);

if i=1 then bio(i)=0;

if i=2 then bio(i)=.1;

if i=3 then bio(i)=.2;

if i=4 then bio(i)=.8;

if i=5 then bio(i)=.9;

if i=6 then bio(i)=.95;

if i=7 then bio(i)=1;

if i>7 and i<=46 then

bio(i)=1;

if i=47 then bio(i)=.9;

if i=48 then bio(i)=.8;

if i=49 then bio(i)=.2;

if i=50 then bio(i)=.1;

if i=51 then bio(i)=.05;

if i>51 then bio(i)=0;

end;

end;

else do;

if &cyr.<&ie_year_1. then

delete;

if region="Inland" |

region="Great Lakes" | region="Gulf of Mexico" then do;

*benefits begin

in first year for these regions;

x=i-&cyr.+&t0.;

*e.g., if i=1 and cyr = 2011 and first year of rule is 2011 then x=1 in 2011;

if

x<=0 then flowy_(i)=0; *x=1 in first year of compliance;

else

flowy_(i)=avgflow*&opt_short._newtech;

if _n_=1 then put

"Not BASELINE";

Page 16
if

x<=0 then bio(i)=0;

else if x=1

then bio(i)=.1;

else if x=2

then bio(i)=.2;

else if x=3

then bio(i)=.8;

else if x=4

then bio(i)=.9;

else if x=5

then bio(i)=.95;

else if x=6

then bio(i)=1;

else if x=7

then bio(i)=1;

else if x=8

then bio(i)=1;

else if x=9

then bio(i)=1;

else if x>=9

and i<=46 then bio(i)=1;

else if i=47

then bio(i)=.9;

else if i=48

then bio(i)=.8;

else if i=49

then bio(i)=.2;

else if i=50

then bio(i)=.1;

else if i=51

then bio(i)=0.05;

else if i>51

then bio(i)=0;

end;

else do;

*benefits begin

in second year for these regions;

x=i-&cyr.+&t0.;

*e.g., if i=1 and cyr = 2011 and first year of rule is 2011 then x=1 in 2012;

if

x<0 then flowy_(i)=0;*x=1 in second year of compliance;

else

flowy_(i)=avgflow*&opt_short._newtech;

if _n_=1 then put

"Not BASELINE";

if

x<=0 then bio(i)=0;

else if x=1

then bio(i)=0;

else if x=2

then bio(i)=.1;

else if x=3

then bio(i)=.2;

else if x=4

then bio(i)=.8;

else if x=5

then bio(i)=.9;

else if x=6

then bio(i)=.95;

else if x=7

then bio(i)=1;

else if x=8

then bio(i)=1;

else if x=9

then bio(i)=1;

Page 17
else if x=10

then bio(i)=1;

else if x>=10

and i<=46 then bio(i)=1;

else if i=47

then bio(i)=.9;

else if i=48

then bio(i)=.8;

else if i=49

then bio(i)=.2;

else if i=50

then bio(i)=.1;

else if i=51

then bio(i)=0.05;

else if i>51

then bio(i)=0;

end;

end;

bschd(i)=(flowy_(i)*bio(i));

end;

format reg $30.;

if region="California"

then reg="calif";

else if region="Great Lakes"

then reg="greatlakes";

else if region="Gulf of Mexico"

then reg="gulfmexico";

else if region="Inland"

then reg="inland";

else if region="Mid-Atlantic"

then reg="midatlantic";

else if region="North Atlantic"

then reg="northatlantic";

else if region="South Atlantic"

then reg="southatlantic";

run;

*calculate total average flow by region;

proc sql;

create table s5t as select

s3t.*,

sum(avgflow*newweight*&opt_short._newtech) as totalavgflow

/*group flag*/

from s3t group by region;

quit;

*generate flow and benefits schedule variables (for each facility) as percentages

to total regional average flow;

data s6t (drop=bio_1-bio_60 flowy_1-flowy_60);

set s5t;

array flowy_(60) flowy_1-flowy_60;

array bschd(60) bschd_1-bschd_60;

do i=1 to 60;

if totalavgflow=0 then flowy_(i)=0;

else if totalavgflow~=0 then

flowy_(i)=newweight*flowy_(i)/totalavgflow;

if totalavgflow=0 then bschd(i)=0;

else if totalavgflow~=0 then

bschd(i)=newweight*bschd(i)/totalavgflow;

end;

run;

*sort data by region;

proc sort data=s6t out=s7t; by region; run;

*generate benefits schedule variable for region, e.g., 1 = full benefits, .5 =

50% of full benefits;

data s8t_&opt (keep=option region reg rbschd_1-rbschd_60);

Page 18
retain option region reg rbschd_1-rbschd_60;

set s7t;

by region;

option="&opt";

array bschd(60) bschd_1-bschd_60;

array rbschd(60) rbschd_1-rbschd_60;

do i=1 to 60;

if first.region then rbschd(i)=bschd(i);

else rbschd(i)+bschd(i);

end;

if last.region;

run;

*repeat 5j6 (for alternative presentation of options);

data s8t_&opt._0 (keep=option region reg rbschd_1-rbschd_60);

retain option region reg rbschd_1-rbschd_60;

set s7t;

by region;

option="&opt._0";

array bschd(60) bschd_1-bschd_60;

array rbschd(60) rbschd_1-rbschd_60;

do i=1 to 60;

if first.region then rbschd(i)=bschd(i);

else rbschd(i)+bschd(i);

end;

if last.region;

run;

%mend;

*This macro calculates benefits schedule, incorporating the biological lag and

the lag in compliance;

*Generate dataset of Benefits Schedule By Option;

%optionmac00;

%optionmac11;

******************************************************************************

******************************************************************************

NEED TO MANIPULATE Step5data in order to implement impingement fraction

note: the distinction based on ie_year is no longer relevant in the model code.

*need to rename array functions in the Step5idata and Step5data;

Data step5idata;

SET step5idata;

array rbschd_(60) rbschd_1 - rbschd_60;

array rbschd_i_(60) rbschd_i_1 - rbschd_i_60;

do i=1 to 60;

rbschd_i_(i)=rbschd_(i);

IF rbschd_i_(i)="." then rbschd_i_(i)=0;

end;

drop rbschd_1-rbschd_60 i;

if region="" then delete;

RUN;

Data step5tdata;

SET step5tdata;

array rbschd_(60) rbschd_1 - rbschd_60;

array rbschd_t_(60) rbschd_t_1 - rbschd_t_60;

do i=1 to 60;

rbschd_t_(i)=rbschd_(i);

IF rbschd_t_(i)="." then rbschd_t_(i)=0;

end;

drop rbschd_1-rbschd_60 i;

if region="" then delete;

RUN;

PROC SORT data=step5idata out=step5idata;

by option region reg;

RUN;

PROC SORT data=step5tdata out=step5tdata;

by option region reg;

RUN;

Data step5data;

merge step5idata step5tdata;

Page 19
by option region reg;

RUN;

*reorganize reductions_detail sheet;

Data reductions_detail_1;

set reductions_detail;

format option $20.;

impingement_fraction_imp = (1-ccr_fraction_imp);

if option_name="option.tmn1" then option="tmn1x";

if option_name="option.tmn2" then option="tmn2x";

if option_name="option.tmn3" then option="tmn3x";

option_name=option;

reg=region;

DROP ccr_fraction_imp option_name region benefit_value_regional_imp;

RUN;

Data reductions_detail_2;

set reductions_detail;

format option $20.;

impingement_fraction_imp = (1-ccr_fraction_imp);

if option_name="option.tmn1" then option="tmn1x_0";

if option_name="option.tmn2" then option="tmn2x_0";

if option_name="option.tmn3" then option="tmn3x_0";

option_name=option;

reg=region;

DROP ccr_fraction_imp option_name region;

RUN;

Data reductions_detail_3;

set reductions_detail_1 reductions_detail_2;

RUN;

Proc sort data=reductions_detail_3 out=reductions_detail_3;

by option reg;

RUN;

Data step5data_1;

merge step5data reductions_detail_3;

by option reg;

RUN;

Data step5data_1;

set step5data_1;

if impingement_fraction_imp="." then impingement_fraction_imp=1;

RUN;

Data step5data_2;

set step5data_1;

array rbschd_i_(60) rbschd_i_1 - rbschd_i_60;

array rbschd_t_(60) rbschd_t_1 - rbschd_t_60;

array rbschd_adj_(60) rbschd_adj_1 - rbschd_adj_60;

do i=1 to 60;

if rbschd_i_(i)= "." then rbschd_i_(i)=0;

if rbschd_t_(i)= "." then rbschd_t_(i)=0;

rbschd_adj_(i)=impingement_fraction_imp*rbschd_i_(i)+(1-impingement_fraction_imp)

*rbschd_t_(i);

END;

DROP rbschd_i_1-rbschd_i_60 impingement_fraction_imp i;

RUN;

Data step5data_2imp;

set step5data_2;

drop rbschd_t_1-rbschd_t_60;

lossmode="imp";

array rbschd_adj_(60) rbschd_adj_1-rbschd_adj_60;

array rbschd_(60) rbschd_1-rbschd_60;

do i=1 to 60;

rbschd_(i)=rbschd_adj_(i);

END;

Drop rbschd_adj_1-rbschd_adj_60 i;

if option="tmn1x" then option="tmn1";

if option="tmn2x" then option="tmn2";

if option="tmn3x" then option="tmn3";

if option="tmn1x_0" then option="tmn1_0";

if option="tmn2x_0" then option="tmn2_0";

if option="tmn3x_0" then option="tmn3_0";

Page 20
RUN;

Data step5data_2ent;

set step5data_2;

drop rbschd_adj_1-rbschd_adj_60;

lossmode="ent";

array rbschd_t_(60) rbschd_t_1-rbschd_t_60;

array rbschd_(60) rbschd_1-rbschd_60;

do i=1 to 60;

rbschd_(i)=rbschd_t_(i);

END;

Drop rbschd_t_1-rbschd_t_60 i;

if option="tmn1x" then option="tmn1";

if option="tmn2x" then option="tmn2";

if option="tmn3x" then option="tmn3";

if option="tmn1x_0" then option="tmn1_0";

if option="tmn2x_0" then option="tmn2_0";

if option="tmn3x_0" then option="tmn3_0";

RUN;

Data step5data_3;

set step5data_2imp step5data_2ent;

optionname=option;

region=reg;

RUN;

******************************************************************************

*create separate step4data files for the different options;

Data step4data;

length option $20;

set step4data;

RUN;

proc sort data=step4data out=step4data;

by option region lossmode;

RUN;

Proc sort data=step5data_3 out=step5data_3;

by option region lossmode;

RUN;

Data s6;

merge step4data step5data_3;

by option region lossmode;

RUN;

*sort data;

proc sort data=s6 out=step6data;

by optionname region re cfspecies species_econ lossmode

rpercent

reduction ABT_NB_Ratio oldlbs price2011 dollars2011;

run;

data step6data_1;

set step6data;

if species_econ="" then delete;

RUN;

*merge in the historical landings data for each species/region;

data step6data_cap;

set step6data;

if species_econ="" then delete;

keep option re cfspecies reduction;

RUN;

proc sort data=step6data_cap out=step6data_cap nodupkey;

by option re cfspecies;

RUN;

proc sql;

create table step6data_cap2 as select

a.*,

b.*

from step6data_cap as a left join hl_9 as b

on a.cfspecies=b.cfspecies and a.re=b.re;

quit;

Data cap_eval_list;

Page 21
format percent_harvest_increase percent10.4;

set step6data_cap2;

percent_harvest_increase=reduction/average_pounds_5yr;

if percent_harvest_increase < .10 then delete;

RUN;

proc sort data=cap_eval_list out=cap_eval_list nodupkey;

by re cfspecies;

RUN;

Data cap_eval_list;

set cap_eval_list;

cap_eval_marker=1;

keep re cfspecies cap_eval_marker;

RUN;

proc sql;

create table step6data_cap2x as select

a.*,

b.*

from step6data_cap2 as a left join cap_eval_list as b

on a.re=b.re and a.cfspecies=b.cfspecies

where b.cap_eval_marker=1;

quit;

Data step6data_cap3;

set step6data_cap2x;

new_harvest=(average_pounds_5yr+reduction);

*create a binary variable to indicate whether the new harvest exceeds the 90th

percentile of historic harvest;

if new_harvest ge p90_30yr then cap_90_dummy=1;

*include options for other capping rules - they need to be entered manually;

if re="CA" and cfspecies="cabezon" then do cap_other=(207.2*1000); end; *based on

MSY from BA;

if cfspecies="california.halibut" then do cap_other=(982106); end; *the average

of the most recent 4 peaks in harvest, calculated directly from harvest data;

if re="CA" and cfspecies="rockfishes" then do cap_other=(77161.8*1000); end;

*based on MSY from BA;

if re="CA" and cfspecies="sculpins" then do cap_other=(482.8*1000); end; *based

on MSY for BA;

*create a binary variable to indicate wther the "other cap" is being exceeded;

if cap_other~="." and new_harvest>cap_other then do cap_other_dummy=1; end;

reduction_cap_other=cap_other_dummy*(cap_other-average_pounds_5yr);

reduction_cap_90=cap_90_dummy*(p90_30yr-average_pounds_5yr);

cap=min(reduction_cap_other,reduction_cap_90);

RUN;

*create a summary table with just the region, option, cfspecies, and cap;

*to be merged back with the main data set of reductions;

proc sql; create table step6data_cap4 as select

a.re,

a.option,

a.cfspecies,

a.cap

from step6data_cap3 as a;

quit;

*merge the capping results back in with the data;

proc sql;

create table step6data_1x as select

a.*,b.*

from step6data_1 as a left join step6data_cap4 as b

on a.re=b.re and a.option=b.option and a.cfspecies=b.cfspecies;

quit;

Data step6data_1x; set step6data_1x;

if cap~="." then do reduction=cap; end;

drop cap;

RUN;

*check cases where the compliance schedule is zero for peaks at less than 1;

data test;

set step6data_1x;

Page 22
if rbschd_45~=0 then delete;

RUN;

*************************************************************************

*************************************************************************

Calculate Producer Surplus, Total and Annualize

*note: Consumer Surplus calculations not used in the analysis

*Reshape data so from wide to long;

proc sort data=step6data_1x out=step6data_1x;

by optionname region re cfspecies species_econ lossmode rpercent

reduction ABT_NB_Ratio oldlbs price2011 dollars2011;

RUN;

proc transpose data=step6data_1x out=long6;

by optionname region re cfspecies species_econ lossmode rpercent

reduction ABT_NB_Ratio oldlbs price2011 dollars2011;

run;

*reformat long-shaped data;

data long7 (drop=_name_ col1);* check1 (keep=region cfspecies);

set long6;

rbschd=col1;

year=input(substr(_name_,8,2),2.0);

run;

data long7a;

set long7;

if cfspecies in

("com.crabs","dungeness.crab","blue.crab","stone.crab")

then elasticity=&Elast_crabs;

else if cfspecies in ("pink.shrimp","pink shrimp","com.shrimp")

then elasticity=&Elast_shrimp;

else if region~="greatlakes" & cfspecies~="blank"

then elasticity=&Elast_saltwater;

run;

*Calculate Consumer and Producer Surplus For Years 1-50;

data long8;

set long7a;

%macro undiscsurplus(opt,ievar,iepercent);

if optionname="&opt" then do; *(dont

perform for irrelevent options);

/*FLAG Rule of Thumb*/*if

region~="greatlakes" and cfspecies~="blank" and negprice~=1 then do;*(saltwater

species with landings data have consumer surplus);

if 1=2 then do; /*FLAG Rule of

Thumb*/

if &ievar.~=. and

&ievar.~=0 then do;

percent=&iepercent.; *elimination or reduction;

IEchange=&ievar.;

*elimination or reduction;

lbs=&ievar.*rbschd+oldlbs; *post-I&E reduction harvest;

price=price2011*((lbs/oldlbs-1)/elasticity+1); *post-I&E reduction price;

CS=((price2011-price)*oldlbs+0.5*(price2011-price)*

(lbs-oldlbs))*&iepercent.; *post-I&E reduction Consumer surp;

GR=price*lbs-price2011*oldlbs; *post-I&E reduction Gross revenue (not adjusted

for imp/ent and species);

PS=GR*ABT_NB_Ratio*&iepercent.; *post-I&E reduction Producer surp;

TS=CS+PS;

*post-I&E reduction welfare gain;

Page 23
end;

else do; *do if there is

no reduction;

percent=.;

IEchange=.;

lbs=oldlbs;

price=price2011;

CS=0;

GR=0;

PS=0;

TS=CS+PS;

end;

end;

*for great lakes assume that the

consumer surplus is equal to the percentage change

in the catch multiplied by the

dockside value of the catch before the change.

based on bishop and holt (2003);

/*FLAG Rule of Thumb*/*else if

region="greatlakes" and cfspecies~="blank" and negprice~=1 then do;

*else if cfspecies~="blank" and

negprice~=1 then do;/*FLAG Rule of Thumb*/

else if 1=2 then do;/*FLAG Rule

of Thumb*/

if &ievar.~=. and

&ievar.~=0 then do;

percent=&iepercent.;

IEchange=&ievar.;

lbs=&ievar.*rbschd+oldlbs;

CSz=(lbs/oldlbs-1)*dollars2011;

CS=CSz*percent;

if CS~=0 then do;

price =

(1/2*(price2011*oldlbs+price2011*lbs)-CSz)/(.5*(lbs+oldlbs));

elasticity=(lbs/oldlbs-1)/(price/price2011-1);

end;

else do;

price=price2011;

end;

GR=price*lbs-price2011*oldlbs;

PS=GR*ABT_NB_Ratio*percent;

TS=CS+PS;

end;

else do;

percent=.;

IEchange=.;

lbs=oldlbs;

elasticity=.;

price=price2011;

CS=0;

GR=0;

PS=0;

TS=CS+PS;

end;

end;

*for species where landings data

are missing assume there is no consumer surplus

and estimate producer surplus

assuming no change in prices;

Page 24
*else if cfspecies="blank" |

negprice=1 then do;

else if 1=1 then do;

if &ievar.~=. and

&ievar.~=0 then do;

percent=&iepercent.;

IEchange=&ievar.;

lbs=&ievar.*rbschd+oldlbs;

elasticity=.;

CS=0;

price=price2011;

GR=price*IEchange*rbschd;

PS=GR*ABT_NB_Ratio*&iepercent.;

TS=CS+PS;

end;

else do;

percent=.;

IEchange=.;

lbs=oldlbs;

elasticity=.;

price=price2011;

CS=0;

GR=0;

PS=0;

TS=CS+PS;

end;

end;

end;

****************;

****************;

*Alternatively, for all species,

assume there is no consumer surplus

and estimate producer surplus

assuming no change in prices;

if optionname="&opt._0" then do;

if &ievar.~=. and

&ievar.~=0 then do;

percent=&iepercent.;

IEchange=&ievar.;

lbs=oldlbs;

elasticity=0;

CS=0;

price=price2011;

GR=price*IEchange*rbschd;

PS=GR*ABT_NB_Ratio*&iepercent.;

TS=CS+PS;

end;

else do;

percent=.;

IEchange=.;

lbs=oldlbs;

elasticity=.;

price=price2011;

CS=0;

GR=0;

PS=0;

TS=CS+PS;

end;

end;

****************;

****************;

%mend;

Page 25
%optionmac2;

*Calculate discounted welfare variables for 3 and 7

percent;

%macro discounted(r);

CS&r. =

CS/(1.0&r.**(year-1+(&t0.-&d0.)));

PS&r. =

PS/(1.0&r.**(year-1+(&t0.-&d0.)));

TS&r. =

TS/(1.0&r.**(year-1+(&t0.-&d0.)));

%mend;

%discounted(3);

%discounted(7);

if price<0 then put "flag error the price is " price "

for region = " re " and species = " species_econ;

run;

*Calculate Consumer and Producer Surplus For All Years;

proc sql;

create table long61 as select

optionname,region,re,cfspecies,species_econ,lossmode,

iechange,percent,

ABT_NB_Ratio,oldlbs,price2011,dollars2011,

61 as year,

sum(CS) as CS,

sum(PS) as PS,

sum(TS) as TS,

sum(CS3) as CS3,

sum(PS3) as PS3,

sum(TS3) as TS3,

sum(CS7) as CS7,

sum(PS7) as PS7,

sum(TS7) as TS7,

max(PS) as PS_peak,

max(TS) as TS_peak

from long8 group by

optionname,region,re,cfspecies,species_econ,lossmode,

iechange,percent,

ABT_NB_Ratio,oldlbs,price2011,dollars2011;

quit;

* 7e Annualized 41-year Benefit (year=52);

proc sql;

create table long62 as select

optionname,region,re,cfspecies,species_econ,lossmode,

iechange,percent,

ABT_NB_Ratio,oldlbs,price2011,dollars2011,

62 as year,

CS/&yrsc. as CS,

PS/&yrsc. as PS,

TS/&yrsc. as TS,

CS3*(.03*(1+.03)**(&yrsc.-1))/((1+.03)**&yrsc.-1) as CS3,

PS3*(.03*(1+.03)**(&yrsc.-1))/((1+.03)**&yrsc.-1) as PS3,

TS3*(.03*(1+.03)**(&yrsc.-1))/((1+.03)**&yrsc.-1) as TS3,

CS7*(.07*(1+.07)**(&yrsc.-1))/((1+.07)**&yrsc.-1) as CS7,

PS7*(.07*(1+.07)**(&yrsc.-1))/((1+.07)**&yrsc.-1) as PS7,

TS7*(.07*(1+.07)**(&yrsc.-1))/((1+.07)**&yrsc.-1) as TS7,

PS_peak as PS_peak,

TS_peak as TS_peak

from long61;

quit;

*Combine years 1-60 with total and annualized;

data long9;

set long8 long61 long62;

run;

Page 26
*Format data of Consumer and Producer Surplus, Total and Annualize;

proc sql;

create table step7data as select

optionname label="Name of Option",

region,re,cfspecies,species_econ,lossmode,

rbschd label="Benefits Schedule Percentage",

elasticity,

ABT_NB_Ratio,

percent label="LossMode/IE Species Share of Reduction"

format=percent12.2,

iechange label="Reduction in Lbs of Fish Lost" format=comma30.2,

year label="Year of Benefits Schedule",

oldlbs,

lbs label="Option Annual LBS of Harvest" format=comma30.2,

price2011,

price label="Price Under Option" format=dollar12.2 ,

dollars2011,

GR label="Change in Gross Revenue (Undiscounted)"

format=dollar30.2,

CS label="Change in Consumer Surplus (Undiscounted)"

format=dollar30.2,

PS label="Change in Producer Surplus (Undiscounted)"

format=dollar30.2,

TS label="Change in Total Surplus (Undiscounted)"

format=dollar30.2,

CS3 label="Change in Consumer Surplus (3%)" format=dollar30.2,

PS3 label="Change in Producer Surplus (3%)" format=dollar30.2,

TS3 label="Change in Total Surplus (3%)" format=dollar30.2,

CS7 label="Change in Consumer Surplus (7%)" format=dollar30.2,

PS7 label="Change in Producer Surplus (7%)" format=dollar30.2,

TS7 label="Change in Total Surplus (7%)" format=dollar30.2,

PS_peak label="Peak Change in Producer Surplus (Undiscounted)"

format=dollar30.2

from long9

order by

optionname,region,re,cfspecies,species_econ,lossmode,year;

quit;

*Begin Data Check;

proc sql;

create table x as select region,

cfspecies,species_econ,

count(cfspecies) as cfcount

from step7data

where year=1

group by region,cfspecies;

quit;

proc sql;

create table x2 as select region,

cfspecies,species_econ,

cfcount,

count(species_econ) as iecount

from x

group by region,cfspecies,species_econ

having count(species_econ)~=cfcount

order by region,cfspecies,species_econ;

quit;

data _null_;

set x2;

by region cfspecies species_econ;

if first.species_econ and species_econ~=cfspecies then

put "Make sure that " species_econ " is

reasonably from a subset of " cfspecies;

run;

*End Data Check;

**********************************************************************

**********************************************************************

Page 27
*SUMMARIZE BY OPTION AND REGION;

proc sql;

create table step8data as select

optionname label="Name of Option",

region,re,

sum(CS)/1000 as CS label="Change in Consumer Surplus

(Undiscounted)" format=dollar30.1,

sum(PS)/1000 as PS label="Change in Producer Surplus

(Undiscounted)" format=dollar30.1,

sum(TS)/1000 as TS label="Change in Total Surplus (Undiscounted)"

format=dollar30.1,

sum(CS3)/1000 as CS3 label="Change in Consumer Surplus (3%)"

format=dollar30.1,

sum(PS3)/1000 as PS3 label="Change in Producer Surplus (3%)"

format=dollar30.1,

sum(TS3)/1000 as TS3 label="Change in Total Surplus (3%)"

format=dollar30.1,

sum(CS7)/1000 as CS7 label="Change in Consumer Surplus (7%)"

format=dollar30.1,

sum(PS7)/1000 as PS7 label="Change in Producer Surplus (7%)"

format=dollar30.1,

sum(TS7)/1000 as TS7 label="Change in Total Surplus (7%)"

format=dollar30.1,

sum(PS_peak)/1000 as PS_peak label="Peak Change in Producer

Surplus (Undiscounted)" format=dollar30.1

from step7data

where year=62

group by optionname,region,re

order by optionname,region,re;

quit;

*Generate Tables;

*pick a year where benefits are in steady state, rbschd=1;

data t1;

set step7data;

if year=45;

if round(rbschd,.0001)~=1 then do;

put "error flag , rbschd = " rbschd " and it should equal

1";

end;

run;

Data t1_zero;

set t1;

if rbschd~=0 then delete;

RUN;

* collapse data by option, region, and species;

proc sql;

create table t2 as select

optionname,region,

cfspecies,

mean(oldlbs) as oldlbs,

max(oldlbs) as oldlbsQA,

mean(price2011) as price2011,

max(price2011) as price2011QA,

mean(elasticity) as elasticity,

max(elasticity) as elasticityQA,

mean(price) as price,

max(price) as priceQA,

sum(cs) as CS,

sum(ps) as PS,

sum(ts) as TS

from t1

group by optionname,region,cfspecies

order by optionname,region,cfspecies;

quit;

*get option/region totals for all species;

proc sql;

Page 28
create table t3 as select

optionname,region,"Total" as cfspecies,

sum(oldlbs*percent) as oldlbs,

sum(cs) as CS,

sum(ps) as PS,

sum(ts) as TS

from t1 group by optionname,region;

quit;

*get species-specific impingement specific variables (pounds of harvest gained);

proc sql;

create table timp as select

optionname,region,cfspecies,

sum(IEchange*percent) as pounds_i

from t1

where lossmode="imp"

group by optionname,region,cfspecies

order by optionname,region,cfspecies;

quit;

*get species-specific entrainment specific variables (pounds of harvest gained);

proc sql;

create table tent as select

optionname,region,cfspecies,

sum(IEchange*percent) as pounds_e

from t1

where lossmode="ent"

group by optionname,region,cfspecies

order by optionname,region,cfspecies;

quit;

*get all-species-total impingement specific variables (pounds of harvest gained);

proc sql;

create table timpT as select

optionname,region,"Total" as cfspecies,

sum(IEchange*percent) as pounds_i

from t1

where lossmode="imp"

group by optionname,region

order by optionname,region;

quit;

*get all-species-total entrainment specific variables (pounds of harvest gained);

proc sql;

create table tentT as select

optionname,region,"Total" as cfspecies,

sum(IEchange*percent) as pounds_e

from t1

where lossmode="ent"

group by optionname,region

order by optionname,region;

quit;

*combine datasets into one table, recode species variable;

data t4 (drop= oldlbsQA price2011QA elasticityQA priceQA);

length cfspecies species reg $50;

merge t2 t3 tent timp tentT timpT;

by optionname region cfspecies;

if cfspecies="Total" then ord=100;

else if cfspecies="blank" then ord=50;

else ord=1;

pounds_ie=sum(pounds_e,pounds_i);

if cfspecies="alewife" then species = "Alewife";

else if cfspecies="american.plaice" then species =

"American Plaice";

else if cfspecies="american.shad" then species =

"American Shad";

Page 29
else if cfspecies="anchovies" then species =

"Anchovies";

else if cfspecies="atlantic.cod" then species =

"Atlantic Cod";

else if cfspecies="atlantic.croaker" then species =

"Atlantic Croaker";

else if cfspecies="atlantic.herring" then species =

"Atlantic Herring";

else if cfspecies="atlantic.mackerel" then species =

"Atlantic Mackerel";

else if cfspecies="atlantic.menhaden" then species =

"Atlantic Menhaden";

else if cfspecies="black.bullhead" then species =

"Black Bullhead";

else if cfspecies="black.crappie" then species =

"Black Crappie";

else if cfspecies="black.drum" then species = "Black

Drum";

else if cfspecies="blue.crab" then species = "Blue

Crab";

else if cfspecies="bluefish" then species =

"Bluefish";

else if cfspecies="bluegill" then species =

"Bluegill";

else if cfspecies="brown.bullhead" then species =

"Brown Bullhead";

else if cfspecies="bullhead.spp" then species =

"Bullhead";

else if cfspecies="butterfish" then species =

"Butterfish";

else if cfspecies="cabezon" then species = "Cabezon";

else if cfspecies="california.halibut" then species =

"California Halibut";

else if cfspecies="california.scorpionfish" then

species = "California Scorpionfish";

else if cfspecies="channel.catfish" then species =

"Channel Catfish";

else if cfspecies="com.crabs" then species =

"Commercial Crabs";

else if cfspecies="com.sea.basses" then species =

"Commercial Sea Basses";

else if cfspecies="com.shrimp" then species =

"Commercial Shrimp";

else if cfspecies="crappie" then species = "Crappie";

else if cfspecies="cunner" then species = "Cunner";

else if cfspecies="drums.croakers" then species =

"Drums and Croakers";

else if cfspecies="dungeness.crab" then species =

"Dungeness Crabs";

else if cfspecies="flounders" then species =

"Flounders";

else if cfspecies="freshwater.drum" then species =

"Freshwater Drum";

else if cfspecies="leatherjacket" then species =

"Leatherjacket";

else if cfspecies="mackerels" then species =

"Mackerels";

else if cfspecies="menhaden.spp" then species =

"Menhaden ";

else if cfspecies="muskellunge" then species =

"Muskellunge";

else if cfspecies="northern.anchovy" then species =

"Northern Anchovy";

else if cfspecies="other.com.species" then species =

"Other Commercial";

else if cfspecies="other.com.crabs" then species =

"Other Commercial Crabs";

else if cfspecies="paddlefish" then species =

"Paddlefish";

Page 30
else if cfspecies="pinfish" then species = "Pinfish";

else if cfspecies="pink.shrimp" then species = "Pink

Shrimp";

else if cfspecies="pollock" then species = "Pollock";

else if cfspecies="rainbow.smelt" then species =

"Rainbow Smelt";

else if cfspecies="red.drum" then species = "Red

Drum";

else if cfspecies="red.hake" then species = "Red

Hake";

else if cfspecies="rockfishes" then species =

"Rockfishes";

else if cfspecies="salmon" then species = "Salmon";

else if cfspecies="sauger" then species = "Sauger";

else if cfspecies="sculpin.spp" then species = "Sculpin

";

else if cfspecies="sculpins" then species =

"Sculpins";

else if cfspecies="scup" then species = "Scup";

else if cfspecies="sea.basses" then species = "Sea

Basses";

else if cfspecies="searobin" then species =

"Searobin";

else if cfspecies="sheepshead" then species =

"Sheepshead";

else if cfspecies="silver.hake" then species = "Silver

Hake";

else if cfspecies="silver.perch" then species =

"Silver Perch";

else if cfspecies="skate.species" then species =

"Skate Species";

else if cfspecies="smallmouth.bass" then species =

"Smallmouth Bass";

else if cfspecies="smelts" then species = "Smelts";

else if cfspecies="spot" then species = "Spot";

else if cfspecies="spotted.seatrout" then species =

"Spotted Seatrout";

else if cfspecies="stone.crab" then species = "Stone

Crab";

else if cfspecies="striped.bass" then species =

"Striped Bass";

else if cfspecies="striped.mullet" then species =

"Striped Mullet";

else if cfspecies="sturgeon.spp" then species =

"Sturgeon ";

else if cfspecies="summer.flounder" then species =

"Summer Flounder";

else if cfspecies="sunfish" then species = "Sunfish";

else if cfspecies="surfperches" then species =

"Surfperches";

else if cfspecies="tautog" then species = "Tautog";

else if cfspecies="walleye" then species = "Walleye";

else if cfspecies="weakfish" then species =

"Weakfish";

else if cfspecies="white.bass" then species = "White

Bass";

else if cfspecies="white.perch" then species = "White

Perch";

else if cfspecies="whitefish" then species =

"Whitefish";

else if cfspecies="windowpane" then species =

"Windowpane";

else if cfspecies="winter.flounder" then species =

"Winter Flounder";

else if cfspecies="yellow.perch" then species =

"Yellow Perch";

else if cfspecies="z.trophic.transfer" then species =

"Trophic Transfer";

else if cfspecies="z.trophic.xfer" then species =

Page 31
"Trophic Transfer";

else if cfspecies="blank" then species = "Other";

else if cfspecies="Total" then species = "Total";

else put "error, No species match for cfspecies variable:

" cfspecies;

*data checks;

if abs(oldlbs-oldlbsQA) >.0001 then put

"error flag oldlbs~=oldlbsQA";

if abs(price2011-price2011QA) >.0001 then put "error

flag price2011~=price2011QA";

if abs(elasticity-elasticityQA) >.0001 then put "error

flag elasticity~=elasticityQA";

if abs(price-priceQA) >.0001 then put

"error flag price~=priceQA";

if region="calif"

then reg="California";

else if region="greatlakes" then

reg="Great Lakes";

else if region="gulfmexico" then

reg="Gulf of Mexico";

else if region="inland" then

reg="Inland";

else if region="midatlantic" then

reg="Mid-Atlantic";

else if region="northatlantic" then

reg="North Atlantic";

else if region="southatlantic" then

reg="South Atlantic";

run;

proc sort data=t4 out=t5; by optionname reg ord cfspecies; run;

*format data, drop rows with no benefits;

proc sql;

create table t6 as select

optionname label="Name of Option",

reg label="Region Name",

species label="Species Name",

oldlbs/1000 as oldlbs label="Average Annual Harvest

2007-20011 (thousands lbs)" format=comma30.1,

price2011 label="Price Per Pound" format=dollar10.2,

pounds_i/1000 as pounds_i label="Increased Harvest from

Reduced Impingment (thousand lbs)" format=comma30.1,

pounds_e/1000 as pounds_e label="Increased Harvest from

Reduced Entrainment (thousand lbs)" format=comma30.1,

pounds_ie/1000 as pounds_ie label='Increased Harvest from

Reduced I&E (thousand lbs)' format=comma30.1,

elasticity label="Own-Price Elasticity" format=comma10.2,

price label="Steady State Price" format=dollar10.2,

CS/1000 as CS label="Consumer Surplus (thousands 2011$)"

format=dollar30.1,

PS/1000 as PS label="Total Producer Surplus (thousands

2011$)" format=dollar30.1,

TS/1000 as TS label="Total Surplus (thousands 2011$)"

format=dollar30.1

from t5

where pounds_ie~=. and pounds_ie~=0;

quit;

*change zeros to missing;

data Step9Data;

set t6;

if pounds_i =0 then pounds_i =.;

if pounds_e =0 then pounds_e =.;

if pounds_ie =0 then pounds_ie =.;

if price =0 then price =.;

if CS =0 then CS

=.;

Page 32
if PS =0 then PS

=.;

if TS =0 then TS

=.;

run;

*create 3% data step from step 8 data;

data Step3p (keep=optionname reg PS species);

set Step8Data;

if region="calif"

then reg="California ";

else if region="greatlakes" then

reg="Great Lakes";

else if region="gulfmexico" then

reg="Gulf of Mexico";

else if region="inland" then

reg="Inland";

else if region="midatlantic" then

reg="Mid-Atlantic";

else if region="northatlantic" then

reg="North Atlantic";

else if region="southatlantic" then

reg="South Atlantic";

species = "Total (3% Discount Rate)";

PS=PS3/1;

run;

*create 7% data step from step 8 data;

data Step7p (keep=optionname reg PS species);

set Step8Data;

if region="calif"

then reg="California ";

else if region="greatlakes" then

reg="Great Lakes";

else if region="gulfmexico" then

reg="Gulf of Mexico";

else if region="inland" then

reg="Inland";

else if region="midatlantic" then

reg="Mid-Atlantic";

else if region="northatlantic" then

reg="North Atlantic";

else if region="southatlantic" then

reg="South Atlantic";

species = "Total (7% Discount Rate)";

PS=PS7/1;

run;

*Combine 3 and 7 percent discount rates with undiscounted;

data Step37p;

set Step9Data Step3p Step7p;

if species="Total"

then ord=1;

else if species="Total (3% Discount Rate)" then ord=2;

else if species="Total (7% Discount Rate)" then ord=3;

else

ord=0;

run;

proc sort data=Step37p; by optionname reg ord species; run;

data os1 (keep=reg optionname increase);

set Step37p;

if ord=1;

rename pounds_ie=increase;

label increase="Increase in Harvest (thousand lbs)";

run;

data os2 (keep=reg optionname d3);

set Step37p;

Page 33
if ord=2;

rename ps=d3;

label d3="3% Discount Rate (thousands 2011$)";

run;

data os3 (keep=reg optionname d7);

set Step37p;

if ord=3;

rename ps=d7;

label d3="7% Discount Rate (thousands 2011$)";

run;

proc sort data=os1; by reg optionname; run;

proc sort data=os2; by reg optionname; run;

proc sort data=os3; by reg optionname; run;

data os4;

merge os1 os2 os3;

by reg optionname;

%optionmac2a;

run;

proc sort data=os4; by reg sortx; run;

*generate datasets for species-option-specific tables;

*List of regions;

%let reglist=

California^North Atlantic^Mid-Atlantic^South Atlantic^Gulf of Mexico^Great Lakes;

*List of possible table numbers;

%let numlist=

01 02 03 04 05 06 07 08 09 10

11 12 13 14 15 16 17 18 19 20

21 22 23 24 25 26 27 28 29 30

31 32 33 34 35 36 37 38 39 40

41 42 43 44 45 46 47 48 49 50

51 52 53 54 55 56 57 58 59 60

61 62 63 64 65 66 67 68 69 70

71 72 73 74 75 76 77 78 79 80

81 82 83 84 85 86 87 88 89 90

91 92 93 94 95 96 97 98 99 100

101 102 103 104 105 106 107 108 109 110

111 112 113 114 115 116 117 118 119 120

121 122 123 124 125 126 127 128 129 130

131 132 133 134 135 136 137 138 139 140

141 142 143 144 145 146 147 148 149 150

151 152 153 154 155 156 157 158 159 160

161 162 163 164 165 166 167 168 169 170

171 172 173 174 175 176 177 178 179 180

181 182 183 184 185 186 187 188 189 190

191 192 193 194 195 196 197 198 199 200

201 202 203 204 205 206 207 208 209 210

211 212 213 214 215 216 217 218 219 220

221 222 223 224 225 226 227 228 229 230

231 232 233 234 235 236 237 238 239 240

241 242 243 244 245 246 247 248 249 250;

%macro SStables(start,by);

%do j=1 %to &speciesnum.; /*Number of Options*/

%do i=1 %to 6; /*Six Regions*/

%let T=%eval(&start+&j-1+&by*(&i-1));

Data Table_X_%scan(&numlist,&T.);

length Table $40.;

set Step37p;

Table="Table

&T.:%scan(&speciesoptions.,&j,^):%scan(®list,&i,^)";

if

optionname="%scan(&speciesoptions.,&j,^)";

if

reg="%scan(®list,&i,^)";

run;

%end;

Page 34
%end;

%mend;

%SSTables(start=&firsttable.,by=&nby.);

*generate datasets for option-specific summary tables;

*get annualized data ;

proc sql;

create table sum1 as select

optionname label="Name of Option",

region,re,lossmode,

sum(CS)/1000 as CS label="Change in Consumer Surplus

(Undiscounted) (thousands 2011$)" format=dollar30.1,

sum(PS)/1000 as PS label="Change in Producer Surplus

(Undiscounted) (thousands 2011$)" format=dollar30.1,

sum(TS)/1000 as TS label="Change in Total Surplus (Undiscounted)

(thousands 2011$)" format=dollar30.1,

sum(CS3)/1000 as CS3 label="Change in Consumer Surplus (3%)

(thousands 2011$)" format=dollar30.1,

sum(PS3)/1000 as PS3 label="Change in Producer Surplus (3%)

(thousands 2011$)" format=dollar30.1,

sum(TS3)/1000 as TS3 label="Change in Total Surplus (3%)

(thousands 2011$)" format=dollar30.1,

sum(CS7)/1000 as CS7 label="Change in Consumer Surplus (7%)

(thousands 2011$)" format=dollar30.1,

sum(PS7)/1000 as PS7 label="Change in Producer Surplus (7%)

(thousands 2011$)" format=dollar30.1,

sum(TS7)/1000 as TS7 label="Change in Total Surplus (7%)

(thousands 2011$)" format=dollar30.1

from step7data

where year=16

group by optionname,region,re,lossmode

order by optionname,region,re,lossmode;

quit;

*get row-specific data for tables;

%macro sumtables(r,v);

data row&r.imp (keep=optionname region re Imp) row&r.ent (keep=optionname region

re Ent);

set sum1;

Imp=&v.;

Ent=&v.;

if lossmode="imp" then output row&r.imp;

else if lossmode="ent" then output row&r.ent;

run;

proc sql;

create table x&r. as select

&r as row,

i.optionname as ioptionname,i.re as ire,

e.optionname as eoptionname,e.re as ere,

i.imp,

e.ent,

sum(i.imp,e.ent) as iande

from row&r.imp as i full join row&r.ent as e

on i.optionname=e.optionname and

i.re=e.re;

quit;

data row&r.;

set x&r.;

if ioptionname~=" " then optionname=ioptionname;

else optionname=eoptionname;

if ire~=" " then re=ire;

else re=ere;

%mend;

%sumtables(1,CS);

%sumtables(2,PS);

%sumtables(3,TS);

%sumtables(4,TS3);

%sumtables(5,TS7);

Page 35
*combine rows into one table;

data sum2;

set row1 row2 row3 row4 row5;

run;

proc sort data=sum2 out=sum3; by re optionname row; run;

*generate option-specific table data;

%macro summarybyoption(base,opt,oname);

data baseline option ;

set sum3;

if optionname="&base." then output baseline;

else if optionname="&opt." and row in (3,4,5) then output option;

run;

proc sql;

create table sum4 as select

o.re,7 as row,

o.imp/b.imp as imp,

o.ent/b.ent as ent,

o.iande/b.iande as iande

from baseline as b left join option as o

on b.re = o.re and

b.row = o.row

where o.row=3;

quit;

data option2;

set option;

row=row+5;

run;

data sum5;

length rowname $80;

set baseline sum4 option2;

if row=1 then rowname="Baseline Consumer Surplus

Lost (Undiscounted)";

else if row=2 then rowname="Baseline Producer Surplus Lost

(Undiscounted)";

else if row=3 then rowname="Baseline Welfare Loss

(Undiscounted)";

else if row=4 then rowname="Baseline Welfare Loss (3%

discount)";

else if row=5 then rowname="Baseline Welfare Loss (7%

discount)";

else if row=7 then rowname="% Reduction in Total Losses From

Rule";

else if row=8 then rowname="Welfare Gain (Undiscounted)";

else if row=9 then rowname="Welfare Gain (3% Discount)";

else if row=10 then rowname="Welfare Gain (7% Discount)";

label

re ="region (short)"

row ="Row Number"

imp ="Imingement"

ent ="Entrainment"

iande ="Total";

format imp ent iande comma30.1;

Option="&oname";

run;

proc sort data=sum5 out=&oname; by re row; run;

%mend;

%optionmac3;

%let relist=

CA^NA^MA^GM^GL^SA;

*generate option-specific tables;

%macro sumtables(start,by);

Page 36
%do j=1 %to &rnum.; *number of options;

%do i=1 %to 6; *6 regions;

%let t=%eval(&start+&j-1+&by*(&i-1));

Data Table_X_%scan(&numlist,&T.);

retain rowname imp ent iande;

set %scan(®ionoptions,&j,^);

if re="%scan(&relist,&i,^)";

run;

%end;

%end;

%mend;

*%sumtables(7,&nby);

%sumtables(%eval(&firsttable+&speciesnum),&nby);

*Export data to excel;

%export(step1data,"&outloc.&output",step1data);

%export(step2data,"&outloc.&output",step2data);

%export(step3data,"&outloc.&output",step3data);

%export(step4data,"&outloc.&output",step4data);

%export(step5data,"&outloc.&output",step5data);

%export(step6data,"&outloc.&output",step6data);

%export(step8data,"&outloc.&output",step8data);

%export(step9data,"&outloc.&output",step9data);

*Generate National Total Tables;

proc sql;

create table nat1 as select

row,optionname,

"TL" as re,

case

when row=3 or row=8 then "Undiscounted"

when row=4 or row=9 then "3 Percent"

when row=5 or row=10 then "7 Percent"

else "Delete"

end as Discount,

sum(imp) as imp,

sum(ent) as ent,

sum(iande) as iande

from sum3 group by row,optionname;

create table nat2 as select

row,optionname,re,

case

when row=3 or row=8 then "Undiscounted"

when row=4 or row=9 then "3 Percent"

when row=5 or row=10 then "7 Percent"

else "Delete"

end as Discount,

sum(imp) as imp,

sum(ent) as ent,

sum(iande) as iande

from sum3 group by row,optionname,re;

quit;

*drop irrelevent rows, format data;

data nat3 (keep=optionname region imp ent iande discount s row) ;

retain optionname discount region imp ent iande s row;

length region $30.;

set nat2 nat1;

if discount~="Delete";

if re="CA" then

region="California";

else if re="GL" then region="Great Lakes";

else if re="GM" then region="Gulf of Mexico";

else if re="MA" then region="Mid-Atlantic";

else if re="NA" then region="North Atlantic";

else if re="SA" then region="South Atlantic";

else if re="TL" then region="National Total";

Page 37
if re="CA" then s=1;

else if re="GL" then s=6;

else if re="GM" then s=5;

else if re="MA" then s=3;

else if re="NA" then s=2;

else if re="SA" then s=4;

else if re="TL" then s=7;

format imp ent iande dollar30.1;

label region="Region"

imp="Impingement"

ent="Entrainment"

iande='I&E'

discount="Discount Rate";

run;

*sort data;

proc sort data=nat3 out=nat4; by optionname row s; run;

*insert blank rows;

data blank;

set nat4;

by optionname row;

if first.row;

region="Blank Row";

imp=.;

ent=.;

iande=.;

s=0;

run;

data nat5;

set nat4 blank;

run;

*sort for printing;

proc sort data=nat5 out=nat6; by optionname row s; run;

*generate national total option-specific tables;

%macro nattables(start);

%do j=1 %to &natnum.;

%let t=%eval(&start+&j-1);

Data Table_X_&t.;

set nat6;

if

optionname="%scan(&natoptions,&j,^)";

run;

%end;

%mend;

%nattables(%eval(&firsttable+&nby*6));

*PRINT REGION TABLES;

%macro printit(var,var2);

%do j=1 %to 6; /*Regions 1 - 6*/

%let region=%scan(®list,&j,^);

%let countlist=0^1^2^3^4^5;

%do i=1 %to &nby.; /*13 Tables Per Region FLAG OPTION-SPECIFIC

STEP!!*/

%if &i<=&speciesnum. %then %do; /*5 species tables per

region FLAG OPTION-SPECIFIC STEP!!*/

Title;

*Title1 "Table

%scan(&numlist,(&j-1)*&nby+&firsttable+&i-1)A : Imp, Ent, and I&E";

Title1 "Table

%eval(%scan(&numlist,((&j-1)*4+&i)*2-1+&firsttable-1)+%scan(&countlist,&j,^)) :

Imp, Ent, and I&E";

Page 38
Title2 "®ion : Option =

%scan(&TableTitles,&i,^)";

proc print

data=Table_X_%scan(&numlist,(&j-1)*&nby+&firsttable+&i-1) noobs label;

var &var. species pounds_i pounds_e

pounds_ie

;

where species~="Total (3% Discount

Rate)" and

species~="Total (7%

Discount Rate)";

run;

*Title1 "Table

%scan(&numlist,(&j-1)*&nby+&firsttable+&i-1)B : Econ Tables:";

Title1 "Table

%eval(%scan(&numlist,((&j-1)*4+&i)*2+&firsttable-1)+%scan(&countlist,&j,^)) :

Econ Tables:";

Title2 "®ion : Option =

%scan(&TableTitles,&i,^)";

proc print

data=Table_X_%scan(&numlist,(&j-1)*&nby+&firsttable+&i-1) noobs label;

var &var. species oldlbs price2011

pounds_ie PS;

run;

%end;

%if &i=5 %then %do; /*option tables per region FLAG

OPTION-SPECIFIC STEP!!*/

Title;

Title1 "Table

%eval(%scan(&numlist,((&j-1)*4+&i)*2+&firsttable-1)+%scan(&countlist,&j,^)-1) :

Option Summary:";

Title2 "®ion";

proc print data=os4;

where reg="®ion";

run;

%end;

%end;

%end;

%mend;

*code for discounting appendix;

Data Discounting_out;

set step7data;

if optionname="baseline_0" then delete;

if optionname="tmn1_0" then delete;

if optionname="tmn2_0" then delete;

if optionname="tmn3_0" then delete;

drop re cfspecies rbschd price elasticity ABT_NB_Ratio percent IEchange

oldlbs lbs price2011 dollars2011 GR CS TS CS3 CS7 TS3 TS7;

RUN;

*merge regional producer surplus across all commercial species;

Proc sql;

create table discounting_out_reg as select

optionname,

region,

year,

sum(PS) as totPS format=dollar30.0,

sum(PS3) as totPS3 format=dollar30.0,

sum(PS7) as totPS7 format=dollar30.0

from discounting_out group by optionname, region, year;

quit;

*merge national producer surplus across all commercial species;

Proc sql;

create table discounting_out_nat as select

optionname,

year,

sum(PS) as totPS format=dollar30.0,

Page 39
sum(PS3) as totPS3 format=dollar30.0,

sum(PS7) as totPS7 format=dollar30.0

from discounting_out group by optionname, year;

quit;

*use national values to create a summary for each option;

Data discounting_out_tmn1;

set discounting_out_nat;

if optionname~="tmn1" then delete;

if year=61 then delete;

if year=62 then delete;

RUN;

Data discounting_out_tmn2;

set discounting_out_nat;

if optionname~="tmn2" then delete;

if year=61 then delete;

if year=62 then delete;

RUN;

Data discounting_out_tmn3;

set discounting_out_nat;

if optionname~="tmn3" then delete;

if year=61 then delete;

if year=62 then delete;

RUN;

%export(discounting_out_nat,"&outloc.&output.",discounting_out_nat)

%export(discounting_out_tmn1,"&outloc.&output.",discounting_out_tmn1)

%export(discounting_out_tmn2,"&outloc.&output.",discounting_out_tmn2)

%export(discounting_out_tmn3,"&outloc.&output.",discounting_out_tmn3)

*create a large summary table for export;

Data summary_by_species;

set

Table_x_08 Table_x_09 Table_x_10 Table_x_11

Table_x_15 Table_x_16 Table_x_17 Table_x_18

Table_x_22 Table_x_23 Table_x_24 Table_x_25

Table_x_29 Table_x_30 Table_x_31 Table_x_32

Table_x_36 Table_x_37 Table_x_38 Table_x_39

Table_x_43 Table_x_44 Table_x_45 Table_x_46;

drop elasticity cs ord;

RUN;

%export(summary_by_species,"&outloc.&output.",summary_by_species)

Data IE_breakdown;

set step7data;

if year<62 then delete;

keep optionname region lossmode species_econ year PS_peak;

RUN;

proc sql;

create table IE_breakdown_1 as select

optionname,

region,

lossmode,

sum(PS_peak) as PS_peak_by_lossmode

from IE_breakdown group by optionname, region, lossmode;

quit;

proc sql;

create table IE_breakdown_2 as select

optionname,

region,

lossmode,

PS_peak_by_lossmode,

sum(PS_peak_by_lossmode) as PS_peak_tot

from IE_breakdown_1 group by optionname, region;

quit;

Data PS_percent;

set ie_breakdown_2;

if lossmode="ent" then ent_PS_percent=PS_peak_by_lossmode/PS_peak_tot;

if lossmode~="ent" then ent_PS_percent=0;

if lossmode="imp" then imp_PS_percent=PS_peak_by_lossmode/PS_peak_tot;

Page 40
if lossmode~="imp" then imp_PS_percent=0;

drop lossmode PS_peak_by_lossmode PS_peak_tot;

RUN;

proc sql;

create table PS_percent as select

optionname,

region,

sum(ent_PS_percent) as ent_PS_percent,

sum(imp_PS_percent) as imp_PS_percent

from PS_percent group by optionname, region;

quit;

Data PS_peak;

set Step8data;

keep optionname region re PS_peak;

RUN;

proc sql;

create table PS_peak_2 as select

a.*,

b.*

from PS_peak as a left join PS_percent as b

on a.optionname=b.optionname and a.region=b.region;

quit;

Data PS_peak_3;

set PS_peak_2;

PS_peak_ent=PS_peak*ent_PS_percent;

PS_peak_imp=PS_peak*imp_PS_percent;

drop ent_PS_percent imp_PS_percent;

format PS_peak_ent DOLLAR30.1;

format PS_peak_imp DOLLAR30.1;

RUN;

*export a summary tables of peak benefits (undiscounted over the compliance

period) - standard undiscounted value is an average;

%export(PS_peak_3,"&outloc.&output.",PS_peak)

Page 41