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

**

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

** Split-Sample Ext Val Test Code_Opt_12.12.12.sas *Author: Ryan Stapler, Abt Associates Inc. Created: 11/2/12 Updated: 12/12/12; *Purpose: This a SAS program that runs split-sample external validity tests on the 316(b) stated preference survey data with data split by option.

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

**

********************************************************************************* **; *specify input and output files; %let d=s; *(C or H drive); %let mainloc=&d.:\Projects\Tyche\WA 4-05 (316b)\316b Survey\; %let scopeloc=&mainloc.scope tests\; %let survey_data=all_reg_model_data_w_wgts_071112.xls; %let outfile=chisq_tests_for_external_scope_&sysdate.;

*define import and export macros; %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 export(datafile,outfile,sheet); PROC EXPORT DATA= &datafile

OUTFILE= &outfile DBMS=EXCEL replace; SHEET=&sheet;
RUN; %mend;

%import(&mainloc.&survey_data.,all_models_w_wghts,survey_data);

*Fish Saved levels for each region Northeast 95%, 50%, 5% Southeast 90%, 55%, 25% Pacific 95%, 50%, 2% Inland 95%, 75%, 55% National 95%, 55%, 25%;

*Region #'s 1=Northeast 2=Southeast 3=Inland 4=Pacific 5=National;

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

********** Run tests split by option

********************************************************************************* **********; %macro chisq_across_opts(r,p,n); *region, percent, and number; Proc sql; create table &r._&p. as select region, option, mean(fish_save) as fish_save, Page 1sum(choice) as yes,

count(choice) as sample, mean(choice) as choice_mean, std(choice) as choice_std, mean(com_fish) as com_fish_mean, std(com_fish) as com_fish_std, mean(fish_pop) as fish_pop_mean, std(fish_pop) as fish_pop_std, mean(aquatic) as aquatic_mean, std(aquatic) as aquatic_std, mean(cost) as cost_mean, std(cost) as cost_std from survey_data where region=&n. and fish_save=&p. and response >=0 group by option, region; quit; Data &r._&p.x1; set &r._&p.; no=sample-yes; keep option yes no;
RUN; proc transpose data=&r._&p.x1 out=&r._&p.x1; by option;
RUN; Data &r._&p.x1; set &r._&p.x1; rename _NAME_=choice col1=count; label choice=choice count=count;
RUN; proc freq data=&r._&p.x1 order=data; weight count; table option*choice/ chisq; output out=&r._&p.x2 pchi;
RUN; Data &r._&p.x2; format region_num 1.; format region $20.; format fish_save 2.; set &r._&p.x2; fish_save=&p.; region_num=&n.; region="&r."; format significance $3.; if P_PCHI le 0.10 then do significance="*"; end; if P_PCHI le 0.05 then do significance="**"; end; if P_PCHI le 0.01 then do significance="***"; end;
RUN; %mend; %chisq_across_opts(Northeast,95,1); %chisq_across_opts(Northeast,50,1); %chisq_across_opts(Northeast,5,1);

%chisq_across_opts(Southeast,90,2); %chisq_across_opts(Southeast,55,2); %chisq_across_opts(Southeast,25,2);

%chisq_across_opts(Inland,95,3); %chisq_across_opts(Inland,75,3); %chisq_across_opts(Inland,55,3);

%chisq_across_opts(Pacific,95,4); %chisq_across_opts(Pacific,50,4); %chisq_across_opts(Pacific,2,4);

%chisq_across_opts(National,95,5); %chisq_across_opts(National,55,5); %chisq_across_opts(National,25,5);

Data chisq_results_across_opts; Page 2set

Northeast_95x2 Northeast_50x2 Northeast_5x2 Southeast_90x2 Southeast_55x2 Southeast_25x2 Inland_95x2 Inland_75x2 Inland_55x2 Pacific_95x2 Pacific_50x2 Pacific_2x2 National_95x2 National_55x2 National_25x2;
RUN;

*Northeast 95%, 50%, 5% Southeast 90%, 55%, 25% Pacific 95%, 50%, 2% Inland 95%, 75%, 55% National 95%, 55%, 25%;

*Region #'s 1=Northeast 2=Southeast 3=Inland 4=Pacific 5=National;

*********************************************************** Testing within options for differences ***********************************************************; %macro chisq_within_opts(r,p1,p2,p3); Data &r._&p1.x1x; set &r._&p1.x1; fish_save=&p1.;RUN; Data &r._&p2.x1x; set &r._&p2.x1; fish_save=&p2.; RUN; Data &r._&p3.x1x; set &r._&p3.x1; fish_save=&p3.; RUN; Data &r._allper; set &r._&p1.x1x &r._&p2.x1x &r._&p3.x1x;
RUN; Data &r._allper_Opt1; set &r._allper; if option~=1 then delete; drop option;
RUN; proc freq data=&r._allper_Opt1 order=data; weight count; table fish_save*choice/ chisq; output out=&r._allper_Opt1x pchi;
RUN; Data &r._allper_Opt2; set &r._allper; if option~=2 then delete; drop option;
RUN; proc freq data=&r._allper_Opt2 order=data; weight count; table fish_save*choice/ chisq; output out=&r._allper_Opt2x pchi;
RUN; Data &r._allper_Opt1x; format region $20.; format option 1.; set &r._allper_Opt1x; option=1; region="&r."; format significance $3.; if P_PCHI le 0.10 then do significance="*"; end; if P_PCHI le 0.05 then do significance="**"; end; if P_PCHI le 0.01 then do significance="***"; end;
RUN;

Data &r._allper_Opt2x; format region $20.; format option 1.; set &r._allper_Opt2x; option=2; region="&r."; Page 3format significance $3.;

if P_PCHI le 0.10 then do significance="*"; end; if P_PCHI le 0.05 then do significance="**"; end; if P_PCHI le 0.01 then do significance="***"; end;
RUN; %mend; %chisq_within_opts(Northeast,95,50,5); %chisq_within_opts(Southeast,90,55,25); %chisq_within_opts(Pacific,95,50,2); %chisq_within_opts(Inland,95,75,55); %chisq_within_opts(National,95,55,25);

Data chisq_results_within_opts;

Set Northeast_allper_Opt1x Northeast_allper_Opt2x Southeast_allper_Opt1x Southeast_allper_Opt2x Pacific_allper_Opt1x Pacific_allper_Opt2x Inland_allper_Opt1x Inland_allper_Opt2x National_allper_Opt1x National_allper_Opt2x;
RUN;

Data mean_and_stdev; format reg $10.;

set Northeast_5 Northeast_50 Northeast_95 Southeast_25 Southeast_55 Southeast_90 Pacific_2 Pacific_50 Pacific_95 Inland_55 Inland_75 Inland_95 National_25 National_55 National_95; *Region #'s 1=Northeast 2=Southeast 3=Inland 4=Pacific 5=National; if region=1 then do reg="Northeast"; end; if region=2 then do reg="Southeast"; end; if region=3 then do reg="Pacific"; end; if region=4 then do reg="Inland"; end; if region=5 then do reg="National"; end;
RUN;

*export results for tests based on all questions;; %export(chisq_results_within_opts,&outfile.,within_opts); %export(mean_and_stdev,&outfile.,mean_and_stdev);

Page 4