-------------------------------------------------------------------------------------------------------- log: C:\UpCD1\WORK\Stata_prg\ml1.log log type: text opened on: 26 Sep 2003, 21:46:09 . . webuse auto.dta,clear /* to use data directly from STATA official website */ (1978 Automobile Data) . *save auto.dta /* to save the data set you just netted from the website to your working dir > ectory */ . webuse weib.dta,clear (Patient Survival in Drug Trial) . *save weib.dta . . *************************** . * Overview of ml * . *************************** . . ********************************************** . * one equation one dependent variable * . ********************************************** . . use auto.dta,clear (1978 Automobile Data) . capture program drop myprobit . program myprobit /* to use maximum likelihood method to estimate the prob > it model */ 1. version 8.0 2. args lnf theta1 3. quietly replace `lnf' = ln(norm(`theta1')) if $ML_y1==1 4. quietly replace `lnf' = ln(norm(-`theta1')) if $ML_y1==0 5. end . . ml model lf myprobit (foreign = mpg weight) /* to estimate the basic probit model using method lf */ . ml check /* to verify that the log-likelihood evaluator you have written seems to work */ Test 1: Calling myprobit to check if it computes log likelihood and does not alter coefficient vector... Passed. Test 2: Calling myprobit again to check if the same log likelihood value is returned... Passed. Test 3: Calling myprobit to check if 1st derivatives are computed... test not relevant for method lf. Test 4: Calling myprobit again to check if the same 1st derivatives are returned... test not relevant for method lf. Test 5: Calling myprobit to check if 2nd derivatives are computed... test not relevant for method lf. Test 6: Calling myprobit again to check if the same 2nd derivatives are returned... test not relevant for method lf. ------------------------------------------------------------------------------ Searching for alternate values for the coefficient vector to verify that myprobit returns different results when fed a different coefficient vector: Searching... initial: log likelihood = - (could not be evaluated) searching for feasible values + feasible: log likelihood = -121.39426 improving initial values ......+... improve: log likelihood = -108.81773 continuing with tests... ------------------------------------------------------------------------------ Test 7: Calling myprobit to check log likelihood at the new values... Passed. Test 8: Calling myprobit requesting 1st derivatives at the new values... test not relevant for method lf. Test 9: Calling myprobit requesting 2nd derivatives at the new values... test not relevant for method lf. ------------------------------------------------------------------------------ myprobit HAS PASSED ALL TESTS ------------------------------------------------------------------------------ Test 10: Does myprobit produce unanticipated output? This is a minor issue. Stata has been running myprobit with all output suppressed. This time Stata will not suppress the output. If you see any unanticipated output, you need to place quietly in front of some of the commands in myprobit. -------------------------------------------------------------- begin execution ---------------------------------------------------------------- end execution . ml search /* to find a better initial value so that the convergence of log-likelihood takes less > time*/ initial: log likelihood = -108.81773 improve: log likelihood = -106.22897 rescale: log likelihood = -45.036434 . ml maximize initial: log likelihood = -45.036434 rescale: log likelihood = -45.036434 Iteration 0: log likelihood = -45.036434 Iteration 1: log likelihood = -27.919273 Iteration 2: log likelihood = -26.859315 Iteration 3: log likelihood = -26.844199 Iteration 4: log likelihood = -26.844189 Iteration 5: log likelihood = -26.844189 Number of obs = 74 Wald chi2(2) = 20.75 Log likelihood = -26.844189 Prob > chi2 = 0.0000 ------------------------------------------------------------------------------ foreign | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- mpg | -.1039503 .0515689 -2.02 0.044 -.2050235 -.0028772 weight | -.0023355 .0005661 -4.13 0.000 -.003445 -.0012261 _cons | 8.275464 2.554142 3.24 0.001 3.269438 13.28149 ------------------------------------------------------------------------------ . ml graph /* to graph the log-likelihood values against the iteration number to verify the proce > ss of convergence */ . . ml model lf myprobit (foreign=mpg weight, nocons) /* to estimate the restricted model withou > t the intercept */ . ml maximize initial: log likelihood = -51.292891 alternative: log likelihood = -44.363633 rescale: log likelihood = -44.363633 Iteration 0: log likelihood = -44.363633 Iteration 1: log likelihood = -33.159091 Iteration 2: log likelihood = -32.947096 Iteration 3: log likelihood = -32.947017 Iteration 4: log likelihood = -32.947017 Number of obs = 74 Wald chi2(2) = 24.30 Log likelihood = -32.947017 Prob > chi2 = 0.0000 ------------------------------------------------------------------------------ foreign | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- mpg | .0631929 .0179544 3.52 0.000 .0280029 .0983828 weight | -.0006996 .0001506 -4.65 0.000 -.0009948 -.0004044 ------------------------------------------------------------------------------ . . ml model lf myprobit (foreign=) /* to estimate the restricted model whose only explantory variable > is the constant */ . ml maximize initial: log likelihood = -51.292891 alternative: log likelihood = -45.055272 rescale: log likelihood = -45.055272 Iteration 0: log likelihood = -45.055272 Iteration 1: log likelihood = -45.03321 Iteration 2: log likelihood = -45.03321 Number of obs = 74 Wald chi2(0) = . Log likelihood = -45.03321 Prob > chi2 = . ------------------------------------------------------------------------------ foreign | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- _cons | -.5321897 .1534465 -3.47 0.001 -.8329394 -.2314401 ------------------------------------------------------------------------------ . . constraint define 1 _b[mpg]==0 /* to define a constraint which drops a > coefficient */ . ml model lf myprobit (foreign = mpg weight), constraint (1) /* to estimate the restricted model usin > g ML*/ . ml maximize initial: log likelihood = -51.292891 alternative: log likelihood = -45.055272 rescale: log likelihood = -45.055272 Iteration 0: log likelihood = -45.055272 Iteration 1: log likelihood = -29.508077 Iteration 2: log likelihood = -28.91219 Iteration 3: log likelihood = -28.908406 Iteration 4: log likelihood = -28.908406 Number of obs = 74 Wald chi2(1) = 21.25 Log likelihood = -28.908406 Prob > chi2 = 0.0000 ( 1) [eq1]mpg = 0 ------------------------------------------------------------------------------ foreign | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- mpg | (dropped) weight | -.0015049 .0003265 -4.61 0.000 -.0021447 -.0008651 _cons | 3.655625 .8775791 4.17 0.000 1.935601 5.375648 ------------------------------------------------------------------------------ . . ml model lf myprobit (foreign = mpg weight),robust /* to specify the robust variance estimator and re > port it */ . ml maximize initial: log pseudo-likelihood = -51.292891 alternative: log pseudo-likelihood = -45.055272 rescale: log pseudo-likelihood = -45.055272 Iteration 0: log pseudo-likelihood = -45.055272 Iteration 1: log pseudo-likelihood = -27.904423 Iteration 2: log pseudo-likelihood = -26.857971 Iteration 3: log pseudo-likelihood = -26.844198 Iteration 4: log pseudo-likelihood = -26.844189 Iteration 5: log pseudo-likelihood = -26.844189 Number of obs = 74 Wald chi2(2) = 30.26 Log pseudo-likelihood = -26.844189 Prob > chi2 = 0.0000 ------------------------------------------------------------------------------ | Robust foreign | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- mpg | -.1039503 .0593548 -1.75 0.080 -.2202836 .0123829 weight | -.0023355 .0004934 -4.73 0.000 -.0033025 -.0013686 _cons | 8.275464 2.539177 3.26 0.001 3.298769 13.25216 ------------------------------------------------------------------------------ . . ml model lf myprobit (foreign = mpg weight) if mpg<= 25 /* to specify a subsample to estimate th > e model*/ . ml maximize initial: log likelihood = -41.588831 alternative: log likelihood = -34.241265 rescale: log likelihood = -34.241265 Iteration 0: log likelihood = -34.241265 Iteration 1: log likelihood = -13.42652 Iteration 2: log likelihood = -11.994833 Iteration 3: log likelihood = -11.968881 Iteration 4: log likelihood = -11.968809 Iteration 5: log likelihood = -11.968809 Number of obs = 60 Wald chi2(2) = 15.76 Log likelihood = -11.968809 Prob > chi2 = 0.0004 ------------------------------------------------------------------------------ foreign | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- mpg | -.4946941 .1721914 -2.87 0.004 -.832183 -.1572052 weight | -.0049661 .0012864 -3.86 0.000 -.0074875 -.0024448 _cons | 23.89964 6.960826 3.43 0.001 10.25667 37.54261 ------------------------------------------------------------------------------ . . ml model lf myprobit (foreign = mpg weight) . ml maximize, gradient hessian trace /* to add to the iteration log a report on the current g > radient vector, > current negative Hessian matrix and current parameter ve > ctor */ initial: log likelihood = -51.292891 trying nonzero initial values +. alternative: log likelihood = -45.055272 rescaling entire vector .. rescale: log likelihood = -45.055272 ------------------------------------------------------------------------------ Iteration 0: Coefficient vector: eq1: eq1: eq1: mpg weight _cons r1 0 0 -.5 log likelihood = -45.055272 Gradient vector (length = 29687.33): eq1: eq1: eq1: mpg weight _cons r1 96.94298 -29687.17 -1.372632 Negative Hessian: eq1: eq1: eq1: mpg weight _cons eq1:mpg 21641.35 eq1:weight 2574845 3.96e+08 eq1:_cons 928.451 125901.2 42.81295 ------------------------------------------------------------------------------ Iteration 1: Coefficient vector: eq1: eq1: eq1: mpg weight _cons r1 -.070688 -.0018056 6.298796 log likelihood = -27.904423 Gradient vector (length = 17874.97): eq1: eq1: eq1: mpg weight _cons r1 -129.3791 -17874.5 -5.813958 Negative Hessian: eq1: eq1: eq1: mpg weight _cons eq1:mpg 17178.88 eq1:weight 1798533 2.31e+08 eq1:_cons 697.2258 81480.02 30.14496 ------------------------------------------------------------------------------ Iteration 2: Coefficient vector: eq1: eq1: eq1: mpg weight _cons r1 -.1034503 -.0022731 8.103193 log likelihood = -26.857971 Gradient vector (length = 577.1195): eq1: eq1: eq1: mpg weight _cons r1 2.919719 -577.1121 -.03931 Negative Hessian: eq1: eq1: eq1: mpg weight _cons eq1:mpg 16095.69 eq1:weight 1577608 1.88e+08 eq1:_cons 634.3298 69168.11 26.61864 ------------------------------------------------------------------------------ Iteration 3: Coefficient vector: eq1: eq1: eq1: mpg weight _cons r1 -.1038803 -.0023337 8.269215 log likelihood = -26.844198 Gradient vector (length = 30.59503): eq1: eq1: eq1: mpg weight _cons r1 -.1258613 -30.59477 -.0078499 Negative Hessian: eq1: eq1: eq1: mpg weight _cons eq1:mpg 15919.63 eq1:weight 1551495 1.84e+08 eq1:_cons 625.8511 67796.43 26.19003 ------------------------------------------------------------------------------ Iteration 4: Coefficient vector: eq1: eq1: eq1: mpg weight _cons r1 -.1039503 -.0023355 8.275459 log likelihood = -26.844189 Gradient vector (length = .0278053): eq1: eq1: eq1: mpg weight _cons r1 -.0001316 -.027805 -7.53e-06 Negative Hessian: eq1: eq1: eq1: mpg weight _cons eq1:mpg 15915.04 eq1:weight 1550748 1.83e+08 eq1:_cons 625.6168 67756.7 26.17784 ------------------------------------------------------------------------------ Iteration 5: Coefficient vector: eq1: eq1: eq1: mpg weight _cons r1 -.1039503 -.0023355 8.275464 log likelihood = -26.844189 Gradient vector (length = 2.73e-08): eq1: eq1: eq1: mpg weight _cons r1 -9.36e-11 -2.73e-08 -6.00e-12 Negative Hessian: eq1: eq1: eq1: mpg weight _cons eq1:mpg 15915.03 eq1:weight 1550748 1.83e+08 eq1:_cons 625.6166 67756.66 26.17783 ------------------------------------------------------------------------------ Number of obs = 74 Wald chi2(2) = 20.75 Log likelihood = -26.844189 Prob > chi2 = 0.0000 ------------------------------------------------------------------------------ foreign | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- mpg | -.1039503 .0515689 -2.02 0.044 -.2050235 -.0028772 weight | -.0023355 .0005661 -4.13 0.000 -.003445 -.0012261 _cons | 8.275464 2.554142 3.24 0.001 3.269437 13.28149 ------------------------------------------------------------------------------ . . ml model lf myprobit (foreign = mpg weight) . ml maximize,level(99) /* to change the significance level from 95 to 99*/ initial: log likelihood = -51.292891 alternative: log likelihood = -45.055272 rescale: log likelihood = -45.055272 Iteration 0: log likelihood = -45.055272 Iteration 1: log likelihood = -27.904423 Iteration 2: log likelihood = -26.857971 Iteration 3: log likelihood = -26.844198 Iteration 4: log likelihood = -26.844189 Iteration 5: log likelihood = -26.844189 Number of obs = 74 Wald chi2(2) = 20.75 Log likelihood = -26.844189 Prob > chi2 = 0.0000 ------------------------------------------------------------------------------ foreign | Coef. Std. Err. z P>|z| [99% Conf. Interval] -------------+---------------------------------------------------------------- mpg | -.1039503 .0515689 -2.02 0.044 -.236783 .0288823 weight | -.0023355 .0005661 -4.13 0.000 -.0037936 -.0008775 _cons | 8.275464 2.554142 3.24 0.001 1.69643 14.8545 ------------------------------------------------------------------------------ . . . *************************************************** . * two equations, one dependent variable * . *************************************************** . . use auto.dta,clear (1978 Automobile Data) . capture program drop myreg /* to use maximum likelihood method to estimate the linea > r regression model */ . program myreg 1. version 8.0 2. args lnf theta1 theta2 /* to use theta2 to stand for the standard deviation, so this is a > two equation model */ 3. quietly replace `lnf' = ln(normd(($ML_y1-`theta1')/`theta2'))-ln(`theta2') 4. end . . ml model lf myreg (mpg =weight displ)/sigma /* to use sigma to specify the equation for standard > deviation */ . ml check Test 1: Calling myreg to check if it computes log likelihood and does not alter coefficient vector... Passed. Test 2: Calling myreg again to check if the same log likelihood value is returned... Passed. ------------------------------------------------------------------------------ The initial values are not feasible. This may be because the initial values have been chosen poorly or because there is an error in myreg and it always returns missing no matter what the parameter values. Stata is going to use ml search to find a feasible set of initial values. If myreg is broken, this will not work and you will have to press Break to make ml search stop. Searching... initial: log likelihood = - (could not be evaluated) searching for feasible values .+ feasible: log likelihood = -10383.274 improving initial values ++........ improve: log likelihood = -284.47835 rescaling entire vector .. rescale: log likelihood = -284.47835 rescaling equations .+.+. rescaling equations .... rescale eq: log likelihood = -244.22397 restarting tests... ------------------------------------------------------------------------------ Test 1: Calling myreg to check if it computes log likelihood and does not alter coefficient vector... Passed. Test 2: Calling myreg again to check if the same log likelihood value is returned... Passed. Test 3: Calling myreg to check if 1st derivatives are computed... test not relevant for method lf. Test 4: Calling myreg again to check if the same 1st derivatives are returned... test not relevant for method lf. Test 5: Calling myreg to check if 2nd derivatives are computed... test not relevant for method lf. Test 6: Calling myreg again to check if the same 2nd derivatives are returned... test not relevant for method lf. ------------------------------------------------------------------------------ Searching for alternate values for the coefficient vector to verify that myreg returns different results when fed a different coefficient vector: Searching... initial: log likelihood = - (could not be evaluated) searching for feasible values + feasible: log likelihood = -6928.0762 improving initial values +++....... improve: log likelihood = -303.2774 continuing with tests... ------------------------------------------------------------------------------ Test 7: Calling myreg to check log likelihood at the new values... Passed. Test 8: Calling myreg requesting 1st derivatives at the new values... test not relevant for method lf. Test 9: Calling myreg requesting 2nd derivatives at the new values... test not relevant for method lf. ------------------------------------------------------------------------------ myreg HAS PASSED ALL TESTS ------------------------------------------------------------------------------ Test 10: Does myreg produce unanticipated output? This is a minor issue. Stata has been running myreg with all output suppressed. This time Stata will not suppress the output. If you see any unanticipated output, you need to place quietly in front of some of the commands in myreg. -------------------------------------------------------------- begin execution ---------------------------------------------------------------- end execution . ml search initial: log likelihood = -303.2774 improve: log likelihood = -282.51086 rescale: log likelihood = -275.49122 rescale eq: log likelihood = -263.67446 . ml maximize initial: log likelihood = -263.67446 rescale: log likelihood = -263.67446 rescale eq: log likelihood = -263.67446 Iteration 0: log likelihood = -263.67446 (not concave) Iteration 1: log likelihood = -224.08024 (not concave) Iteration 2: log likelihood = -214.78351 Iteration 3: log likelihood = -198.26311 Iteration 4: log likelihood = -195.32349 Iteration 5: log likelihood = -195.23991 Iteration 6: log likelihood = -195.2398 Iteration 7: log likelihood = -195.2398 Number of obs = 74 Wald chi2(2) = 139.21 Log likelihood = -195.2398 Prob > chi2 = 0.0000 ------------------------------------------------------------------------------ mpg | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- eq1 | weight | -.0065671 .0011424 -5.75 0.000 -.0088061 -.0043281 displacement | .0052808 .0096674 0.55 0.585 -.0136671 .0242286 _cons | 40.08452 1.978739 20.26 0.000 36.20627 43.96278 -------------+---------------------------------------------------------------- sigma | _cons | 3.385282 .2782685 12.17 0.000 2.839886 3.930678 ------------------------------------------------------------------------------ . ml graph . . ml model lf myreg (mpg =weight displ) () /* an equivalent specification as the former one whi > ch uses sigma */ . ml maximize initial: log likelihood = - (could not be evaluated) feasible: log likelihood = -10383.274 rescale: log likelihood = -292.89564 rescale eq: log likelihood = -238.45986 Iteration 0: log likelihood = -238.45986 (not concave) Iteration 1: log likelihood = -225.48338 (not concave) Iteration 2: log likelihood = -215.65944 Iteration 3: log likelihood = -199.17981 Iteration 4: log likelihood = -195.29821 Iteration 5: log likelihood = -195.24 Iteration 6: log likelihood = -195.2398 Iteration 7: log likelihood = -195.2398 Number of obs = 74 Wald chi2(2) = 139.21 Log likelihood = -195.2398 Prob > chi2 = 0.0000 ------------------------------------------------------------------------------ mpg | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- eq1 | weight | -.0065671 .0011424 -5.75 0.000 -.0088061 -.0043281 displacement | .0052808 .0096674 0.55 0.585 -.0136671 .0242286 _cons | 40.08452 1.978738 20.26 0.000 36.20627 43.96278 -------------+---------------------------------------------------------------- eq2 | _cons | 3.385282 .2782684 12.17 0.000 2.839886 3.930678 ------------------------------------------------------------------------------ . . ml model lf myreg (mpg =weight displ) (sigma:) /* another equivalent way to specify the second equa > tion, and the name > of the second quation has been changed to sigma */ . ml maximize initial: log likelihood = - (could not be evaluated) feasible: log likelihood = -10383.274 rescale: log likelihood = -292.89564 rescale eq: log likelihood = -238.45986 Iteration 0: log likelihood = -238.45986 (not concave) Iteration 1: log likelihood = -225.48338 (not concave) Iteration 2: log likelihood = -215.65944 Iteration 3: log likelihood = -199.17981 Iteration 4: log likelihood = -195.29821 Iteration 5: log likelihood = -195.24 Iteration 6: log likelihood = -195.2398 Iteration 7: log likelihood = -195.2398 Number of obs = 74 Wald chi2(2) = 139.21 Log likelihood = -195.2398 Prob > chi2 = 0.0000 ------------------------------------------------------------------------------ mpg | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- eq1 | weight | -.0065671 .0011424 -5.75 0.000 -.0088061 -.0043281 displacement | .0052808 .0096674 0.55 0.585 -.0136671 .0242286 _cons | 40.08452 1.978738 20.26 0.000 36.20627 43.96278 -------------+---------------------------------------------------------------- sigma | _cons | 3.385282 .2782684 12.17 0.000 2.839886 3.930678 ------------------------------------------------------------------------------ . . ml model lf myreg (mpg =weight displ) (sigma: weight) /* to estimate the conditional heteroskedastici > ty model, and to > specify that standard deviation depends on weig > ht and constant */ . ml maximize initial: log likelihood = - (could not be evaluated) feasible: log likelihood = -10383.274 rescale: log likelihood = -292.89564 rescale eq: log likelihood = -238.45986 Iteration 0: log likelihood = -238.45986 (not concave) Iteration 1: log likelihood = -223.70178 (not concave) Iteration 2: log likelihood = -208.95405 Iteration 3: log likelihood = -195.25115 Iteration 4: log likelihood = -190.48052 Iteration 5: log likelihood = -190.19891 Iteration 6: log likelihood = -190.19848 Iteration 7: log likelihood = -190.19848 Number of obs = 74 Wald chi2(2) = 140.31 Log likelihood = -190.19848 Prob > chi2 = 0.0000 ------------------------------------------------------------------------------ mpg | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- eq1 | weight | -.0060495 .0011241 -5.38 0.000 -.0082526 -.0038463 displacement | .0052541 .008891 0.59 0.555 -.0121718 .0226801 _cons | 38.47725 2.095853 18.36 0.000 34.36946 42.58505 -------------+---------------------------------------------------------------- sigma | weight | -.0009508 .0002892 -3.29 0.001 -.0015176 -.000384 _cons | 6.122385 1.026743 5.96 0.000 4.110006 8.134763 ------------------------------------------------------------------------------ . . ml model lf myreg (mpg =weight displ) (sigma: weight, nocons) /* to specify the second equation witho > ut intercept */ . ml maximize initial: log likelihood = - (could not be evaluated) feasible: log likelihood = -4207.6269 rescale: log likelihood = -289.15681 rescale eq: log likelihood = -257.89841 Iteration 0: log likelihood = -257.89841 (not concave) Iteration 1: log likelihood = -245.15079 (not concave) Iteration 2: log likelihood = -237.96905 (not concave) Iteration 3: log likelihood = -230.45037 Iteration 4: log likelihood = -214.59618 Iteration 5: log likelihood = -210.80852 Iteration 6: log likelihood = -210.75623 Iteration 7: log likelihood = -210.75609 Iteration 8: log likelihood = -210.75609 Number of obs = 74 Wald chi2(2) = 106.26 Log likelihood = -210.75609 Prob > chi2 = 0.0000 ------------------------------------------------------------------------------ mpg | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- eq1 | weight | -.0068679 .0012348 -5.56 0.000 -.0092881 -.0044477 displacement | .003304 .0109685 0.30 0.763 -.018194 .0248019 _cons | 41.33294 2.017912 20.48 0.000 37.3779 45.28797 -------------+---------------------------------------------------------------- sigma | weight | .0014306 .0001175 12.18 0.000 .0012004 .0016609 ------------------------------------------------------------------------------ . . *********************************************** . * two equations, two dependent variables * . *********************************************** . . use weib.dta,clear (Patient Survival in Drug Trial) . capture program drop myweib /* to use maximum likelihood method to estimate the Weibull > model */ . program define myweib 1. version 8.0 2. args lnf theta1 theta2 3. tempvar p M R /* to make programming easier by introducing tempo > rary variabls*/ 4. quietly gen double `p' = exp(`theta2') /* temporary variables should be generated as doub > les */ 5. quietly gen double `M' = ($ML_y1*exp(-`theta1'))^`p' 6. quietly gen double `R' = ln($ML_y1)-`theta1' 7. quietly replace `lnf' = -`M' + $ML_y2*(`theta2'-`theta1'+(`p'-1)*`R') 8. end . . ml model lf myweib (studytime died =drug2 drug3 age) () /* the () corresponds to the Weibull sh > ape parameter s*/ . ml check Test 1: Calling myweib to check if it computes log likelihood and does not alter coefficient vector... Passed. Test 2: Calling myweib again to check if the same log likelihood value is returned... Passed. Test 3: Calling myweib to check if 1st derivatives are computed... test not relevant for method lf. Test 4: Calling myweib again to check if the same 1st derivatives are returned... test not relevant for method lf. Test 5: Calling myweib to check if 2nd derivatives are computed... test not relevant for method lf. Test 6: Calling myweib again to check if the same 2nd derivatives are returned... test not relevant for method lf. ------------------------------------------------------------------------------ Searching for alternate values for the coefficient vector to verify that myweib returns different results when fed a different coefficient vector: Searching... initial: log likelihood = - (could not be evaluated) searching for feasible values + feasible: log likelihood = -1.803e+09 improving initial values .+........ improve: log likelihood = -582889 continuing with tests... ------------------------------------------------------------------------------ Test 7: Calling myweib to check log likelihood at the new values... Passed. Test 8: Calling myweib requesting 1st derivatives at the new values... test not relevant for method lf. Test 9: Calling myweib requesting 2nd derivatives at the new values... test not relevant for method lf. ------------------------------------------------------------------------------ myweib HAS PASSED ALL TESTS ------------------------------------------------------------------------------ Test 10: Does myweib produce unanticipated output? This is a minor issue. Stata has been running myweib with all output suppressed. This time Stata will not suppress the output. If you see any unanticipated output, you need to place quietly in front of some of the commands in myweib. -------------------------------------------------------------- begin execution ---------------------------------------------------------------- end execution . ml search initial: log likelihood = -582889 improve: log likelihood = -1416.3095 rescale: log likelihood = -1226.5627 rescale eq: log likelihood = -143.42378 . ml maximize initial: log likelihood = -143.42378 rescale: log likelihood = -143.42378 rescale eq: log likelihood = -143.42378 Iteration 0: log likelihood = -143.42378 (not concave) Iteration 1: log likelihood = -124.6107 Iteration 2: log likelihood = -112.54233 Iteration 3: log likelihood = -110.39698 Iteration 4: log likelihood = -110.2677 Iteration 5: log likelihood = -110.26736 Iteration 6: log likelihood = -110.26736 Number of obs = 48 Wald chi2(3) = 35.25 Log likelihood = -110.26736 Prob > chi2 = 0.0000 ------------------------------------------------------------------------------ | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- eq1 | drug2 | 1.012966 .2903917 3.49 0.000 .4438086 1.582123 drug3 | 1.45917 .2821196 5.17 0.000 .9062261 2.012114 age | -.0671728 .0205688 -3.27 0.001 -.1074868 -.0268587 _cons | 6.060723 1.152845 5.26 0.000 3.801188 8.320259 -------------+---------------------------------------------------------------- eq2 | _cons | .5573333 .1402154 3.97 0.000 .2825162 .8321504 ------------------------------------------------------------------------------ . ml graph . . ml model lf myweib (studytime died =drug2 drug3 age) /sigma /* An alternative way to specify the s > econd equation*/ . ml maximize initial: log likelihood = -744 alternative: log likelihood = -356.14276 rescale: log likelihood = -200.80201 rescale eq: log likelihood = -136.69232 Iteration 0: log likelihood = -136.69232 (not concave) Iteration 1: log likelihood = -124.12938 Iteration 2: log likelihood = -113.93256 Iteration 3: log likelihood = -110.30796 Iteration 4: log likelihood = -110.26748 Iteration 5: log likelihood = -110.26736 Iteration 6: log likelihood = -110.26736 Number of obs = 48 Wald chi2(3) = 35.25 Log likelihood = -110.26736 Prob > chi2 = 0.0000 ------------------------------------------------------------------------------ | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- eq1 | drug2 | 1.012966 .2903917 3.49 0.000 .4438086 1.582123 drug3 | 1.45917 .2821195 5.17 0.000 .9062261 2.012114 age | -.0671728 .0205688 -3.27 0.001 -.1074868 -.0268587 _cons | 6.060723 1.152845 5.26 0.000 3.801188 8.320259 -------------+---------------------------------------------------------------- sigma | _cons | .5573333 .1402154 3.97 0.000 .2825162 .8321504 ------------------------------------------------------------------------------ . . ml model lf myweib (studytime died =drug2 drug3 age) /s /* Another equivalent way to specify t > he second equation*/ . ml maximize initial: log likelihood = -744 alternative: log likelihood = -356.14276 rescale: log likelihood = -200.80201 rescale eq: log likelihood = -136.69232 Iteration 0: log likelihood = -136.69232 (not concave) Iteration 1: log likelihood = -124.12938 Iteration 2: log likelihood = -113.93256 Iteration 3: log likelihood = -110.30796 Iteration 4: log likelihood = -110.26748 Iteration 5: log likelihood = -110.26736 Iteration 6: log likelihood = -110.26736 Number of obs = 48 Wald chi2(3) = 35.25 Log likelihood = -110.26736 Prob > chi2 = 0.0000 ------------------------------------------------------------------------------ | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- eq1 | drug2 | 1.012966 .2903917 3.49 0.000 .4438086 1.582123 drug3 | 1.45917 .2821195 5.17 0.000 .9062261 2.012114 age | -.0671728 .0205688 -3.27 0.001 -.1074868 -.0268587 _cons | 6.060723 1.152845 5.26 0.000 3.801188 8.320259 -------------+---------------------------------------------------------------- s | _cons | .5573333 .1402154 3.97 0.000 .2825162 .8321504 ------------------------------------------------------------------------------ . . ********************************************************************** . * another example of two equations, two dependent variables model * . ********************************************************************** . . use auto.dta,clear (1978 Automobile Data) . capture program drop myreg1 . program myreg1 1. version 8.0 2. args lnf theta1 theta2 3. quietly replace `lnf' = ln(normd(($ML_y1-`theta1')/`theta2'))-ln(`theta2') 4. end . . ml model lf myreg1 (mpg =weight displ) (price=weight) /* the second dependent variable is price which > depends on weight and constant*/ . ml maximize initial: log likelihood = - (could not be evaluated) feasible: log likelihood = -10383.274 rescale: log likelihood = -292.89564 rescale eq: log likelihood = -238.45986 Iteration 0: log likelihood = -238.45986 (not concave) Iteration 1: log likelihood = -223.70178 (not concave) Iteration 2: log likelihood = -208.95405 Iteration 3: log likelihood = -195.25115 Iteration 4: log likelihood = -190.48052 Iteration 5: log likelihood = -190.19891 Iteration 6: log likelihood = -190.19848 Iteration 7: log likelihood = -190.19848 Number of obs = 74 Wald chi2(2) = 140.31 Log likelihood = -190.19848 Prob > chi2 = 0.0000 ------------------------------------------------------------------------------ | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- eq1 | weight | -.0060495 .0011241 -5.38 0.000 -.0082526 -.0038463 displacement | .0052541 .008891 0.59 0.555 -.0121718 .0226801 _cons | 38.47725 2.095853 18.36 0.000 34.36946 42.58505 -------------+---------------------------------------------------------------- eq2 | weight | -.0009508 .0002892 -3.29 0.001 -.0015176 -.000384 _cons | 6.122385 1.026743 5.96 0.000 4.110006 8.134763 ------------------------------------------------------------------------------ . . ml model lf myreg1 (mpg price=weight displ) (weight) /* an equivalent specification*/ . ml maximize initial: log likelihood = - (could not be evaluated) feasible: log likelihood = -10383.274 rescale: log likelihood = -292.89564 rescale eq: log likelihood = -238.45986 Iteration 0: log likelihood = -238.45986 (not concave) Iteration 1: log likelihood = -223.70178 (not concave) Iteration 2: log likelihood = -208.95405 Iteration 3: log likelihood = -195.25115 Iteration 4: log likelihood = -190.48052 Iteration 5: log likelihood = -190.19891 Iteration 6: log likelihood = -190.19848 Iteration 7: log likelihood = -190.19848 Number of obs = 74 Wald chi2(2) = 140.31 Log likelihood = -190.19848 Prob > chi2 = 0.0000 ------------------------------------------------------------------------------ | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- eq1 | weight | -.0060495 .0011241 -5.38 0.000 -.0082526 -.0038463 displacement | .0052541 .008891 0.59 0.555 -.0121718 .0226801 _cons | 38.47725 2.095853 18.36 0.000 34.36946 42.58505 -------------+---------------------------------------------------------------- eq2 | weight | -.0009508 .0002892 -3.29 0.001 -.0015176 -.000384 _cons | 6.122385 1.026743 5.96 0.000 4.110006 8.134763 ------------------------------------------------------------------------------ . . ml model lf myreg1 (mpg =weight displ) (price=weight, nocons) /* the second dependent variable depends > only on weight*/ . ml maximize initial: log likelihood = - (could not be evaluated) feasible: log likelihood = -4207.6269 rescale: log likelihood = -289.15681 rescale eq: log likelihood = -257.89841 Iteration 0: log likelihood = -257.89841 (not concave) Iteration 1: log likelihood = -245.15079 (not concave) Iteration 2: log likelihood = -237.96905 (not concave) Iteration 3: log likelihood = -230.45037 Iteration 4: log likelihood = -214.59618 Iteration 5: log likelihood = -210.80852 Iteration 6: log likelihood = -210.75623 Iteration 7: log likelihood = -210.75609 Iteration 8: log likelihood = -210.75609 Number of obs = 74 Wald chi2(2) = 106.26 Log likelihood = -210.75609 Prob > chi2 = 0.0000 ------------------------------------------------------------------------------ | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- eq1 | weight | -.0068679 .0012348 -5.56 0.000 -.0092881 -.0044477 displacement | .003304 .0109685 0.30 0.763 -.018194 .0248019 _cons | 41.33294 2.017912 20.48 0.000 37.3779 45.28797 -------------+---------------------------------------------------------------- eq2 | weight | .0014306 .0001175 12.18 0.000 .0012004 .0016609 ------------------------------------------------------------------------------ . . ml model lf myreg1 (mpg price=weight displ) (weight, nocons) /* an equivalent specification of the re > stricted model*/ . ml maximize initial: log likelihood = - (could not be evaluated) feasible: log likelihood = -4207.6269 rescale: log likelihood = -289.15681 rescale eq: log likelihood = -257.89841 Iteration 0: log likelihood = -257.89841 (not concave) Iteration 1: log likelihood = -245.15079 (not concave) Iteration 2: log likelihood = -237.96905 (not concave) Iteration 3: log likelihood = -230.45037 Iteration 4: log likelihood = -214.59618 Iteration 5: log likelihood = -210.80852 Iteration 6: log likelihood = -210.75623 Iteration 7: log likelihood = -210.75609 Iteration 8: log likelihood = -210.75609 Number of obs = 74 Wald chi2(2) = 106.26 Log likelihood = -210.75609 Prob > chi2 = 0.0000 ------------------------------------------------------------------------------ | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- eq1 | weight | -.0068679 .0012348 -5.56 0.000 -.0092881 -.0044477 displacement | .003304 .0109685 0.30 0.763 -.018194 .0248019 _cons | 41.33294 2.017912 20.48 0.000 37.3779 45.28797 -------------+---------------------------------------------------------------- eq2 | weight | .0014306 .0001175 12.18 0.000 .0012004 .0016609 ------------------------------------------------------------------------------ . . ml model lf myreg1 (mpg =weight displ) (price=) /* the second dependent varible is a constant, i > n this case > the model degenerates into one dependent vari > able model*/ . ml maximize initial: log likelihood = - (could not be evaluated) feasible: log likelihood = -10383.274 rescale: log likelihood = -292.89564 rescale eq: log likelihood = -238.45986 Iteration 0: log likelihood = -238.45986 (not concave) Iteration 1: log likelihood = -225.48338 (not concave) Iteration 2: log likelihood = -215.65944 Iteration 3: log likelihood = -199.17981 Iteration 4: log likelihood = -195.29821 Iteration 5: log likelihood = -195.24 Iteration 6: log likelihood = -195.2398 Iteration 7: log likelihood = -195.2398 Number of obs = 74 Wald chi2(2) = 139.21 Log likelihood = -195.2398 Prob > chi2 = 0.0000 ------------------------------------------------------------------------------ | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- eq1 | weight | -.0065671 .0011424 -5.75 0.000 -.0088061 -.0043281 displacement | .0052808 .0096674 0.55 0.585 -.0136671 .0242286 _cons | 40.08452 1.978738 20.26 0.000 36.20627 43.96278 -------------+---------------------------------------------------------------- eq2 | _cons | 3.385282 .2782684 12.17 0.000 2.839886 3.930678 ------------------------------------------------------------------------------ . . ml model lf myreg1 (mpg =weight displ)/s /* an equivalent specification of the one depend > ent variable model*/ . ml maximize initial: log likelihood = - (could not be evaluated) feasible: log likelihood = -10383.274 rescale: log likelihood = -292.89564 rescale eq: log likelihood = -238.45986 Iteration 0: log likelihood = -238.45986 (not concave) Iteration 1: log likelihood = -225.48338 (not concave) Iteration 2: log likelihood = -215.65944 Iteration 3: log likelihood = -199.17981 Iteration 4: log likelihood = -195.29821 Iteration 5: log likelihood = -195.24 Iteration 6: log likelihood = -195.2398 Iteration 7: log likelihood = -195.2398 Number of obs = 74 Wald chi2(2) = 139.21 Log likelihood = -195.2398 Prob > chi2 = 0.0000 ------------------------------------------------------------------------------ mpg | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- eq1 | weight | -.0065671 .0011424 -5.75 0.000 -.0088061 -.0043281 displacement | .0052808 .0096674 0.55 0.585 -.0136671 .0242286 _cons | 40.08452 1.978738 20.26 0.000 36.20627 43.96278 -------------+---------------------------------------------------------------- s | _cons | 3.385282 .2782684 12.17 0.000 2.839886 3.930678 ------------------------------------------------------------------------------ . . end of do-file . exit, clear