Basics of Stata, Statistics 220 Last modified December 10, 1999.

Similar documents
EXCEL BASICS: MICROSOFT OFFICE 2007

Tiny Instruction Manual for the Undergraduate Mathematics Unix Laboratory

Cmpt 101 Lab 1 - Outline

EXCEL BASICS: MICROSOFT OFFICE 2010

Online User Guide, Part 1 Navigating the HCTF Online Website

CSE 101 Introduction to Computers Development / Tutorial / Lab Environment Setup

1 Introduction to Using Excel Spreadsheets

An Introduction to Stata Part I: Data Management

Ph3 Mathematica Homework: Week 1

Intro To Excel Spreadsheet for use in Introductory Sciences

Getting Started with UNIX

DOING MORE WITH EXCEL: MICROSOFT OFFICE 2013

An Introduction to Stata Exercise 1

Getting Our Feet Wet with Stata SESSION TWO Fall, 2018

Laboratory 1: Eclipse and Karel the Robot

Objective 1: Familiarize yourself with basic database terms and definitions. Objective 2: Familiarize yourself with the Access environment.

Spectroscopic Analysis: Peak Detector

Survey of Math: Excel Spreadsheet Guide (for Excel 2016) Page 1 of 9

Chapter 2 The SAS Environment

Introduction to Stata Getting Data into Stata. 1. Enter Data: Create a New Data Set in Stata...

TUTORIAL FOR IMPORTING OTTAWA FIRE HYDRANT PARKING VIOLATION DATA INTO MYSQL

Exercise 1: Introduction to Stata

Introduction to Minitab 1

PHY Microprocessor Interfacing Techniques LabVIEW Tutorial - Part X File Output and Input

Copyright 2018 MakeUseOf. All Rights Reserved.

Easy Windows Working with Disks, Folders, - and Files

Using the Inbox to Manage Messages

PBWORKS - Student User Guide

MIS2502: Data Analytics MySQL and SQL Workbench. Jing Gong

1 Interface Fundamentals

Introduction to Personal Computing

1. Open the New American FactFinder using this link:

DOING MORE WITH EXCEL: MICROSOFT OFFICE 2010

Instructions for Using the Databases

TOTAL ECLIPSE POCKET GUIDE CONTENTS

Accuterm 7 Usage Guide

tabulate varname [aw=weightvar]

Chapter. Accessing Files and Folders MICROSOFT EXAM OBJECTIVES COVERED IN THIS CHAPTER

ExamSoft: Examplify Guide - Detailed


Touring the Mac S e s s i o n 4 : S A V E, P R I N T, C L O S E & Q U I T

Depending on the computer you find yourself in front of, here s what you ll need to do to open SPSS.

Outlook Web Access. In the next step, enter your address and password to gain access to your Outlook Web Access account.

Stata: A Brief Introduction Biostatistics

International Graduate School of Genetic and Molecular Epidemiology (GAME) Computing Notes and Introduction to Stata

Econ Stata Tutorial I: Reading, Organizing and Describing Data. Sanjaya DeSilva

Quick Start Guide - Contents. Opening Word Locating Big Lottery Fund Templates The Word 2013 Screen... 3

Advanced Regression Analysis Autumn Stata 6.0 For Dummies

Instructions for Using the Databases

PISCES Installation and Getting Started 1

COMPUTER FOR BEGINNERS

The Very Basics of the R Interpreter

Biology 345: Biometry Fall 2005 SONOMA STATE UNIVERSITY Lab Exercise 2 Working with data in Excel and exporting to JMP Introduction

EE168 Lab/Homework #1 Introduction to Digital Image Processing Handout #3

HTML/CSS Lesson Plans

Using Microsoft Excel

A Quick-Reference Guide. To access reddot:

VERSION GROUPWISE WEBACCESS USER'S GUIDE

MATLAB - Lecture # 4

