I am starting to try and figure out how to bootstrap my ml estimations, and I am having trouble so I was hoping you could give some pointers. Basically I am estimating a conditional logit model to try and make it work. Here is the code to setup the data, and the program I have created to do the estimation.
Code:
version 15
clear all
set more off
// Path to testing directory
local tdir "/Users/alfonso/Dropbox/My Documents/Programming/Stata/Testing/nelogit"
// Load the data for estimation
use "`tdir'/estimationdata"
// Have to check why income is missing and if order makes a difference. For now
// we drop missing observations of both.
drop if missing(Income, Order)
global rpv "Cal Sug Sod Fat Price Serv Brand"
global fpv "c1 c2 bmi1 bmi2 inc1 inc2 new1 new2 labin1 labin2"
// Common mata external value
mata nelogit_J = 3 // Number of alternatives
capture porgram drop bsnelogit_fp
program def bsnelogit_fp, eclass
version 15
// Setup to use our estimator.
global nelogit_method = 1 // ml evaluator to be conditional logit
quiet regress choice $fpv $rpv, noconst // Initial values from regression
tempname b0
mat `b0' = e(b)
// Mata external values
mata: nelogit_X = st_data(.,"$fpv $rpv") // independent variables
mata: nelogit_Y = st_data(.,"choice") // dependent variables
// Estimation of fixed parameters
ml model d2 nelogit_d2 (mean:choice = $fpv $rpv, noconst), maximize ///
missing init(`b0', copy) search(off) nolog
endCode:
. // Test the program
. bsnelogit_fp
. ml display
Number of obs = 9,282
Wald chi2(17) = 454.02
Log likelihood = -3119.7094 Prob > chi2 = 0.0000
------------------------------------------------------------------------------
choice | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
c1 | 1.555249 .2332806 6.67 0.000 1.098028 2.012471
c2 | 1.384334 .2361873 5.86 0.000 .9214152 1.847252
bmi1 | -.0081936 .0049027 -1.67 0.095 -.0178028 .0014156
bmi2 | -.0059896 .0048895 -1.22 0.221 -.0155729 .0035936
inc1 | .000045 .000092 0.49 0.624 -.0001352 .0002252
inc2 | .0000352 .0000921 0.38 0.702 -.0001453 .0002157
new1 | -.1135318 .1045485 -1.09 0.278 -.3184432 .0913795
new2 | -.0033199 .1046828 -0.03 0.975 -.2084944 .2018545
labin1 | .2851946 .1047451 2.72 0.006 .0798979 .4904913
labin2 | .3654949 .1048108 3.49 0.000 .1600696 .5709202
Cal | -.0005064 .0008785 -0.58 0.564 -.0022283 .0012155
Sug | -.034054 .0072128 -4.72 0.000 -.0481909 -.0199171
Sod | .0106329 .001784 5.96 0.000 .0071364 .0141295
Fat | .0330286 .0131235 2.52 0.012 .0073071 .0587501
Price | -.2055178 .03213 -6.40 0.000 -.2684916 -.1425441
Serv | .0040012 .000982 4.07 0.000 .0020765 .0059259
Brand | -.228362 .06646 -3.44 0.001 -.3586212 -.0981027
------------------------------------------------------------------------------Code:
. bootstrap _b, reps(50) seed(1234): bsnelogit_fp (running bsnelogit_fp on estimation sample) Bootstrap replications (50) ----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
0 Response to Help using bootstrap command
Post a Comment