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

**

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

**

*Author: Ryan Stapler, Abt Associates Inc.

*Created: 2/5/10;

*Updated: 7/5/12;

*Purpose: This a SAS program thats runs statistical tests comparing the

characteristics of respondents to the 316(b) stated preference (SP) survey to

survey non-respondents. Tests include the Student T-test, Mann-Whitney U Test

(Wilcoxon Test), and Chi-Squared Test of Proportions. Results were used in

developing model weights.

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

**

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

**;

*Note: main survey and non-response data are imported below from separate excel

files.

These datasets are in a single excel file in the rulemaking docket;

*import the spreadsheet of mail survey data;

PROC IMPORT DBMS=excelcs REPLACE

DATAFILE= "S:\Projects\Tyche\WA 4-05 (316b)\316b

Survey\mail_survey_data_052312.xls"

OUT= WORK.mail_survey;

SHEET="mail_survey_data_052312";

RUN;

*import the nonresponse data for all regions;

PROC IMPORT DBMS=excelcs REPLACE

DATAFILE= "S:\Projects\Tyche\WA 4-05 (316b)\316b Survey\nonresponse

testing\nonresponse_data_060712.xls"

OUT= WORK.Nonresponse;

RUN;

*import the nonresponse data for the Northeast;

PROC IMPORT DBMS=excelcs REPLACE

DATAFILE= "S:\Projects\Tyche\WA 4-05 (316b)\316b Survey\nonresponse

testing\Northeast_NR_data_07.05.12rws.xls"

OUT= WORK.Nonresponse_NE;

RUN;

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

*edit the mail survey to that it can compared to the non-response data;

*change missing values to "";

Data mail_survey_1;

set mail_survey;

%macro rep_9(q); if &q.=9 or &q.="" then do &q.=".";end;%mend;

%macro rep_99(q); if &q.=99 or &q.="" then do &q.=".";end;%mend;

%macro rep_999(q); if &q.=999 or &q.="" then do &q.=".";end;%mend;

%macro rep_9999(q); if &q.=9999 or &q.=99999 or &q.="" then do &q.=".";end;%mend;

%rep_9(q1_1);%rep_9(q1_2);%rep_9(q1_3);%rep_9(q1_4);%rep_9(q1_5);%rep_9(q1_6);%re

p_9(q2);

%rep_9(q3_1);%rep_9(q3_2);%rep_9(q3_3);%rep_9(q3_4);%rep_9(q3_5);

%rep_9(q4);%rep_9(q5);%rep_9(q6);

%rep_9(q7_1);%rep_9(q7_2);%rep_9(q7_3);%rep_9(q7_4);%rep_9(q7_5);%rep_9(q7_6);

%rep_9(q8_1);%rep_9(q8_2);%rep_9(q8_3);%rep_9(q8_4);%rep_9(q8_5);%rep_9(q8_6);%re

p_9(q8_7);%rep_9(q8_8);

%rep_9(q9_1);%rep_9(q9_2);%rep_9(q9_3);%rep_9(q9_4);%rep_9(q9_5);%rep_9(q9_6);%re

p_9(q9_7);%rep_9(q9_8);%rep_9(q9_9);%rep_9(q9_10);%rep_9(q9_11);

%rep_9(q10_1);%rep_9(q10_2);%rep_9(q10_3);%rep_9(q10_4);%rep_9(q10_5);%rep_9(q10_

6); %rep_9(q11_1); %rep_9(q11_2);

%rep_999(q12);%rep_9(q13);%rep_9(q14);%rep_99(q15);%rep_99(q16);%rep_99(q17);%rep

_9999(q18_1);%rep_9999(q18_2);%rep_9(q19);%rep_9(q20);%rep_9(q21);

%rep_9(q22_1);%rep_9(q22_2);%rep_9(q22_3); %rep_99(q23);

RUN;

Data mail_survey_1;

set mail_survey_1;

keep ID Region version q2 q12 q13 q14 q19 q21 q22_1 q22_2 q22_3 q22_4 q22_5 q23;

RUN;

Page 1
*format and convert any character variables to numeric;

Data mail_survey_1;

set mail_survey_1;

if q23=99 or q23=98 or q23=97 then do q23=""; end;

RUN;

*combine race into a single field within the mail survey data;

data mail_survey_2; set mail_survey_1;

*reformat the race question such that they are dummy variables;

if q22_1=1 then q22d_1=1; *d stands for dummy;

if q22_2=2 then q22d_2=1;

if q22_3=3 then q22d_3=1;

if q22_4=4 then q22d_4=1;

if q22_5=5 then q22d_5=1;

sumd=sum(of q22d_1-q22d_5); *this is the sum of the dummies - indicates how many

race boxes were checked;

sumrace=sum(of q22_1-q22_5); *this is the sum of the race values;