NiceForm User Guide. English Edition. Rev Euro Plus d.o.o. & Niceware International LLC All rights reserved.

Basic Microsoft Word

Lab 1. Introduction to R & SAS. R is free, open-source software. Get it here:

AEMLog Users Guide. Version 1.01

If you use Stata for Windows, starting Stata is straightforward. You just have to double-click on the wstata (or stata) icon.

Desktop Command window

This Tutorial is for Word 2007 but 2003 instructions are included in [brackets] after of each step.

Excel Macros, Links and Other Good Stuff

How to Do Everything We Need to Do on a TI Calculator in Algebra 2 for Now (Unless Davies Forgot Something)

Outlook Skills Tutor. Open Outlook

Introduction to Microsoft Office 2016: Word

A Document Created By Lisa Diner Table of Contents Western Quebec School Board October, 2007

Knowledgebase Article. Queue Member Report. BMC Remedyforce

Getting Started in CAMS Enterprise

Ektron Advanced. Learning Objectives. Getting Started

umapps Using umapps 6/14/2017 Brought to you by: umtech & The Center for Teaching & Learning

Getting Started With UNIX Lab Exercises

Website Management with the CMS

How to Edit Your Website

Tips & Tricks #66 Working with Online Calculator Variables

CME E-quotes Wireless Application for Android Welcome

The Menu and Toolbar in Excel (see below) look much like the Word tools and most of the tools behave as you would expect.

Getting Started with Amicus Document Assembly

An Introduction to Stata By Mike Anderson

Interactive MATLAB use. Often, many steps are needed. Automated data processing is common in Earth science! only good if problem is simple

Oracle Application Express Users Guide

Key File Generation. November 14, NATIONAL STUDENT CLEARINGHOUSE 2300 Dulles Station Blvd., Suite 220, Herndon, VA 20171

Creating a Do File in Stata

ECONOMICS 351* -- Stata 10 Tutorial 1. Stata 10 Tutorial 1

NQF ONLINE MEASURE SUBMISSION FORM USERS GUIDE

Wordpress Training Manual

Part 1: Understanding Windows XP Basics

LifeStructures Link. P a g e 1 12

Using WebBoard at UIS

DRAFT. TRAC User Guide. Revised: October 6, 2008 Revision: 1.0

Blackboard for Faculty: Grade Center (631) In this document:

Introduction to Stata First Session. I- Launching and Exiting Stata Launching Stata Exiting Stata..

Xchange for Samsung MAC User Guide. Version 2.4

Statistics 528: Minitab Handout 1

Depending on the computer you find yourself in front of, here s what you ll need to do to open SPSS.

4Sight for Mac User Guide. Version 2.4

Transcription:

