Stata Introduction To Stata.pdf

(227 KB) Pobierz
Introduction to Stata 7.0: Economics 311
1
I. Access to Stata
Stata is in a folder on your dock titled “IRC Applications.” Stata can be
accessed from other machines on campus by selecting the “Data Analysis and
Processing” folder in the Academic Server.
Stata is a “keyed” program, so you need to be on campus to use the program.
II. Starting Stata
Double-click on the file titled “Stata” in the
IRC Applications
folder.
A. Stata Windows
review
results
variables
command
B. Stata Toolbar
13 buttons – bring your mouse over a button and a box will appear with a
description of that button.
C. Stata Log File
A log file is a record of your Stata session. Log files can either be in a Stata
format (SMCL) or a text (ASCII) format. Saving the log file as a text file will
allow you to bring the file into
Word
for additional editing.
Start a log file by clicking on the Log button, select begin, and fill in a
filename.
You can add comments to your log by typing a star (*) at the beginning of a
command line. This will treat that line as a comment.
1
This handout draws liberally from Stata 7: Getting Started, Macintosh. 2001.
College Station, TX: Stata Corporation.
III. Stata’s Help Feature
Choosing
Help
from the menu allows you to:
1. See the help table of contents
2. Search for help entries on a topic
3. Get help for a Stata command
Choosing
Search...
from the Help menu allows you to enter keywords and
produces a screen with hypertext links (in blue) that will take you to the help
files for the appropriate Stata commands. You will also see references to the
topic in the Reference Manual, Graphics Manual, User’s Guide, etc.
Example:
Select
Search
from the Help menu
Enter regression and click
OK
Scroll down to
regress
and click on this word
*Use proper English and statistical terminology with
Search
Choosing
Help Contents
from the Help menu gives a list of Stata’s help table of
contents. You can:
1. Choose from the links on this page to view help for a particular
command
2. Or enter the full name of the Stata command in the edit field at the top
of the Help window.
Example:
1. Type
ttest
and press Enter
*Only enter Stata commands – using proper English or
statistical terminology will probably not work
The help files contain a lot of information, but not as much as the
Reference
Manual, Graphics Manual,
and
User’s Guide.
These publications are on reserve at
the Reed Library and in the Public Policy Workshop.
2
Help will let you know where to find more information about specific topics in
these manuals. For example,
“[U] 2.4
The Stata Technical Bulletin”
means section 2.4 in the
User’s Guide.
“[R]
regress”
means the entry
regress
in the
Reference Manual.
“[G]
graph options”
means the entry
graph options
in the
Graphics Manual.
Example:
1.
Choose
Help
from the menu bar and select
Search...
2. Enter data and click
OK
3. Scroll down until you see [R] describe.
describe
is a Stata command that
describes the contents of data in memory or on disk. The [R] means that
documentation is in the
Reference Manual.
An on-line help file exists for this
command.
4. Click on the hypertext link “describe” in “help describe.”
5. The help file for Stata commands contain:
The command’s syntax
A description of the command
Options
Examples, and
References to related commands.
IV. Inputting Data into Stata using the
Data Editor
Click on the
Data Editor
button or type edit and press Return in the Command
window.
Stata’s editor looks like a spreadsheet and it functions in a way that is quite
similar to
Excel.
A. Inputting Data
Things to know about entering data in Stata
Quotes around string variables are unnecessary
A period (‘.’) represents a missing numeric value
Press Tab or Return to input a missing numeric value
Press Tab or Return to input a missing value for a string variable
Stata will not allow empty columns or rows in the middle of your
dataset
Example:
1. Enter the auto data on the Session 1 handout into Stata’s editor.
You can do this variable-by-variable or observation-by observation.
2. When entering data observation-by-observation use the tab key.
Stata’s tab key is smart. Notice what happens after you’ve entered
the first observation.
3
B. Renaming Variables
Double-click anywhere in the variable’s column. This brings up the Variable
Information dialog box. Enter the new name of the variable. Label allows you to
specify a more detailed description of the variable.
Rules for variable names:
Stata is case sensitive
A variable name must be between 1 and 8 characters long
Characters can be letters, digits, or underscores
Spaces or other characters are not allowed
The first character of a variable name must be a letter or an underscore
C. Copying and Pasting Data
1. Select the data you want to copy
Click and drag the mouse to select a range of cells
2. Copy the data to the clipboard
Pull down on the
Edit
menu and choose
Copy
3. Paste the data from the clipboard
Click on the top left cell of the area to which you wish to paste. Pull down
the
Edit
menu and choose
Paste.
D. Exiting the Data Editor
Click on the editor’s close box.
Changes that you made in the editor are not saved until you tell Stata to save
them. Data can be saved by pulling down
File
and choosing
Save As.
You cannot save your data until you have exited the editor.
Example:
1. Click on the
File
menu and select
Save.
2. Enter the filename
afewcars
Stata will automatically add the .dta
extension to the file.
3. Type
clear
in the Stata command window. This removes the
dataset from Stata’s memory.
4
V. Inputting Data from a File
A. Insheet
The insheet command is used to import text (ascii) files created by a spreadsheet
program. It is important that the file be saved in the spreadsheet program as
“text only” with a tab or comma column delimiter. The general format of the
insheet command is:
insheet using “filename”
If the file is not in the current folder type “insheet using” then select Filename
from the File menu and select the file.
Example:
1. Import the file “SavingsIncome-UK.txt” (a tab delimited text file) from
the Econ 311 folder.
2. Type
browse
in your command window. This allows you to view, but
not change the data. Exit the browser.
3. Type
clear
in the Stata command window.
VI. Labeling Data
Using the dataset
afewcars.dta
Example:
1. Type
use afewcars
into the Stata command window
2. Type
describe
into the Stata command window
The data description provides information on the variable name, storage type,
and display format.
Example:
1. Type clear in the Stata command window.
2. Open the file “auto.dta” in the Econ 311 folder.
3. Use the
describe
command
5
Zgłoś jeśli naruszono regulamin