*define variables for race for hypothesis testing;

if sumd=. then race=.;

if sumd=1 then race=sumrace;

if sumd>1 then race=6;

if q22d_5=1 and sumd=1 then race_minor=2;

if q22d_5=1 and sumd>1 then race_minor=1;

if q22d_5=. and sumd~=. then race_minor=1;

if sumd=. then race_minor=.;

sample="main";

RUN;

data mail_survey_2qa; set mail_survey_2;

if race_minor~=. then race_m=1;

keep region race_m;

RUN;

proc sql;

create table mail_survey_2qa as select

region,

sum(race_m) as race_msum

from mail_survey_2qa group by region;

quit;

Data mail_survey_3; set mail_survey_2;

age=q12;

gender=q13;

education=q14;

employ=q19;

aquatic=q2;

hisp=q21;

income=q23;

if income = . then income_lt60k=.;

else if income = 1 or income =2 or income = 3 or income =4

then income_lt60k=1;

else income_lt60k=0;

drop q12 q13 q14 q19 q2 q21 q23

q22_1 q22_2 q22_3 q22_4 q22_5

sum version;

RUN;

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

*Edit the non-response survey data so that it compared to the mail survey;

Data nonresponse_ne;

set nonresponse_ne;

idcombx=input(idcomb,8.);

q16cmb_3x=input(q16cmb_3,1.);

q16cmb_4x=input(q16cmb_4,1.);

q16cmb_6x=input(q16cmb_6,1.);

q16cmb_7x=input(q16cmb_7,1.);

q16cmb_8x=input(q16cmb_8,1.);

drop idcomb q16cmb_3 q16cmb_4 16cmb_6 16cmb_7 16cmb_8;

rename idcombx=idcomb

q16cmb_3x=q16cmb_3 q16cmb_4x=q16cmb_4

q16cmb_4x=q16cmb_6 q16cmb_4x=q16cmb_7 q16cmb_4x=q16cmb_8;

RUN;

data nonresponse; set nonresponse;

Data nonresponse;

Page 2
set nonresponse nonresponse_ne;

RUN;

data nonresponse;

set nonresponse;

if q1comb=99 or q1comb=98 then do q1comb=""; end;

if q2comb=8 or q2comb=9 then do q2comb=""; end;

if q8comb=8 or q8comb=9 then do q8comb=""; end;

if q10comb=8 or q10comb=9 then do q10comb=""; end;

if q15comb=8 or q15comb=9 then do q15comb=""; end;

if q18comb=99 or q18comb=98 or q18comb=97 then do q18comb=""; end;

drop q16cmb_6 q16cmb_7 q16cmb_8;

RUN;

*keep only those variables that are being tested;

Data nonresponse_1;

set nonresponse;

keep

regioncomb idcomb q1comb q2comb q3comb q8comb q10comb q15comb q16cmb_1 q16cmb_2

q16cmb_3 q16cmb_4 q16cmb_5 q18comb;

RUN;

*combine race into a single field within the nonresponse data;

Data nonresponse_2; set nonresponse_1;

if q16cmb_1=1 then q16cmbd_1=1; *d stands for dummy;

if q16cmb_2=2 then q16cmbd_2=1;

if q16cmb_3=3 then q16cmbd_3=1;

if q16cmb_4=4 then q16cmbd_4=1;

if q16cmb_5=5 then q16cmbd_5=1;

sumd=sum(of q16cmbd_1-q16cmbd_5); *this is the sum of the dummies - indicates how

many race boxes were checked;

sumrace=sum(of q16cmb_1-q16cmb_5); *this is the sum of the race values;

*define variables for race for hypothesis testing;

if sumd=. then race=.;

if sumd=1 then race=sumrace;

if sumd>1 then race=6;

if q16cmbd_5=1 and sumd=1 then race_minor=2;

if q16cmbd_5=1 and sumd>1 then race_minor=1;

if q16cmbd_5=. and sumd~=. then race_minor=1;

if sumd=. then race_minor=.;

sample="nonresponse";

RUN;

data nonresponse_2qa; set nonresponse_2;

if race_minor~=. then race_m=1;

keep regioncomb race_m;

RUN;

proc sql;

create table nonresponse_2qa as select

regioncomb,

sum(race_m) as race_msum

from nonresponse_2qa group by regioncomb;

quit;

Data nonresponse_3; set nonresponse_2;

age=q1comb;

gender=q2comb;

education=q3comb;

employ=q8comb;

aquatic=q10comb;

hisp=q15comb;

income=q18comb;

region=regioncomb;

id=idcomb;

if income = . then income_lt60k=.;

else if income = 1 or income =2 or income = 3 or income =4

then income_lt60k=1;

else income_lt60k=0;

drop q1comb q2comb q3comb q8comb q10comb q15comb q18comb