Basics of Stata, Statistics 220 Last modified December 10, 1999. 1 Accessing Stata 1.1 At USITE Using Stata on the USITE PCs: Stata is easily available from the Windows PCs at Harper and Crerar USITE. Beginning with the Start menu in the lower left of the screen, choose the following options: Start Programs Mathematics & Statistics Intercooled Stata. Using Stata on the USITE UNIX workstations: This handout focuses on using Stata from the PC, as we assume that the majority of students prefer to do so. From one of the UNIX workstations at USITE, however, it is entirely possible to log into another UNIX server to run Stata. In general, Stata on UNIX is highly text-based, lacking the toolbar and multiple windows of the PC implementation. Also note that to view and print graphics on the UNIX system, you must first save the graph as a Postscript file. (See details below in Section.) To run Stata during a UNIX workstation session, follow these steps: 1 Telnet to mach.uchicago.edu (it s sufficient just to type telnet mach within the university domain.) 2 Log into mach just as you did with the UNIX workstation. 3 At the UNIX prompt, start a Stata session by typing: stata 1.2 For Remote Users We are working on the details of how to log into Stata from a remote PC or Mac outside USITE. Please see one of the 220 course instructors or CA s for help, and bring as many details as you can of your remote system. 2 Description of a PC Windows Stata Session 2.1 The Toolbar Stata s toolbar is very convenient. The Log button lets you record all your Stata commands and their results (except graphs) as you type them. This file will contain everything, from your mistakes, typos and... Therefore you are required to edit it before turning it in! The last resort is to cut and paste through the file using scissors. The Results button will bring the result window up front, which will contain the output from your Stata commands. The Editor button will bring a spreadsheet editor containing your data and lets you make changes in it. This is a very nice way to correct a typo in your dataset and also to assign names to variables. The Browse button will bring the same spreadsheet as under the Editor button but you can now only browse through it and won t be able to record any changes made in it. This is the safe way to look at your data and not run the risk of destroying it. The Break button lets you interrupt a Stata command that takes a long time and that you are no longer interested in. 2.2 The windows The big window that pops up when you start Stata is called the Results window. All the results of your Stata commands (except graphs which are shown in their own separate windows) will appear here. You enter commands in the Command window. To open the Command window, go to the Window menu and select Command. You can also open a Review window by selecting the Review option from the Window menu. The review window will record all the Stata commands you enter. You can repeat a previous command by double-clicking the command in the Review window. You can also open a Variables Window by selecting the Variables option from

the Window menu. This window will show a record of all the variables in the data set that you are currently using. 3 Structure of a Stata command In general, you tell Stata what to do by typing commands at the. in the Command Window. You do not need to type the. before the command. The form of all commands is or command variables, options command variable1 variable2..., option1 option2... The command is the command you want to execute, options (each option separated by a space) tells Stata how you want to execute the command, and variables (each variable name separated by a space) are the list variables to use in performing this command. Sometimes commands have options which you can specify on the same line as the original command, using a comma to separate the command from the options. For example, graph x1, hist bin(10) specifies that the graph to be produced is a histogram with 10 bins. End all commands by hitting the Return key. If a command goes beyond one line, keep typing the display will continue into the next line, and the command will not execute until you hit Return. If you need to stop the execution of a Stata command, on a PC hit the Break button on the Toolbar. 4 Online Help The nicest way to get help within Stata is to use the Help menu. Just click on it and follow your nose. A slightly faster but less pretty way is to type help at the command line. This will give you a list of topics for which help is available. If you know you need help with a specific command you can also type help commandname If you do not know the exact name of commands, you can type lookup commandname If the help file for a command is longer than a page (you should see more at the bottom of the help output), you can see more of it by pressing the space bar. Often real examples of how to use commands are at the end of help files. If you are scrolling through a very long help message and you would like to get out of help, type q. Command line help is probably most useful if you re only looking for the syntax of a command. If you really want to read the whole help file then you should use the menu bar, since the window based help lets you scroll backwards. 5 Log File Stata stores your commands and their results in a log file. At the start of every Stata session, you should start a log file. log using filename where you choose a name for filename. The log file often contains a lot of unwanted output and should not be submitted without editing.

