. * 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 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 sp > readsheet . . * We use METHOD 1 here . . * 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(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 (0 observations deleted) . * . * 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 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 . . . ********** CLOSE OUTPUT . log close