DOC PREVIEW
MIT 17 871 - Introduction to Stata

This preview shows page 1-2-3-4-5-6 out of 19 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 19 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 19 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 19 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 19 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 19 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 19 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 19 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

1This document was heavily cribbed from a similar one created by Jeroen Wessie, Departmentof Sociology, Utrech University.17.871Spring 2002Introduction to Stata11. IntroductionStata is a modern and general command-driven package for statistical analysis, data management, andgraphics. Versions are available for PC/DOS/Windows, Mac, and Unix. This document brieflyreviews some key elements of the program, reproduces a sample session, and finishes with a tabledescribing some of the more important Stata commands. This document was produced to helpintroduce Stata on the Athena operating environment, therefore the operating system I am assuming isUnix. 1. Starting StataIn an xterm window type the following:add stataxstataThis will fire up the graphical interface for Stata. If, instead of typing xstata you type stata, you willget a purely command-line interface.WARNING: Last year when the graphical interface was added for Unix, a number of problems werediscovered when Athena did the upgrading. In particular, xstata will sometimes cause Athena machinesto catastrophically fail, requiring a cold reboot. This problem appears to be associated with non-standard window managers. The following three points unfortunately comprise the workaround for theproblem:(1) Save your work often.(2) If you encounter problems of Athena hanging when you use Stata, try to use the standardAthena window manager.(3) To be absolutely certain you won't have these problems, use the command-line version ofStata.1.1 Entering and editing commands2Commands are entered and edited via the keyboard. Previous commands are saved in a buffer andcan be restored for editing. In addition, the GUI contains a window labeled “review” which records therecent commands you have entered. Once having entered a command, you may go to the ReviewWindow and double-click on any command to run it again. Single-clicking on the command brings thatcommand into the Command Window for editing and execution.Here are the most useful editing commands for the Command Window, using Unix.command Shortcutretrieves previous command Ctrl-Rnext command Ctrl-Bcursor back left arrowcursor forward right arrowmove cursor to start of line homemove cursor to end of line enddeletes char to the left backspacedeletes char at cursor position deldeletes full line Ctrl-Uexecute command EnterTo review the previous 10 commands, type #review 10.1.2 Exit from StataTo exit Stata, issue the command exit. If you worked on a dataset, you probably made changes to thedata, e.g., you created new variables. If you didn’t first save your data, Stata will refuse to let you exit. This is a paternalistic method to protect you from your own sloppiness. You can exit Stata withoutsaving the data by typing exit, clear.1.3 Help3The F1 key is reserved by Stata for help. Using the help command you can get detailed informationabout most aspects of the programs and command. For instance typing help regress gets youdetailed information about running linear regressions using the regress command.1.4 SearchThe search topic command allows you to search for the Stata command for analyses with referenceto topic. For instance, search regression gives a compact survey of the commands relevant forregression analysis. Note: at the end of the help section of commands, you’ll also find a list of relatedcommands.1.5 Stata on the InternetStata’s internet site is www.stata.com, and it can be accessed from within Stata via the Help menu. On the site, you will find an extensive FAQ page, plus other goodies.1.6 IdentifiersAn identifier (“name”), such as the name of a command or variable, consists of maximal 32 characters(both lowercase and uppercase letters, digits, and the underscore), where the first character shouldpreferably be a letter. (Note that the 32-character limit is new to version 7. Previous versionsimposed an 8-character limit. Because of compatibility issues, I will adhere to the 8-character limit, andwould ask you to do the same.) Stata is case-sensitive. Almost all Stata commands are in lowercase.1.7 AbbreviationsA general rule in Stata is that is that you may abbreviate commands and variables as long as Stata maynot become confused about what you mean. For instance, if you have variables income1 and inkvar2in your data set, Stata will understand that inc is the variable income1, while Stata would not be able todecide whether in means income1 or inkvar1. If you really mean to specify all variables that start with“in,” you can use a wildcard expression (in*).1.8 Log filesThe command log using filename specifies that all commands that are entered from the keyboard,plus most of the output that is produced as a result, are saved in a file named filename.scml. In this4way, you can save output and review it. Unfortunately (in my view), Stata v. 7 by default produces alog file that is in a mutant version of html. Therefore, to translate a log file into something you can moreeasily read, you will need to issue the translate command. You can skip this step by typing logusing filename, text.1.9 Shell commandsYou may enter a Unix command by prefixing it with an “!”. For instance !ls will list the files that are inthe current directory.1.10Batch filesYou can build a file of Stata commands to be run in batch mode. This is very useful for replicating youranalyses, and you will need to write such files to document your work in some problems sets and yourfinal project. To build and test a file of Stata commands you can either use an ASCII editor (such asemacs) or the Do-File Editor in the graphical interface.1.11A sample sessionThe following is a short introductory session in Stata, using the Black Elected Officials(beo_example.dta) data set in /mit/17.801/Examples. Comments are preceded by *.* Note: Immediately preceding this I typed “log using example”------------------------------------------------------------------------------- log: /afs/athena.mit.edu/course/17/17.801/Examples/example.smcl log type: smcl opened on: 12 Feb 2001, 14:09:37. clear* use the existing system file /mit/17.801/Examples/black_officials.dta. use black_officials* find out basic things about the organization of this data set. describeContains data from black_officials.dta5 obs: 50 vars: 4 12 Feb 2001 14:05 size: 900 (99.8% of memory


View Full Document

MIT 17 871 - Introduction to Stata

Documents in this Course
Load more
Download Introduction to Stata
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Introduction to Stata and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Introduction to Stata 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?