Although Stata includes the options asclogit and cmclogit commands, i want to programe it manually because I want to estimate another equation for a choice model for research.
I manage to get an estimation of a multinomial logit with case-specific using this code
program define test
args lnf Xb2 Xb3
quietly replace `lnf' = -`Xb2' - ln(1+exp(-`Xb2')+exp(-`Xb3')) if $ML_y1==2
quietly replace `lnf' = -`Xb3' - ln(1+exp(-`Xb2')+exp(-`Xb3')) if $ML_y1==3
quietly replace `lnf' = -ln(1+exp(-`Xb2')+exp(-`Xb3')) if $ML_y1==1
end
ml model lf prueba4 (xb2: choice= i.sex i.location ib(2).hhclass basic_housing) (xb3:=choice= i.sex i.location ib(2).hhclass basic_housing)
ml maximize
However, when dealing with alternative specific coeficients, these coefficients are estimated for all states
I tried this
program define alt_logit
args lnf todo Xb2 Xb3 a
tempvar za
tempvar ya
quietly generate double `za'=`a'[1,1]*income_2+`a'[1,2]*leisure_2+`a'[1,3]*leisure_sq_2
quietly generate double `ya'=`a'[1,1]*income_3+`a'[1,2]*leisure_3+`a'[1,3]*leisure_sq_3
quietly replace `lnf' = -(`za'+`Xb2') - ln(1+exp(`za'-`Xb2')+exp(`ya'-`Xb3')) if $ML_y1==2
quietly replace `lnf' = -(`ya'+`Xb2') - ln(1+exp(`za'-`Xb2')+exp(`ya'-`Xb3')) if $ML_y1==3
quietly replace `lnf' = - ln(1+exp(`za'-`Xb2')+exp(`ya'-`Xb3')) if $ML_y1==1
end
ml model lf alt_logit (xb2: choice= i.sex i.location ib(2).hhclass basic_housing) (xb3:=choice= i.sex i.location ib(2).hhclass basic_housing)
ml maximize
It does not work,
The coefficients are the same for a variable in different states (see income, leisure and leisure_sq). This is easily computed with asclogit. As far as i can tell, ml does not work in long datasets (several rows per obs) but i don't know how to create the vector of coefficients "a" to work with different variables in a wide dataset. Maybe im not programming this correctly
I would appreciate any ideas to deal with this
DIEGO
I manage to get an estimation of a multinomial logit with case-specific using this code
program define test
args lnf Xb2 Xb3
quietly replace `lnf' = -`Xb2' - ln(1+exp(-`Xb2')+exp(-`Xb3')) if $ML_y1==2
quietly replace `lnf' = -`Xb3' - ln(1+exp(-`Xb2')+exp(-`Xb3')) if $ML_y1==3
quietly replace `lnf' = -ln(1+exp(-`Xb2')+exp(-`Xb3')) if $ML_y1==1
end
ml model lf prueba4 (xb2: choice= i.sex i.location ib(2).hhclass basic_housing) (xb3:=choice= i.sex i.location ib(2).hhclass basic_housing)
ml maximize
However, when dealing with alternative specific coeficients, these coefficients are estimated for all states
I tried this
program define alt_logit
args lnf todo Xb2 Xb3 a
tempvar za
tempvar ya
quietly generate double `za'=`a'[1,1]*income_2+`a'[1,2]*leisure_2+`a'[1,3]*leisure_sq_2
quietly generate double `ya'=`a'[1,1]*income_3+`a'[1,2]*leisure_3+`a'[1,3]*leisure_sq_3
quietly replace `lnf' = -(`za'+`Xb2') - ln(1+exp(`za'-`Xb2')+exp(`ya'-`Xb3')) if $ML_y1==2
quietly replace `lnf' = -(`ya'+`Xb2') - ln(1+exp(`za'-`Xb2')+exp(`ya'-`Xb3')) if $ML_y1==3
quietly replace `lnf' = - ln(1+exp(`za'-`Xb2')+exp(`ya'-`Xb3')) if $ML_y1==1
end
ml model lf alt_logit (xb2: choice= i.sex i.location ib(2).hhclass basic_housing) (xb3:=choice= i.sex i.location ib(2).hhclass basic_housing)
ml maximize
It does not work,
The coefficients are the same for a variable in different states (see income, leisure and leisure_sq). This is easily computed with asclogit. As far as i can tell, ml does not work in long datasets (several rows per obs) but i don't know how to create the vector of coefficients "a" to work with different variables in a wide dataset. Maybe im not programming this correctly
I would appreciate any ideas to deal with this
DIEGO
Comment