. . * 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. . * We use a simple read command here. For more complex reads see stinfile.do . . * 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) . * . * 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 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 ------------------------------------------------------------------------------- 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 ------------------------------------------------------------------------------ . . * As command spans more than one line use /* and */ here . . . ********** CREATE A GRAPH OF DATA . * . * For more details see the separate Stata Manual "Graphics Manual" . . graph numbids bidprem, xlab ylab s(p) c(s) bands(10) saving (stmedb10, replac > e) /* > */ title("Numbids on bidprem: median bands with 10 bands") . . * Detailed explanation follows ... . . * The basic command is graph varlist . * Basic options are xlab, ylab s( ) c( ) . . * varlist with k entries has first (k-1) on y axis and last on x axis . . * The options xlab and ylab lead to rounded values along the y and x axes . . * The option s( ) or symbol( ) chooses the symbol used in the graph . * Default is large circle . * O large circle, S large square, T large triangle . * o small circle, d small diamond, p small plus . * . dot, i invisible, . * [varname] variable to be used as text . * [_n] use obs. no. as symbol . . * The option c( ) or connect( ) connects points on graph . * Default is do not connect . * . do not connect, . * l straight lines between points (most udeful for time series) . * L straight lines between ascending x values . * m connect median bands using straight lines . * s connect median bands using straight lines . * J conect rectilinearly . * || connect two variables vertically (high-low) . * II same as || but cap top and bottom of line . . * The option bands( ) is used with connect median bands c(m) or c(s) . * Median bands regression splits the x axis into #bands bands of equal length > . . * Within each band the cross-median between y and x is computed . * (I think this is simply the point (med(x),med(y)) . * These #bands points are then are either directly connected or connected by > a smooth curve . * using a cubic spline to smooth the points. . * The fewer the #bands the smoother the curve will be. The default is bands(2 > 00) which is too large. . . * The option saving( ) saves the graph with default extension .gph . * It should be used if you want to print out graph later . * It may be needed if you want to see the graph later if use batch in Unix . . * the option title( ) or ti( ) gives a title to the graph . . . ********** PRINT A GRAPH OF DATA . * . * For more details see printing in the separate Stata Manual "Graphics Manual > " . . * Printing in Windows interactively - assumes graph previously saved as npmed > b.gph . . graph using stmedb10.gph . . * Then either: File / Print Graph perhaps Prefs / Graph Preferences first . * or: Edit / Copy Graph to cut and paste as .wmf file into e.g. MS > Word . . * Printing in Unix after batch run - assumes graph previously saved as npmedb > .gph . * Outside stata and in Uix give command gphdot or gphpen . * gphdot supports HP laser printers and dot matrix . * gphpen supports Postscript printers and pen plotters . * This is complicated. Go help stata gphdot for more info and your unix perso > n . * e.g. on Black give command ??? . . * Then either: File / Print Graph perhaps Prefs / Graph Preferences first . * or: Edit / Copy Graph to cut and paste as .wmf file into e.g. MS > Word . . ********** KERNEL REGRESSION . * . * The graph with c(m) or c(s) option does a form of nonparametric regression. . * Better is to use the command ksm, though this is a lot slower than graph. . . * ksm uses lowess or locally weight smoothing. . * Then y_i hat = Sum_j of w_ji times y_j a weighted average of the y_j wher > e . * where the weights w_ji = [1 - (|x_j - x_i|^3)^2 j=imin,..,imax a tricu > be weight . * = 0 j outside imin,imax . * imin = max(1,i-k) where k = n x bwidth-0.5)/2 . * imax = min(i+k,n) . * So in the center a fraction bwidth of the data is used, and less is used in > the tails . * Note this definition of lowess differs from lowess in Hardle (1990, p.192-3 > ) . . * Default is bwidth(0.8) . . ksm numbids bidprem, lowess xlab ylab bwidth(0.9) s(p) saving(stksm09, replac > e)/* > */ title("Numbids on bidprem: lowess with bwidth(0.9)") (Note: file stksm09.gph not found) . . ksm numbids bidprem, lowess xlab ylab bwidth(0.2) s(p) saving(stksm02, replac > e)/* > */ title("Numbids on bidprem: lowess with bwidth(0.2)") (Note: file stksm02.gph not found) . . * To print see print a graph . . . ********** POISSON REGRESSION . * . * Commands such as poisson. logit and probit have similar form to command reg > ress . * Use Poisson here as data are a count . * Should ideally use option ,robust to get better standard errors . * I use the simpler ones as below these are calculated as a Stata matrix comm > ands exercise. . . 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 ------------------------------------------------------------------------------ . . * As command spans more than one line use /* and */ here . . . ********** 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. . * Here the Poisson standard errors assuming a Poisson distribution are calcul > ated. . . * 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