Using Stata's -insheet- Command
(by Amy Yuen)

-insheet- is a command designed to read in ASCII text files with delimiters (e.g. a comma or a tab) that separate variables within each row of data. You can see examples of such files here. If your data are fixed-format files, you should instead use the -infix- command, which you can read more about here.

The syntax for using -insheet- is very straightforward. Simply open Stata and type in the command window something along the lines of the following:

insheet using "filename"

Example:

insheet using "C:/patrons/username/wdi-example.txt"



Click here for full-size image

After you enter and execute the command, open up the Data Browser and you should then see something like this:



Click here for full-size image

-insheet- also has certain options to allow for idiosyncrasies of certain files. If we look at the file above, we can see that the variables names were stored in the first line of the original data file and that Stata read these names as being part of the data themselves, which we do not want. However, you can tell Stata to treat the first row of a raw data file as variables names when it reads the dataset into Stata. To do so, just include the "names" option in the command syntax:

Example:
insheet using "C:/patrons/username/wdi-example.txt", names



Click here for full-size image


If we enter this command and then re-open our data in the Data Browser, we will see that the variable names in the original file have now trasnferred over as variable names in the new file, rather than being read in as the first row of data:



Click here for full-size image

Another option with the command concerns identifying the delimiter in the raw data. Usually, delimiters are tabs or commas, but you may encounter files where delimiteres are blank spaces or semi-colons or the like. To help address such situations, -insheet- allows you to specify the delimiter type in the command line by adding the "delimiter" option. Say, for example, that we have a raw datafile which uses a semi-colon as a delimiter. To read data into Stata, we can enter the following command:

insheet using "C:/patrons/username/wdi-example.txt", delimiter(";")



Click here for full-size image


(Be sure to enclose the delimiter in both parentheses and double quotes.)

If we then look at our file in the Data Brower, we should see the following:



Click here for full-size image

For additional options with -insheet-, see the Stata documentation or view the Stata -insheet- help page.


Other Means for Getting Data in Stata:

If your data are in another format (e.g. an Excel file, a fixed-format ASCII file) there are other methods for reading your data into Stata format:

Cutting and pasting data directly into Stata

Using StatTransfer

Using Stata's -infix- command

Converting ICPSR Data in ASCII Format into Stata Data Files



Home | Analyze Data Online | Help Resources | Contacts & Hours | Emory General Libraries