Published on :

PROC BCHOICE Example - Heterogeneity and Individual Characteristics

This code is also available in: Deutsch Español Français
The script begins by displaying the first 24 observations of the `Sashelp.Margarin` dataset using `PROC PRINT`, sorted by `HouseID` and `Set`. Then, it executes `PROC BCHOICE` to fit a Bayesian choice model. The model includes classification variables (`Brand`, `HouseID`, `Set`), a main model term (`Choice` as a function of the choice set `HouseID` and `Set`), and random effects for `Brand` and `LogPrice` at the subject level `HouseID`, with re-centering on `LogInc` and `FamSize`.
Data Analysis

Type : SASHELP


The script exclusively uses the `Sashelp.Margarin` dataset, an example dataset built into SAS.

1 Code Block
PROC PRINT
Explanation :
This block uses `PROC PRINT` to display the first 24 rows of the `Sashelp.Margarin` dataset. Observations are grouped and identified by the `HouseID` and `Set` variables. It provides an initial overview of the data before analysis.
Copied!
1PROC PRINT DATA=Sashelp.Margarin (obs=24);
2 BY HouseID SET;
3 id HouseID SET;
4RUN;
2 Code Block
PROC BCHOICE
Explanation :
This block executes `PROC BCHOICE` to perform a Bayesian discrete choice analysis. The `Sashelp.Margarin` dataset is used. The `seed`, `nmc`, `thin`, `nthreads` options control the Markov Chain Monte Carlo (MCMC) simulation. Variables `Brand`, `HouseID`, `Set` are declared as classification variables. The model specifies that `Choice` depends on the choice set defined by `HouseID` and `Set`. Random effects are defined for `Brand` and `LogPrice` at the subject level `HouseID`, with covariates (`LogInc`, `FamSize`) for re-centering of random effects.
Copied!
1PROC BCHOICE DATA=Sashelp.Margarin seed=123 nmc=40000 thin=2
2 nthreads=4 plots=none;
3 class Brand(ref='PPk') HouseID SET;
4 model Choice = / choiceset=(HouseID SET);
5 random Brand LogPrice / subject=HouseID remean=(LogInc FamSize)
6 type=un monitor=(1);
7RUN;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
Copyright Info : SAS SAMPLE LIBRARY