6 Exiting Stata The smart way to exit Stata is to pull down the File menu and select Exit or Quit. Sometimes when you do this and the data in memory has not yet been saved Stata will not let you exit. In this case, a dialog box will appear giving you the option to Exit Anyway or Don t Exit. To exit Stata from the command line type exit. Sometimes Stata won t let you exit and gives you a message no;data in memory would be lost. This message warns you that the data currently in memory has not been saved. To exit you have two choices: 1. Exit without saving the data by typing exit, clear 2. Save the data and then exit by typing, for example, save yourdata exit 7 Getting Data into Stata 7.1 Using Stata-Format Datasets To use a dataset that has been saved in Stata format use the use command. Stata-format datasets are usually recognizable by the.dta in the filename (e.g. wind.dta). To use a dataset called wind.dta, type use wind If you are not sure of the filename, select File and Open from the menus. A file-finder dialog box will appear and you can navigate to the appropriate directory and find your data file. Sometimes if you already have a dataset in memory, Stata will not let you load a new dataset until you type clear to clear out the previous dataset. Stata-format datasets typically come with the variables already labeled. To see the labels, use the describe command. 7.2 Typing in a New Dataset Click on the Editor button on the toolbar. This will bring up a window that has rows and columns where you can enter your data. Each column represents a variable. You can enter both numeric or character data directly. You can also modify the data (e.g., correct typographical error) using this window. To label variables after entering data, double-click on the box of the spreadsheet immediately above the column containing the data. When you are done, close the edit window (click on square in upper-left corner) and save changes when asked. If you want to suffer, you can also do this using the input command to type raw data into Stata. Use the input command followed by a list of names (up to eight characters each) for the variables you want to enter. For example input dsun radius rings str7 planet 1. 57.9 2439 0 Mercury 2. 108.2 6050 0 Venus 3. 149.6 6378 0 Earth 4. end