q16cmb_1 q16cmb_2 q16cmb_3 q16cmb_4 q16cmb_5

regioncomb idcomb sum;

RUN;

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

Page 3
*Combine the mail survey and non-rsponse survey datasets;

Data Data_combined;

set nonresponse_3 mail_survey_3;

RUN;

*add a summary of race as a QA;

Data data_combined_QA;

set data_combined;

if race_minor>=1 then race_QA=1;

RUN;

proc sql;

create table data_combined_QA as select

a.*,

sum(race_QA) as race_QA_sum

from data_combined_QA as a group by region, sample;

quit;

proc sort data=data_combined_QA out=data_combined_QA nodupkey;

by region sample;

RUN;

data data_combined_QA; set data_combined_QA; keep region sample race_QA_sum;

RUN;

*generate separate data sets for each region;

Data Data_national;

set data_combined;

if region~=5 then delete;

RUN;

Data Data_southeast;

set data_combined;

if region~=2 then delete;

RUN;

Data data_inland;

set data_combined;

if region~=3 then delete;

RUN;

Data data_pacific;

set data_combined;

if region~=4 then delete;

RUN;

Data data_northeast;

set data_combined;

if region~=1 then delete;

RUN;

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

START HYPOTHESIS TESTING

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

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

*RUN T-test for Age;

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

%macro ttest(reg,var);

proc ttest data = data_®.;

class sample;

var &var.;

run;

%mend;

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

RUN mann-whitney U tests for multiple categorical variables;

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

%macro wilc(reg,var);

PROC NPAR1WAY data=data_®. wilcoxon;

Class sample;

Var &var.;

*Exact; *OPTIONAL;

Run;

%mend;

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

RUN Chi-sq tests for multiple categorical variables

>if there aren't enough obervations in a category it may be

Page 4
necessary

to use results from fisher exact test rather chi-sq test

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

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

RUN Chi-sq test for gender

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

%macro chisq_gender(reg);

proc sql; create table ®._gender as select

sample,gender,count(gender) as count

from data_®. group by sample,gender;

quit;

proc sort data=®._gender out=®._gender nodupkey;

by sample gender; RUN;

Data ®._gender; set ®._gender;

if gender="." then delete;

if gender=2 then genderx="female";

if gender=1 then genderx="male";

drop gender; rename genderx=gender;

RUN;

proc freq data=®._gender order=data;

weight count;

table sample * gender / chisq;

RUN;

%mend;

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

RUN Chi-sq test for employment

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

%macro chisq_employ(reg);

proc sql; create table ®._employ as select

sample,employ,count(employ) as count

from data_®. group by sample,employ;

quit;

proc sort data=®._employ out=®._employ nodupkey;

by sample employ; RUN;

Data ®._employ; set ®._employ;

if employ="." then delete;

if employ=2 then employx="unemployed";

if employ=1 then employx="employed";

drop employ; rename employx=employ;

RUN;

proc freq data=®._employ order=data;

weight count;

table sample * employ / chisq;

RUN;

%mend;

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

RUN Chi-sq test for hispanic or latino origin

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

%macro chisq_hisp(reg);

proc sql; create table ®._hisp as select

sample,hisp,count(hisp) as count

from data_®. group by sample,hisp;

quit;

proc sort data=®._hisp out=®._hisp nodupkey;

by sample hisp; RUN;

Data ®._hisp; set ®._hisp;

if hisp="." then delete;

if hisp=2 then hispx="nothispanic";

if hisp=1 then hispx="hispanic";

drop hisp; rename hispx=hisp;

RUN;

proc freq data=®._hisp order=data;

weight count;

table sample * hisp / chisq;

RUN;

%mend;

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

Page 5
RUN Chi-sq test for race(minority/non-white)

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

%macro chisq_race_minor(reg);

proc sql; create table ®._race_minor as select

sample,race_minor,count(race_minor) as count

from data_®. group by sample,race_minor;

quit;

proc sort data=®._race_minor out=®._race_minor nodupkey;

by sample race_minor; RUN;

Data ®._race_minor; set ®._race_minor;

if race_minor="." then delete;

if race_minor=2 then race_minorx="white";

if race_minor=1 then race_minorx="minority";

drop race_minor; rename race_minorx=race_minor;

RUN;

proc freq data=®._race_minor order=data;

weight count;

table sample * race_minor / chisq;

RUN;

%mend;

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

RUN Chi-sq test for educational attainment

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

%macro chisq_edu(reg);

proc sql; create table ®._education as select

sample,education,count(education) as count

from data_®. group by sample,education;

quit;

proc sort data=®._education out=®._education nodupkey;

by sample education; RUN;

Data ®._education; set ®._education;

if education="." then delete;

RUN;

proc freq data=®._education order=data;

