/********************************************************************************** BRANDS data set ************************************************************************************ How to fit a conditional logit model where the values of the variables (differ) over choice sets. Data are from Logistic Regression examples using the SAS System, but the method presented here is much simpler. It involves using GENMOD and getting the data in the appropriate format; Individuals choose 1 brand out of 5 possible. In the differ choice sets, the price could differ. ***************************************************************************************/; data brands; title 'Brand Choice Data'; input p1-p5 f1-f5; datalines; 5.99 5.99 5.99 5.99 4.99 12 19 22 33 14 5.99 5.99 3.99 3.99 4.99 34 26 8 27 5 5.99 3.99 5.99 3.99 4.99 13 37 15 27 8 5.99 3.99 3.99 5.99 4.99 49 1 9 37 4 3.99 5.99 5.99 3.99 4.99 31 12 6 18 33 3.99 5.99 3.99 5.99 4.99 4 29 16 42 9 3.99 3.99 5.99 5.99 4.99 37 10 5 35 13 3.99 3.99 3.99 3.99 4.99 16 14 5 51 14 ; data brands2; input combo brand price choice @@; datalines; 1 1 5.99 12 1 2 5.99 0 1 3 5.99 0 1 4 5.99 0 1 5 4.99 0 1 1 5.99 0 1 2 5.99 19 1 3 5.99 0 1 4 5.99 0 1 5 4.99 0 1 1 5.99 0 1 2 5.99 0 1 3 5.99 22 1 4 5.99 0 1 5 4.99 0 1 1 5.99 0 1 2 5.99 0 1 3 5.99 0 1 4 5.99 33 1 5 4.99 0 1 1 5.99 0 1 2 5.99 0 1 3 5.99 0 1 4 5.99 0 1 5 4.99 14 2 1 5.99 34 2 2 5.99 0 2 3 3.99 0 2 4 3.99 0 2 5 4.99 0 2 1 5.99 0 2 2 5.99 26 2 3 3.99 0 2 4 3.99 0 2 5 4.99 0 2 1 5.99 0 2 2 5.99 0 2 3 3.99 8 2 4 3.99 0 2 5 4.99 0 2 1 5.99 0 2 2 5.99 0 2 3 3.99 0 2 4 3.99 27 2 5 4.99 0 2 1 5.99 0 2 2 5.99 0 2 3 3.99 0 2 4 3.99 0 2 5 4.99 5 3 1 5.99 13 3 2 3.99 0 3 3 5.99 0 3 4 3.99 0 3 5 4.99 0 3 1 5.99 0 3 2 3.99 37 3 3 5.99 0 3 4 3.99 0 3 5 4.99 0 3 1 5.99 0 3 2 3.99 0 3 3 5.99 15 3 4 3.99 0 3 5 4.99 0 3 1 5.99 0 3 2 3.99 0 3 3 5.99 0 3 4 3.99 27 3 5 4.99 0 3 1 5.99 0 3 2 3.99 0 3 3 5.99 0 3 4 3.99 0 3 5 4.99 8 4 1 5.99 49 4 2 3.99 0 4 3 3.99 0 4 4 5.99 0 4 5 4.99 0 4 1 5.99 0 4 2 3.99 1 4 3 3.99 0 4 4 5.99 0 4 5 4.99 0 4 1 5.99 0 4 2 3.99 0 4 3 3.99 9 4 4 5.99 0 4 5 4.99 0 4 1 5.99 0 4 2 3.99 0 4 3 3.99 0 4 4 5.99 37 4 5 4.99 0 4 1 5.99 0 4 2 3.99 0 4 3 3.99 0 4 4 5.99 0 4 5 4.99 4 5 1 3.99 31 5 2 5.99 0 5 3 5.99 0 5 4 3.99 0 5 5 4.99 0 5 1 3.99 0 5 2 5.99 12 5 3 5.99 0 5 4 3.99 0 5 5 4.99 0 5 1 3.99 0 5 2 5.99 0 5 3 5.99 6 5 4 3.99 0 5 5 4.99 0 5 1 3.99 0 5 2 5.99 0 5 3 5.99 0 5 4 3.99 18 5 5 4.99 0 5 1 3.99 0 5 2 5.99 0 5 3 5.99 0 5 4 3.99 0 5 5 4.99 33 6 1 3.99 4 6 2 5.99 0 6 3 3.99 0 6 4 5.99 0 6 5 4.99 0 6 1 3.99 0 6 2 5.99 29 6 3 3.99 0 6 4 5.99 0 6 5 4.99 0 6 1 3.99 0 6 2 5.99 0 6 3 3.99 16 6 4 5.99 0 6 5 4.99 0 6 1 3.99 0 6 2 5.99 0 6 3 3.99 0 6 4 5.99 42 6 5 4.99 0 6 1 3.99 0 6 2 5.99 0 6 3 3.99 0 6 4 5.99 0 6 5 4.99 9 7 1 3.99 37 7 2 3.99 0 7 3 5.99 0 7 4 5.99 0 7 5 4.99 0 7 1 3.99 0 7 2 3.99 10 7 3 5.99 0 7 4 5.99 0 7 5 4.99 0 7 1 3.99 0 7 2 3.99 0 7 3 5.99 5 7 4 5.99 0 7 5 4.99 0 7 1 3.99 0 7 2 3.99 0 7 3 5.99 0 7 4 5.99 35 7 5 4.99 0 7 1 3.99 0 7 2 3.99 0 7 3 5.99 0 7 4 5.99 0 7 5 4.99 13 8 1 3.99 16 8 2 3.99 0 8 3 3.99 0 8 4 3.99 0 8 5 4.99 0 8 1 3.99 0 8 2 3.99 14 8 3 3.99 0 8 4 3.99 0 8 5 4.99 0 8 1 3.99 0 8 2 3.99 0 8 3 3.99 5 8 4 3.99 0 8 5 4.99 0 8 1 3.99 0 8 2 3.99 0 8 3 3.99 0 8 4 3.99 51 8 5 4.99 0 8 1 3.99 0 8 2 3.99 0 8 3 3.99 0 8 4 3.99 0 8 5 4.99 14 run; title 'Brands Model 1 '; proc genmod; class combo brand ; model choice = combo brand price /link=log dist=poi; ; title 'Brands Model 2 '; proc genmod; class combo brand ; model choice = combo brand brand*price /link=log dist=poi; run; /******************** Set up data for PROC MDC **************************/ data tmp1; set brands; array p[5] p1-p5; array f[5] f1-f5; array brand[5] brand1-brand5; subj=0; do b=1 to 5; brand[b]=0; do j=1 to f[b]; do pr=1 to 5; price=p[pr]; if b=pr then Y=1; else Y=0; if pr=1 then do; brand1=1; brand2=0; brand3=0; brand4=0; end; else if pr=2 then do; brand1=0; brand2=1; brand3=0; brand4=0; end; else if pr=3 then do; brand1=0; brand2=0; brand3=1; brand4=0; end; else if pr=4 then do; brand1=0; brand2=0; brand3=0; brand4=1; end; else if pr=5 then do; brand1=0; brand2=0; brand3=0; brand4=0; end; output; end; end; end; run; data case_index; do case =1 to 800; do j =1 to 5 by 1; output; end; end; run; data mdc_data; merge tmp1 case_index; keep Y price brand1-brand4 case pr; run;; title 'MDC for the brands and price'; proc mdc data=mdc_data; model y = brand1 brand2 brand3 brand4 price / type=clogit nchoice=5 covest=hessian; id case; run; title 'MDC for the brands and price'; proc mdc data=mdc_data; class pr; model y = pr price / type=clogit nchoice=5 covest=hessian; id case; run; title 'MDC interaction'; proc mdc data=mdc_data; class pr; model y = pr price pr*price/ type=clogit nchoice=5 covest=hessian; id case; run; /************************************************************************/ * Using phreg; * Code is basically from Logistic Regression Exampls book (1995); data brands3; set brands; drop p1-p5 f1-f5; * Define arrays for variables of the orginal data set; array p[5] p1-p5; /* Array for prices*/ array f[5] f1-f5; /* Array for frequencies*/ * Define arrays for design matrices in new data set; array pb[5] price1-price5; /* Array for prices*/ array brand[5] brand1-brand5; /* Aarray for brands*/; * Initialize brand and brand by price design matrices; do j=1 to 5; /* 5=number of choice options*/ brand[j]=0; pb[j]=0; end; * Count the total number of choices; nobs = sum(of f1-f5); * Store choice set number to stratify; ch_set=_n_; * Create design matrix; do j=1 to 5; price = p[j]; brand[j]=1; pb[j] = price; * Output number of times each brand choosen; freq = f[j]; choose=1; t = 1; /* choice occurs at time 1 */ output; * Output number of times each brand was not choosen; freq = nobs-f[j]; choose =0; t = 2; /* NON choice occurs at time 2 */ output; * Set up for next alternative; brand[j] = 0; pb[j] = 0; end; run; proc print data=brands3 (obs=15); proc phreg data=brands3; strata ch_set; model t*choose(0)=brand1 brand2 brand3 brand4 brand5 price; freq freq; title 'PHREG: Discrete choice with common price effect'; proc phreg data=brands3; strata ch_set; model t*choose(0)=brand1-brand5 price1-price5; freq freq; title 'PHREG: Discrete choice with brand by price effect'; run;