
Click «Format» - «Column Width» again and enter the value suggested by the program (as a rule, it's 8.43 – the number of characters in the Calibri font, size 11 pt). Select any cell in the column that needs to go back to the initial size. Click «Format» - « AutoFit Row Width» Memorize this number. To bring the rows to their initial boundaries, open the tool menu: «HOME»-«Format» and choose «AutoFit Row Height». However, it works only if used immediately. To go back to the previous size, you can press the «Undo Typing» button or the hot-key combination CTRL+Z. To change the column width and the row height in a certain range, resize 1 column/row (by dragging its boundaries manually) – and all the selected columns and rows will be resized automatically.
#Excel tables with stata 12 how to#
list, clean nolabelĪnd that’s how to read data from multiple sheets from Excel into Stata.Creating a table in Excel: a dummy's guide When you run the do-file you end up with a dataset Option to indicate that the first row contains the variable names. Values, B2, which indicates the upper left-hand starting location to begin reading the data. This time the cellrange option has just a single The sheet and clear options are the same as before. Here is the second import excel command: import excel using hospital.xls, /// The clear option clears out any data already in memory. In this case, indicates that we want to read a single cell (cell A1). Of course, indicates which Sheet (1 thru 4) that we want to read. The first one looks like this: import excel using hospital.xls, /// The two import excel commands are worth commenting on in detail. Save hospital, replace /* final save of the data */ Order hname hnum /* reorder data placing hospital name first */
#Excel tables with stata 12 code#
Generate str12 hname = "`hname'" /* create variable with hospital name */Įncode hname, gen(hnum) /* create numeric hospital code */ Sheet(Sheet`i') cellrange(B2) firstrow clear Local hname = A /* local macro with hospital name */ * capture the hospital name from cell A1 */ * loop thru each of the Sheets beginning with Sheet4 */ * do-file code to read Excel spreadsheets */ Then we want to append the data from each of the hospitals together into a single Stata data file.Īdditionally, we want to create a numeric variable that codes the hospital name. We want to capture the hospital name and add to each row of theĭata. What we want to do with the Sheets in this Excel file. Here is a sample of whatĪs you can see, the hospital is Santa Monica and the variable names are x, y and z. In cellsī2:D5 are the data for each hospital. The file, hospital.xls, has four Sheets each with the same format. To illustrate how this is accomplished we have an Excel file The sheet() option allows us top specify from which sheet of the spreadsheet we want to read, and by appending the data together, we can read data from multiple sheets. xlsx) filesĭirectly using the import excel command. Beginning in Stata 12 you can read Excel (.xls and.