weight count;

table sample * education / chisq;

RUN;

%mend;

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

RUN Chi-sq test for importance of aquatic ecosystems

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

%macro chisq_aquatic(reg);

proc sql; create table ®._aquatic as select

sample,aquatic,count(aquatic) as count

from data_®. group by sample,aquatic;

quit;

proc sort data=®._aquatic out=®._aquatic nodupkey;

by sample aquatic; RUN;

Data ®._aquatic; set ®._aquatic;

if aquatic="." then delete;

RUN;

proc freq data=®._aquatic order=data;

weight count;

table sample * aquatic / chisq;

RUN;

%mend;

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

RUN Fishers exact test for education

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

%macro chisq_f_edu(reg);

proc sql; create table ®._edu as select

sample,education,count(education) as count

from data_®. group by sample,education;

quit;

proc sort data=®._edu out=®._edu nodupkey;

by sample education; RUN;

Data ®._edu; set ®._edu;

if education="." then delete;

RUN;

Page 6
proc freq data=®._edu order=data;

weight count;

table sample * education / fisher;

RUN;

%mend;

proc sql; create table northeast_edu as select

sample,education,count(education) as count

from data_northeast group by sample,education;

quit;

proc sort data=northeast_edu out=northeast_edu nodupkey;

by sample education; RUN;

Data northeast_edu; set northeast_edu;

if education="." then delete;

RUN;

proc freq data=northeast_edu order=data;

weight count;

table sample * education / fisher;

RUN;

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

RUN Chi-sq test for household income lt 60k

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

%macro chisq_income_lt60k(reg);

proc sql; create table ®._income_lt60k as select

sample,income_lt60k,count(income_lt60k) as count

from data_®. group by sample,income_lt60k;

quit;

proc sort data=®._income_lt60k out=®._income_lt60k nodupkey;

by sample income_lt60k; RUN;

Data ®._income_lt60k; set ®._income_lt60k;

if income_lt60k="." then delete;

RUN;

proc freq data=®._income_lt60k order=data;

weight count;

table sample * income_lt60k / chisq;

RUN;

%mend;

*group hyp tests by region;

*national;

%ttest(national,age);

%wilc(national,gender); %wilc(national,employ); %wilc(national,hisp);

%wilc(national,race_minor);

%wilc(national,education); %wilc(national,aquatic);

%chisq_gender(national);%chisq_employ(national); %chisq_hisp(national);

%chisq_race_minor(national);

%chisq_edu(national); %chisq_aquatic(national);

%chisq_income_lt60k(national);

%wilc(national,income_lt60k );

*inland;

%ttest(inland,age);

%wilc(inland,gender); %wilc(inland,employ); %wilc(inland,hisp);

%wilc(inland,race_minor);

%wilc(inland,education); %wilc(inland,aquatic);

%chisq_gender(inland);%chisq_employ(inland); %chisq_hisp(inland);

%chisq_race_minor(inland);

%chisq_edu(inland); %chisq_aquatic(inland);

%chisq_income_lt60k(inland);

%wilc(inland,income_lt60k );

*pacific;

%ttest(pacific,age);

%wilc(pacific,gender); %wilc(pacific,employ); %wilc(pacific,hisp);

%wilc(pacific,race_minor);

%wilc(pacific,education); %wilc(pacific,aquatic);

%chisq_gender(pacific);%chisq_employ(pacific); %chisq_hisp(pacific);

%chisq_race_minor(pacific);

Page 7
%chisq_edu(pacific); %chisq_aquatic(pacific);

%chisq_income_lt60k(pacific);

%wilc(pacific,income_lt60k );

*southeast;

%ttest(southeast,age);

%wilc(southeast,gender); %wilc(southeast,employ); %wilc(southeast,hisp);

%wilc(southeast,race_minor);

%wilc(southeast,education); %wilc(southeast,aquatic);

%chisq_gender(southeast);%chisq_employ(southeast); %chisq_hisp(southeast);

%chisq_race_minor(southeast);

%chisq_edu(southeast); %chisq_aquatic(southeast);

%chisq_f_race(southeast);

%chisq_income_lt60k(southeast);

%wilc(southeast,income_lt60k );

*northeast;

%ttest(northeast,age);

%wilc(northeast,gender); %wilc(northeast,employ); %wilc(northeast,hisp);

%wilc(northeast,race_minor);

%wilc(northeast,education); %wilc(northeast,aquatic);

%chisq_gender(northeast);%chisq_employ(northeast); %chisq_hisp(northeast);

%chisq_race_minor(northeast);

%chisq_edu(northeast); %chisq_aquatic(northeast);

%chisq_income_lt60k(northeast);

%wilc(northeast,income_lt60k );

ods html close; /* close previous */

ods html; /* open new */

Page 8