After the input command, Stata prompts with case numbers 1., 2., and so on. Input columns need not line up, but there must be at least one space between values. Type end to stop data entry and return to Stata s. prompt. Notice that for the non-numeric variable planet it is necessary to put str7 in the input command immediately before planet. The str7 notifies Stata that the next variable will be a non-numeric (or string) variable and the maximum number of letters in these names is 7 (you can use up to str80). If you want to include blanks or special characters in the names you must enclose the string in quotes (e.g. Moon #2 ) (single or double quotes). If you want to include missing values for numeric variables you have to enter a period. rather than a blank and you must enter a double quote for missing string values. If you made a mistake in entering the data you use the Editor window and change the value wrongly entered or the replace command. For example, to change the value of radius in the second observation type replace radius = 7050 in 2 For more sophisticated file operations use the help function to get information on the append and merge commands. Note, successive input commands will keep adding data to the data already in memory. For example, the command input x followed by a later command input y will result in both x and y being stored in memory. To delete some or all variables from memory use the drop command. See help drop for more information. 7.3 Using Non-Stata-Format Datasets The only Non-Stata-Format datasets that Stata can read is a plain text file. In the computer literature, these files are called ASCII files. If you are using a text editing program to type in you dataset, remember to save it in an ASCII format (text format). This is not the format by default. For example if you use Microsoft Word and do not specify the ASCII format (text only format), the saved file will be in a Microsoft Word format which is unreadable by Stata. 7.3.1 With the dictionary The dictionary command tells Stata what the variables in the dataset are and can also contain the names and labels of these variables. For example A dictionary dataset must have the.dct extension to be recognized by Stata. If you are not sure whether a file has a dictionary or not, just look at it with any word processor you have. If the file starts by dictionary then it is a dictionary file, otherwise it isn t. This is what the top of a.dct file looks like. dictionary { str14 Name float Populatn "Population" float Income "Income mean" float Illitrcy "Illiteracy Rate" float Life.Exp "Life Expectancy" float Murder "Murder Rate per 100,000" } "Alabama" 3615 3624 2.1 69.05 15.1 "Alaska" 365 6315 1.5 69.31 11.3... After the curly brackets you have the type of the variable (str14, float,...) then the name of the variable (at most 8 characters) and finally the label attached to the specific variable. The last label is very useful since it is used when you plot or graph the specific variable. Finally, each field has to be separated by at least a space (in the example above, we used a tab ). You can input that file in Stata using the infile command. For example infile using reactor.dct You may have to specify the entire path name. For example, to input a file from your disk, you will have to type infile using c: reactor.dct

7.3.2 Without the dictionary Stata can read ASCII (or text-only) data files using the infile command. For example, to read a file called reactor.dat which has five variables (site, capacity, decom, start, close, where site is a string variable with a maximum of 30 characters and the others are numeric) you can use the following command: infile str30 site capacity decom start close using reactor.dat Notice that str30 precedes site to notify Stata that site is a string (not-numeric) variable with a maximum of 30 characters. In the ASCII file, missing numeric values should be indicated by a period,., and missing string values by a double quote. Because this is not a Stata-format dataset, it will not come with attached labels. You have to add labels by following the instructions given in the previous section. 8 Saving Data To save your data and the attached labels (if there are any) in Stata-format pull down the File menu and then select Save or Save As to save data in Stata format. You can also type.save filename On a PC, you may have include the path name with the filename (i.e.,. save M: filename). To use this data later, use the use command (that is, use filename). You are also able to double-click on the icon for the saved data set to reopen it. On a PC, you may have include the path name with the filename (i.e.,. use M: filename). To save your data in ASCII format (e.g. in case you want to read it into another statistics package or any text editors) use the outfile command. By default, any file saved using the outfile command is given a.raw extension. 9 Saving, Editing and Printing your work 9.1 With a word processor running at the same time as Stata If you have enough computer memory you should run Stata and a word processor at the same time while you are doing your homework. Doing so will save you a lot of time especially when you edit your Stata session for your homework. Having both programs running at the same time allows you to copy ouput from any Stata window (Select Copy from the Edit menu in Stata) and paste it in the word processor (Select Paste from the Edit menu of your word processor). Furthermore, you ll also be able to copy and paste Stata Graphs. That will save you from having to print each graph and then cut and paste them in your text using scissors and tape. Notice that once you pasted a graph in the word processor, some word processor (like Microsoft Word) will even let you edit them by double-clicking on them. An important reminder is that what you want to copy must be in the front-most window on your desktop. Finally, in order to preserve the spacing and the look of Stata tables you have to select the Courier font in your word processor. That is, pull down the Font menu and Select the Courier font. If you keep cutting your work from Stata and pasting it into your word processor, your report will almost be done by the time you are done with Stata. To get a hardcopy of your report, you can now print it throught your word processor. 9.2 When you can t run a word processor and Stata at the same time 9.2.1 Saving and Printing Output (Except Graphs) You can save a transcript of all text input and output that appears on your screen during your Stata session (no graphics are saved in the log file), by clicking on the Log button on the toolbar. You will be prompted to enter the name of your log file and where you want it saved. You can also start the log file by typing

log using myfile This will begin a log file called myfile.log. Th log file contains a literal transcript of all text input and output appearing on your screen from now until you interrupt it with log off or terminate it with log close or leave Stata. Once you ve interrupted your log file with log off you can turn it back on with log on. It is suggested that you use your name (first or last) in the title mylogfile. The title you give your log file will show up on the output. If you make the title unique, you will have an easier time finding your work when you print it. Your log file will be saved as an ASCII (or text-only) file. It can be printed directly to the printer or edited by any word processor. A note on editing the log file on PCs: If you are editting the log file in a wordprocessor, try changing the font of the document to Courier. This will make all the columns in your Stata output line up and look neat. Starting a log file is the first thing you should do everytime you use Stata. You can always cut and paste later (with a word processor, or with scissors and tape) to extract and organize the important results. Note, these log commands will save a record of your Stata commands and their text output. It will not save graphs and it will not save your data. To save your data, follow the instructions in the previous section. To save (and print) graphs, follow the instructions in the next sections. 9.2.2 Saving and Printing Graphs You should use the Save graph option under the File menu to save a graph. For example, first make a graph (here a histogram of the variable called radius), graph radius, hist this should open a new window with your graph in it, now Select Save graph under the File menu. You can choose a name for your graph and the location it will go. Relevant for a PC: To redisplay a previously saved graph type, for example, graph using mygraph To print a previously saved graph, re-display it, and then select File and Print Graph. You can also print a graph directly, without saving it, this way. Needless to say, you may need to log on a printer by going throughout the following sequence of menus: Start Programs Printer Logon and typing in your username and password before any attempt to print.