Information, Technology & Consulting

Reading and Converting Data to Stata

Details

How do I read data from an Excel spreadsheet into Stata?

Open your spreadsheet in Excel. Use your mouse to highlight the columns in your spreadsheet you want to copy to Stata. Make sure you highlight complete columns, i.e., do not ignore a header line if one exists (a header line contains variable names). Next, select Copy from the Edit menu in Excel. At this point you can quit Excel but doing so is not required. Start Stata as you normally would. From the command line type edit and you should now see a blank spreadsheet. Select Paste from the Edit menu in Stata, and you should see your data. Close the edit window, and you are done.

How do I save data that I am using to a Stata file?

Select Save or Save As from the Stata File menu. You will be prompted for a directory to save your dataset. Choose the appropriate directory, type a name for the file, and then save the file. To load your dataset, just double-click it. This will start Stata and automatically load your data.

How do I download a Stata .dta file from Canvas? When I click the file I see nonsense characters on the screen.

The problem is that your browser thinks the .dta file is a text file. Right click the file (or Control-Click if using a one-button mouse on a Mac) and save the file to your computer. Ensure the file has the correct .dta suffix; sometimes browsers will add a .txt suffix after a .dta suffix. If the file's suffix is not .dta, rename the file with a .dta suffix.

How do I read an ascii file (usually a .txt or .csv file) into Stata?

Use the insheet command. Let's suppose that the file you want to read is called newdata.txt and is on your Desktop. Click the File menu and choose Select Working Folder. Choose your Desktop as the folder. To see if your ascii file called newdata.txt is indeed in the folder, type ls to list the files in your working directory (which you set to the Desktop). If you do not see the file, then stop and either move the file to your Desktop or select a working folder that contains the file. Now, type insheet using newdata.txt to read the file into Stata. This assumes that the file has a header line.

Can Stata read XML files? If I have an Excel spreadsheet, can I convert it to XML and then have Stata read this?

Steps for converting Excel to XML and then reading XML into Stata:

In Excel:

  1. Open the xls file.
  2. Click File, then Save as.
  3. Under Save as Type, scroll down to the XML spreadsheet.
  4. Click Save.

In Stata:

  1. Click File, then Import, then xml data.
  2. Browse for the file.
  3. For document type, select Excel Spreadsheet.
  4. Check the First Row is Variable Names box.
  5. Click OK.
Topic: 
Research Computing
Subtopic: 
Scientific and Research Software
Last updated: 
Thursday, November 16, 2017

If you have questions or need further information, contact your department's IT support office, or contact the IT Service Desk via email at [email protected], via phone at 603-646-2999 or walk in to see them in Baker/Berry 178J.

Close
Information, Technology & Consulting