. * replace here means existing file of same name will be overwritten . * and if this file is already open then give command log close . . . ********** MEMORY MANAGEMENT . * . set maxvar 100 width 1000 (maxvar and maxobs no longer need be set with this version of Stata) . * If need more memory then in Stata give command help memory . . . ********** READ DATA . * . * If data are already loaded in Stata you need to first give the command . * clear . * . * The data are in ascii file jaggia.asc . * There are 126 observations on 12 variables with three lines per obs . * The data are fixed format with . * line 1 variables 1-4 F16.8,F17.9,F17.9,F17.9 . * line 2 variables 5-8 F16.8,F17.9,F17.9,F17.9, . * line 3 variables 9-12 F16.8,F17.9,F17.9,F17.9, . * There are several ways to read in this data as these data also free format. . * . * METHOD 1: Infile: FIXED FORMAT WITH LENGTHY DICTIONARY . infile using jaggia.dct dictionary using jaggia.asc { _column(1) docno %16.8f "Document Number" _column(17) weeks %17.8f "Weeks" _column(34) numbids %17.8f "Number of takeover bids (after the first)" _column(51) takeover %17.8f "1 if takeover occurred, 0 otherwise" _newline _column(1) bidprem %16.8f "Bid price / price 14 work days before bid" _column(17) insthold %17.8f "Percentage of stock held by insitutions" _column(34) size %17.8f "Total book value of assets inb $billions " _column(51) leglrest %17.8f "Equals one if legal defense by lawsuit" _newline _column(1) realrest %16.8f "One if proposed changes in asset structure" _column(17) finrest %17.8f "One if proposed changes in ownership struc" _column(34) regulatn %17.8f "One if intervention by fed regulators" _column(57) whtknght %17.8f "One if mgmt invite friendly 3rd-party bid" * For this example the column numbers are redundant. * Also the long labels need not be given. } (126 observations read) . * . * This provides more detail than necessary to read in data. . * You need to create a separate file jaggia.dct withs the following lines: . * dictionary using jaggia.asc { . * _column(1) docno %16f8 "Document Number" . * _column(17) weeks %17f8 "Weeks" . * _column(34) numbids %17f8 "Number of takeover bids (after the first)" . * _column(51) takeover %17f8 "1 if takeover occurred, 0 otherwise" . * _newline . * _column(1) bidprem %16f8 "Bid price / price 14 work days before bid" . * _column(17) insthold %17f8 "Percentage of stock held by insitutions" . * _column(34) size %17f8 "Total book value of assets inb $billions " . * _column(51) leglrest %17f8 "Equals one if legal defense by lawsuit" . * _newline . * _column(1) realrest %16f8 "One if proposed changes in asset structure" . * _column(17) finrest %17f8 "One if proposed changes in ownership struc" . * _column(34) regulatn %17f8 "Oone if intervention by fed regulators" . * _column(57) whtknght %17f8 "One if mgmt invite friendly 3rd-party bid" . * } . * . * METHOD 2: Infile: FREE FORMAT WITH BRIEF DICTIONARY . * infile using jaggia2.dct . * . * You need to create a separate file jaggia2.dct withs the following lines: . * dictionary using jaggia.asc { . * docno weeks numbids takeover . * _newline . * bidprem insthold size leglrest . * _newline . * realrest finrest regulatn whtknght . * } . * . * METHOD 3: 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 . * . * To drop off extra blanks (if any) at end of file jaggia.asc . drop if _n>126 (0 observations deleted) . * . * If your data have special missing value codes see the Stata manual. . . . ********** DATA TRANSFORMATIONS . gen sizesq = size*size . label variable sizesq "size squared" . . . ******** CHECK DATA: DESCRIPTIVE STATISTICS . * . * The following lists the variables in data set . describe Contains data obs: 126 vars: 13 size: 7,056 (99.2% of memory free) ------------------------------------------------------------------------------- 1. docno float %9.0g Document Number 2. weeks float %9.0g Weeks 3. numbids float %9.0g Number of takeover bids (after the first) 4. takeover float %9.0g 1 if takeover occurred, 0 otherwise 5. bidprem float %9.0g Bid price / price 14 work days before bid 6. insthold float %9.0g Percentage of stock held by insitutions 7. size float %9.0g Total book value of assets inb $billions 8. leglrest float %9.0g Equals one if legal defense by lawsuit 9. realrest float %9.0g One if proposed changes in asset structure 10. finrest float %9.0g One if proposed changes in ownership struc 11. regulatn float %9.0g One if intervention by fed regulators 12. whtknght float %9.0g One if mgmt invite friendly 3rd-party bid 13. sizesq float %9.0g size squared ------------------------------------------------------------------------------- Sorted by: Note: dataset has changed since last saved . * . * The following should always be used to check data correctly read in . * It gives number of observations, meaan, standard deviation, min and max . * For all variables in the data set . 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 . * And to get more detail such as quantiles use the d option . * summarize, d . . . ******** SAVE DATA AS STATA DATA SET . . save jaggia, replace file jaggia.dta saved . . . ********** OLS REGRESSION . * . regress numbids leglrest realrest finrest whtknght bidprem insthold size /* > */ sizesq regulatn Source | SS df MS Number of obs = 126 ---------+------------------------------ F( 9, 116) = 4.01 Model | 60.8336144 9 6.75929048 Prob > F = 0.0002 Residual | 195.523528 116 1.68554766 R-squared = 0.2373 ---------+------------------------------ Adj R-squared = 0.1781 Total | 256.357143 125 2.05085714 Root MSE = 1.2983 ------------------------------------------------------------------------------ numbids | Coef. Std. Err. t P>|t| [95% Conf. Interval] ---------+-------------------------------------------------------------------- leglrest | .4560416 .2564168 1.779 0.078 -.0518241 .9639074 realrest | -.386424 .3368528 -1.147 0.254 -1.053603 .2807553 finrest | .1314257 .3965438 0.331 0.741 -.6539792 .9168307 whtknght | .759148 .2470734 3.073 0.003 .269788 1.248508 bidprem | -1.173247 .6275882 -1.869 0.064 -2.416265 .0697702 insthold | -.5689557 .6986462 -0.814 0.417 -1.952712 .8148011 size | .3966998 .1244471 3.188 0.002 .1502168 .6431829 sizesq | -.0166721 .0062429 -2.671 0.009 -.029037 -.0043072 regulatn | -.0222786 .2779142 -0.080 0.936 -.5727226 .5281655 _cons | 2.576962 .8925073 2.887 0.005 .8092387 4.344685 ------------------------------------------------------------------------------ . * Here as command spans more than one line use /* and */ . . . ********** POISSON REGRESSION . * . poisson numbids leglrest realrest finrest whtknght bidprem insthold size /* > */ sizesq regulatn Iteration 0: log likelihood = -184.9518 Iteration 1: log likelihood = -184.94833 Iteration 2: log likelihood = -184.94833 Poisson regression Number of obs = 126 LR chi2(9) = 33.25 Prob > chi2 = 0.0001 Log likelihood = -184.94833 Pseudo R2 = 0.0825 ------------------------------------------------------------------------------ numbids | Coef. Std. Err. z P>|z| [95% Conf. Interval] ---------+-------------------------------------------------------------------- leglrest | .2601464 .1509594 1.723 0.085 -.0357286 .5560213 realrest | -.1956597 .1926309 -1.016 0.310 -.5732093 .1818899 finrest | .07403 .2165219 0.342 0.732 -.3503452 .4984053 whtknght | .4813822 .1588698 3.030 0.002 .170003 .7927613 bidprem | -.6776959 .3767373 -1.799 0.072 -1.416087 .0606956 insthold | -.3619913 .4243292 -0.853 0.394 -1.193661 .4696788 size | .1785026 .0600221 2.974 0.003 .0608614 .2961438 sizesq | -.0075693 .0031217 -2.425 0.015 -.0136878 -.0014509 regulatn | -.0294392 .1605682 -0.183 0.855 -.344147 .2852686 _cons | .9860599 .5339202 1.847 0.065 -.0604044 2.032524 ------------------------------------------------------------------------------ . * Here as command spans more than one line use /* and */ . . . ********** USE OUTPUT FROM e.g. POISSON REGRESSION . * . * For post-regression output see Stata 6 [U] chapter 23 and 16 . * For matrices see Stata 6 [U] chapter 17 and [R] matrix . * Same results can be stored in more than one plass e.g. . . * Following gives list of where regression output is saved . estimates list scalars: e(rc) = 0 e(ll) = -184.9483264202831 e(ll_0) = -201.5715960914247 e(df_m) = 9 e(chi2) = 33.2465393422832 e(p) = .0001209739913648 e(k) = 10 e(k_eq) = 1 e(k_dv) = 1 e(ic) = 2 e(N) = 126 e(r2_p) = .0824683139563074 macros: e(cmd) : "poisson" e(predict) : "poisso_p" e(gof) : "poiss_g" e(opt) : "ml" e(title) : "Poisson regression" e(depvar) : "numbids" e(user) : "poiss_lf" e(chi2type) : "LR" matrices: e(b) : 1 x 10 e(V) : 10 x 10 e(ilog) : 1 x 20 functions: e(sample) . . * Following displays key regression output . estimates display ------------------------------------------------------------------------------ numbids | Coef. Std. Err. z P>|z| [95% Conf. Interval] ---------+-------------------------------------------------------------------- numbids | leglrest | .2601464 .1509594 1.723 0.085 -.0357286 .5560213 realrest | -.1956597 .1926309 -1.016 0.310 -.5732093 .1818899 finrest | .07403 .2165219 0.342 0.732 -.3503452 .4984053 whtknght | .4813822 .1588698 3.030 0.002 .170003 .7927613 bidprem | -.6776959 .3767373 -1.799 0.072 -1.416087 .0606956 insthold | -.3619913 .4243292 -0.853 0.394 -1.193661 .4696788 size | .1785026 .0600221 2.974 0.003 .0608614 .2961438 sizesq | -.0075693 .0031217 -2.425 0.015 -.0136878 -.0014509 regulatn | -.0294392 .1605682 -0.183 0.855 -.344147 .2852686 _cons | .9860599 .5339202 1.847 0.065 -.0604044 2.032524 ------------------------------------------------------------------------------ . . * Following obtains prediction of y at the mean of x . * Command predict with xb option (default) gives x'bhat . predict poissxb, xb . * and to get the vector of predicted means take exponential . gen poissmu = exp(poissxb) . . * Following obtains the fitted log-likelihood for Poisson . scalar llfpoiss = $S_E_ll . di "llfpoiss = " llfpoiss llfpoiss = -184.94833 . . * The following saves the coefficient estimates in a vector . matrix bpoiss = get(_b) /* Poisson coefficient vector */ . matrix list bpoiss /* List this vector */ bpoiss[1,10] numbids: numbids: numbids: numbids: numbids: numbids: leglrest realrest finrest whtknght bidprem insthold y1 .26014637 -.19565973 .07403005 .48138216 -.67769586 -.36199125 numbids: numbids: numbids: numbids: size sizesq regulatn _cons y1 .17850259 -.00756935 -.02943918 .98605988 . . * The following saves the cariance matrix and converts to standard errors . matrix vmpoiss = get(VCE) . * Following creates a row vector (not a cloumn vector) . matrix vpoiss = vecdiag(vmpoiss) . matrix list vpoiss vpoiss[1,10] numbids: numbids: numbids: numbids: numbids: numbids: leglrest realrest finrest whtknght bidprem insthold r1 .02278874 .03710666 .04688175 .02523962 .14193097 .1800553 numbids: numbids: numbids: numbids: size sizesq regulatn _cons r1 .00360265 9.745e-06 .02578214 .28507076 . scalar colsvp = colsof(vpoiss) /* Row vector of variances */ . * matrix list rowsvp . matrix sepoiss = J(1,colsvp,0) /* Row vector of zeroes */ . matrix list sepoiss sepoiss[1,10] c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 r1 0 0 0 0 0 0 0 0 0 0 . scalar icol = 1 . /* Need loop here as Stata does not do square root on a vector */ . while icol <= colsvp { 2. matrix sepoiss[1,icol] = sqrt(vpoiss[1,icol]) 3. scalar icol = icol+1 4. } . matrix list sepoiss sepoiss[1,10] c1 c2 c3 c4 c5 c6 r1 .15095939 .19263088 .21652194 .15886982 .37673727 .42432924 c7 c8 c9 c10 r1 .0600221 .0031217 .16056816 .53392018 . . . ********** USE MAXIMUM LIKELIHOOD COMMANDS ML . * . * This is much harder . * See program stmle.do . . . ********** CLOSE OUTPUT . log close