** STATA Sample Program by Colin Cameron ** Program stinfile.do October 1999 * To run you need files * jaggia.asc and * jaggia.dct * in your directory * This program demonstrates various ways to read in data into Stata ********** DATA DESCRIPTION * * The original data are from Sanjiv Jaggia and Satish Thosar, 1993, * "Multiple Bids as a Consequence of Target Management Resistance" * Review of Quantitative Finance and Accounting, 447-457. * This is used e.g. in A.C.Cameron and P.K.Trivedi (1998) * "Regression Analysis of Count Data", Cambridge University Press, pp.146-151. * * 1. DOCNO Doc No. * 2. WEEKS Weeks * 3. NUMBIDS Count (Dependent Variable) * 4. TAKEOVER Delta (1 if taken over) * 5. BIDPREM Bid Premium * 6. INSTHOLD Institutional Holdings * 7. SIZE Size measured in billions * 8. LEGLREST Legal Restructuring * 9. REALREST Real Restructuring * 10. FINREST Financial Restructuring * 11. REGULATN Regulation * 12. WHTKNGHT White Knight * and this program will create * 13. SIZESQ Size Squared ********** CLOSE FILES POSSIBLY OPEN FROM PREVIOUS EXECUTION clear capture log close * capture in front means program continues even if no log file open ********** CREATE OUTPUT FILE * log using stinfile.log, replace * replace here means existing file of same name will be overwritten * and if this file is already open then give command log close di "stinfile.do by Colin Cameron: Stata read in data using infile example ********** 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 DEMONSTRATE FOUR WAYS * * Method 1 (used here) will handle the most different types of data * but requires a separate dictionary file to be created * Method 2 is most convenient for fixed format data that is of simple form * Method 3 is for free format data * Method 4 is easier than 3 for free format data * Method 5 is not demonstrated here but works easily for .csv files from a spreadsheet * We use METHOD 1 here * METHOD 1: Infile: FIXED FORMAT WITH LENGTHY DICTIONARY infile using jaggia.dct * 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(51) whtknght %17f8 "One if mgmt invite friendly 3rd-party bid" * } * METHOD 2: Infix: FIXED FORMAT WITHOUT DICTIONARY * infix 3 lines 1: docno 1-16 weeks 17-33 numbids 34-50 takeover 51-67 /* * */ 2: bidprem 1-16 insthold 17-33 size 34-50 leglrest 51-67 /* * */ 3: realrest 1-16 finrest 17-33 regulatn 34-50 whtknght 51-67 /* * */ using jaggia.asc * METHOD 3: 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 4: 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 * * If your data have special missing value codes see the Stata manual. * METHOD 5: Insheet: TEXT FILE CREATED BY SPREADSHEET * If data were in a text file created by a spreadsheet (possibly with headers) * insheet using jaggia.csv * assuming jaggia.csv has been created from spreadsheet ********** DATA TRANSFORMATIONS gen sizesq = size*size label variable sizesq "size squared" ******** CHECK DATA: DESCRIPTIVE STATISTICS * * The following lists the variables in data set describe * * 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 ********** CLOSE OUTPUT log close