september 28, 2011

Reading in Data

If Data you are interested in is in Stata Format, then all you need is knowing its file path. Assuming you are using PC, and data set is named “Coffee.dta”, and is located in “My documents”, then the Stata command for loading such will be

use "C:\Documents and Settings\Paul\My Documents\Coffee.dta", clear

Note: Don’t forget putting the double quotes (“”) enclosing the path of the data set.

Data Set inform of Excel(or text file)

If the data set you are interested in is .xls, Its still possible to work with it in Stata.

first, from your excel application, save the data as of type Text(Tab delimited). this will save it in a .txt file extension.

Now our coffee data set, coffee.xls becomes coffee.txt.

from Stata, issue the following command:

insheet using "C:\Documents and Settings\Paul\My Documents\coffee.txt"

The same command is issued if importing a .csv file.

insheet using "C:\Documents and Settings\Paul\My Documents\coffee.csv"

Note:

You can also save Excel data COULD be saved in the .csv format (“save as”, if not already in that format).

You can also enter the data manually (or copy and paste from Excel or almost any format) by typing

From Stata’s Command window, type edit.

This will trigger a Data Editor window. Paste your Data here or edit it manually.

If you choose this option, Stata will automatically name your variables by column, e.g. the variable first column is “var1”. To change this, you can rename your variables by typing
rename var1 price – to rename “var1” to “price”. Read more on variables renaming.