. di "stmlogit.do by Colin Cameron: Stata logit example" stmlogit.do by Colin Cameron: Stata logit example . . . ********** ADJUSTMENTS FOR LARGER SIZE PROBLEMS . set maxvar 100 width 1000 (maxvar and maxobs no longer need be set with this version of Stata) . set matsize 100 . . . ********** READ DATA . * You need file jaggia.asc in your directory . * Infile: FREE FORMAT WITHOUT DICTIONARY . * As there is space between each observation data is also space-delimited . * free format and then there is no need for a dictionary file . * The following command spans more that one line so use /* and */ . . infile docno weeks numbids takeover bidprem insthold size leglrest /* > */ realrest finrest regulatn whtknght using jaggia.asc (126 observations read) . . . ********** DATA TRANSFORMATIONS . gen sizesq = size*size . label variable sizesq "size squared" . . * Code numbids data as 1 or 0 for binary logit . gen dbids=numbids>0 /* equals 1 if numbids>0 and 0 otherwise */ . . * Code numbids data as 1, 2 or 3 for Stata mlogit . * Here y=1 will be numbids=0 . * y=2 will be numbids=1 . * y=3 will be numbids=2 or more . gen ybids = numbids + 1 . replace ybids = 3 if ybids>3 (23 real changes made) . /* use replace here as modifying existing variable */ . . . ******** CHECK DATA: DESCRIPTIVE STATISTICS . describe Contains data obs: 126 vars: 15 size: 8,064 (99.2% of memory free) ------------------------------------------------------------------------------- 1. docno float %9.0g 2. weeks float %9.0g 3. numbids float %9.0g 4. takeover float %9.0g 5. bidprem float %9.0g 6. insthold float %9.0g 7. size float %9.0g 8. leglrest float %9.0g 9. realrest float %9.0g 10. finrest float %9.0g 11. regulatn float %9.0g 12. whtknght float %9.0g 13. sizesq float %9.0g size squared 14. dbids float %9.0g 15. ybids float %9.0g ------------------------------------------------------------------------------- Sorted by: Note: dataset has changed since last saved . summarize Variable | Obs Mean Std. Dev. Min Max ---------+----------------------------------------------------- docno | 126 82174.41 2251.783 78001 85059 weeks | 126 11.44898 7.711424 2.857 41.429 numbids | 126 1.738095 1.432081 0 10 takeover | 126 1 0 1 1 bidprem | 126 1.346806 .189325 .9426754 2.066366 insthold | 126 .2518175 .1856136 0 .904 size | 126 1.219031 3.096624 .017722 22.169 leglrest | 126 .4285714 .4968472 0 1 realrest | 126 .1825397 .3878308 0 1 finrest | 126 .1031746 .3054011 0 1 regulatn | 126 .2698413 .4456492 0 1 whtknght | 126 .5952381 .4928054 0 1 sizesq | 126 10.99902 59.91479 .0003141 491.4646 dbids | 126 .9285714 .2585675 0 1 ybids | 126 2.357143 .6127223 1 3 . . . * Full regressor set is . * regress dbids leglrest realrest finrest whtknght /* > * */ bidprem insthold size sizesq regulatn . * where use /* and */ as command spans two lines . . * Here have only BIDPREM as regressor for simplicity . . . ****************** REGRESSIONS FOR 0, 1 DATA ******************* . . . *** OLS REGRESSION . regress dbids bidprem Source | SS df MS Number of obs = 126 ---------+------------------------------ F( 1, 124) = 0.24 Model | .01626326 1 .01626326 Prob > F = 0.6238 Residual | 8.3408796 124 .067265158 R-squared = 0.0019 ---------+------------------------------ Adj R-squared = -0.0061 Total | 8.35714286 125 .066857143 Root MSE = .25936 ------------------------------------------------------------------------------ dbids | Coef. Std. Err. t P>|t| [95% Conf. Interval] ---------+-------------------------------------------------------------------- bidprem | .0602478 .1225271 0.492 0.624 -.1822677 .3027632 _cons | .8474294 .16663 5.086 0.000 .517622 1.177237 ------------------------------------------------------------------------------ . * Same regression with robust standard errors . regress dbids bidprem, robust Regression with robust standard errors Number of obs = 126 F( 1, 124) = 0.39 Prob > F = 0.5323 R-squared = 0.0019 Root MSE = .25936 ------------------------------------------------------------------------------ | Robust dbids | Coef. Std. Err. t P>|t| [95% Conf. Interval] ---------+-------------------------------------------------------------------- bidprem | .0602478 .0962031 0.626 0.532 -.1301651 .2506606 _cons | .8474294 .1360336 6.230 0.000 .5781808 1.116678 ------------------------------------------------------------------------------ . predict pols (option xb assumed; fitted values) . . . *** PROBIT REGRESSION . probit dbids bidprem Iteration 0: log likelihood = -32.422149 Iteration 1: log likelihood = -32.287958 Iteration 2: log likelihood = -32.287481 Iteration 3: log likelihood = -32.287481 Probit estimates Number of obs = 126 LR chi2(1) = 0.27 Prob > chi2 = 0.6038 Log likelihood = -32.287481 Pseudo R2 = 0.0042 ------------------------------------------------------------------------------ dbids | Coef. Std. Err. z P>|z| [95% Conf. Interval] ---------+-------------------------------------------------------------------- bidprem | .4929145 .9650653 0.511 0.610 -1.398579 2.384408 _cons | .807549 1.291257 0.625 0.532 -1.723268 3.338366 ------------------------------------------------------------------------------ . * Next reports dF/dx rather than betas . dprobit dbids bidprem Iteration 0: log likelihood = -32.422149 Iteration 1: log likelihood = -32.287958 Iteration 2: log likelihood = -32.287481 Iteration 3: log likelihood = -32.287481 Probit estimates Number of obs = 126 LR chi2(1) = 0.27 Prob > chi2 = 0.6038 Log likelihood = -32.287481 Pseudo R2 = 0.0042 ------------------------------------------------------------------------------ dbids | dF/dx Std. Err. z P>|z| x-bar [ 95% C.I. ] ---------+-------------------------------------------------------------------- bidprem | .0666113 .1295583 0.51 0.610 1.34681 -.187318 .320541 ---------+-------------------------------------------------------------------- obs. P | .9285714 pred. P | .9294098 (at x-bar) ------------------------------------------------------------------------------ z and P>|z| are the test of the underlying coefficient being 0 . * Calculate predicted probability that y=1 for each person in the sample . predict pprobit (option p assumed; Pr(dbids)) . . . *** LOGIT REGRESSION . logit dbids bidprem Iteration 0: log likelihood = -32.422149 Iteration 1: log likelihood = -32.295467 Iteration 2: log likelihood = -32.294406 Iteration 3: log likelihood = -32.294406 Logit estimates Number of obs = 126 LR chi2(1) = 0.26 Prob > chi2 = 0.6132 Log likelihood = -32.294406 Pseudo R2 = 0.0039 ------------------------------------------------------------------------------ dbids | Coef. Std. Err. z P>|z| [95% Conf. Interval] ---------+-------------------------------------------------------------------- bidprem | .9663924 1.95132 0.495 0.620 -2.858124 4.790909 _cons | 1.277133 2.596833 0.492 0.623 -3.812566 6.366832 ------------------------------------------------------------------------------ . * Calculate predicted probability that y=1 for each person in the sample . predict plogit (option p assumed; Pr(dbids)) . . . *** COMPARE PREDICTED PROBABILITIES ACROSS MODELS . summarize dbids pols pprobit plogit Variable | Obs Mean Std. Dev. Min Max ---------+----------------------------------------------------- dbids | 126 .9285714 .2585675 0 1 pols | 126 .9285714 .0114064 .9042234 .9719233 pprobit | 126 .92857 .0120912 .8983503 .9660817 plogit | 126 .9285714 .0115037 .8991783 .9635279 . . . ****************** REGRESSIONS FOR 0, 1, 2 DATA **************** . . . *** MULTINOMIAL LOGIT REGRESSION . mlogit ybids bidprem, base(1) Iteration 0: log likelihood = -113.17387 Iteration 1: log likelihood = -109.95111 Iteration 2: log likelihood = -109.93262 Iteration 3: log likelihood = -109.93261 Multinomial regression Number of obs = 126 LR chi2(2) = 6.48 Prob > chi2 = 0.0391 Log likelihood = -109.93261 Pseudo R2 = 0.0286 ------------------------------------------------------------------------------ ybids | Coef. Std. Err. z P>|z| [95% Conf. Interval] ---------+-------------------------------------------------------------------- 2 | bidprem | 2.128291 2.076001 1.025 0.305 -1.940597 6.197179 _cons | -.9291773 2.772749 -0.335 0.738 -6.363665 4.50531 ---------+-------------------------------------------------------------------- 3 | bidprem | -.4823504 2.114099 -0.228 0.820 -4.625908 3.661207 _cons | 2.423579 2.802771 0.865 0.387 -3.069751 7.916909 ------------------------------------------------------------------------------ (Outcome ybids==1 is the comparison group) . * Calculate predicted probability that y=1, 2 or 3 for each person in the sam > ple . predict p1mlogit p2mlogit p3mlogit (option p assumed; predicted probabilities) . summarize ybids dbids p1mlogit p2mlogit p3mlogit Variable | Obs Mean Std. Dev. Min Max ---------+----------------------------------------------------- ybids | 126 2.357143 .6127223 1 3 dbids | 126 .9285714 .2585675 0 1 p1mlogit | 126 .0714286 .0114713 .0268391 .0900996 p2mlogit | 126 .5 .1115048 .2645489 .8613591 p3mlogit | 126 .4285714 .1001529 .1118018 .6453515 . . . *** ORDERED LOGIT REGRESSION . ologit ybids bidprem, table Iteration 0: log likelihood = -113.17387 Iteration 1: log likelihood = -111.46815 Iteration 2: log likelihood = -111.4643 Iteration 3: log likelihood = -111.4643 Ordered logit estimates Number of obs = 126 LR chi2(1) = 3.42 Prob > chi2 = 0.0644 Log likelihood = -111.4643 Pseudo R2 = 0.0151 ------------------------------------------------------------------------------ ybids | Coef. Std. Err. z P>|z| [95% Conf. Interval] ---------+-------------------------------------------------------------------- bidprem | -1.692962 .9288622 -1.823 0.068 -3.513498 .1275747 ---------+-------------------------------------------------------------------- _cut1 | -4.902893 1.34265 (Ancillary parameters) _cut2 | -1.994982 1.262441 ------------------------------------------------------------------------------ ybids | Probability Observed ---------|------------------------------------- 1 | Pr( xb+u<_cut1) 0.0714 2 | Pr(_cut1 ple . predict p1ologit p2ologit p3ologit (option p assumed; predicted probabilities) . summarize ybids dbids p1ologit p2ologit p3ologit Variable | Obs Mean Std. Dev. Min Max ---------+----------------------------------------------------- ybids | 126 2.357143 .6127223 1 3 dbids | 126 .9285714 .2585675 0 1 p1ologit | 126 .070653 .0241364 .0353325 .1970849 p2ologit | 126 .4980413 .0521523 .3662038 .6209808 p3ologit | 126 .4313058 .0748015 .1819343 .5984637 . . . ****************** REGRESSIONS FOR 0,1,2,... DATA ************** . . . *** OLS REGRESSION for NUMBIDS . regress numbids bidprem, robust Regression with robust standard errors Number of obs = 126 F( 1, 124) = 5.54 Prob > F = 0.0202 R-squared = 0.0284 Root MSE = 1.4173 ------------------------------------------------------------------------------ | Robust numbids | Coef. Std. Err. t P>|t| [95% Conf. Interval] ---------+-------------------------------------------------------------------- bidprem | -1.274282 .5414959 -2.353 0.020 -2.346054 -.2025099 _cons | 3.454306 .7931588 4.355 0.000 1.884423 5.02419 ------------------------------------------------------------------------------ . . . *** POISSON REGRESSION for NUMBIDS . poisson numbids bidprem, robust Iteration 0: log likelihood = -199.39907 Iteration 1: log likelihood = -199.39907 Poisson regression Number of obs = 126 Wald chi2(1) = 5.79 Prob > chi2 = 0.0161 Log likelihood = -199.39907 Pseudo R2 = 0.0108 ------------------------------------------------------------------------------ | Robust numbids | Coef. Std. Err. z P>|z| [95% Conf. Interval] ---------+-------------------------------------------------------------------- bidprem | -.775097 .3220889 -2.406 0.016 -1.40638 -.1438143 _cons | 1.586409 .4520529 3.509 0.000 .7004011 2.472416 ------------------------------------------------------------------------------ . . . *** TOBIT REGRESSION for NUMBIDS . tobit numbids bidprem, ll(0) Tobit estimates Number of obs = 126 LR chi2(1) = 3.02 Prob > chi2 = 0.0825 Log likelihood = -223.12317 Pseudo R2 = 0.0067 ------------------------------------------------------------------------------ numbids | Coef. Std. Err. t P>|t| [95% Conf. Interval] ---------+-------------------------------------------------------------------- bidprem | -1.238909 .7081747 -1.749 0.083 -2.640474 .1626567 _cons | 3.35369 .9633557 3.481 0.001 1.44709 5.260291 ---------+-------------------------------------------------------------------- _se | 1.493248 .0992505 (Ancillary parameter) ------------------------------------------------------------------------------ Obs. summary: 9 left-censored observations at numbids<=0 117 uncensored observations . . . ********** CLOSE OUTPUT . log close