/* A program to prepare data for a conditional logit and estimate it */ #delimit; set mem 3000k; log using clogit.log, replace; use ps206hw7; generate id = _n; /* created a variable for ID# */ generate choice = 1; /* to keep track of which canidate this sub-dataset is for */ generate votec=0; replace votec=1 if vote==1; /* =1 if vote for Bush */ generate discand = disbush; keep id choice votec discand gender educ age income; save vbush, replace; /* We need to do this so we can use the "append" command later */ clear; use ps206hw7; generate id = _n; generate choice = 2; generate votec=0; replace votec=1 if vote==2; /* =1 if vote for Clinton */ generate discand = disclin; keep id choice votec discand gender educ age income; save vclin, replace; clear; use ps206hw7; generate id = _n; generate choice = 3; generate votec=0; replace votec=1 if vote==3; /* =1 if vote for Perot */ generate discand = dispero; keep id choice votec discand gender educ age income; save vpero, replace; clear; use vbush; append using vclin; append using vpero; /* this stacks all of our sub-datasets into 1 dataset */ sort id; generate cbush = 0; replace cbush = 1 if choice==1; generate cclin = 0; replace cclin = 1 if choice==2; /* creating data matrix, normalized wrt Perot */ generate bgen = gender*cbush; generate cgen = gender*cclin; generate beduc = educ*cbush; generate ceduc = educ*cclin; generate bage = age*cbush; generate cage = age*cclin; generate binc = income*cbush; generate cinc = income*cclin; /* estimate conditional logit */ clogit votec discand cbush cclin bgen cgen beduc ceduc bage cage binc cinc, group(id);