[U] User's Guide - Stata

1y ago
74 Views
8.81 MB
401 Pages
Last View : 5d ago
Transcription

STATA USER’S GUIDERELEASE 16 A Stata Press PublicationStataCorp LLCCollege Station, Texas

ContentsStata basics1Read this—it will help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .22A brief description of Stata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .93Resources for learning and using Stata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .134Stata’s help and search facilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .245Flavors of Stata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .316Managing memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .347–more– conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .368Error messages and return codes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .379The Break key . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4010Keyboard use . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .42Elements of Stata11Language syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4912Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8413Functions and expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12314Matrix expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .14415Saving and printing output—log files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .15916Do-files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .16517Ado-files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17818Programming Stata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .18319Immediate commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .23720Estimation and postestimation commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .24121Creating reports . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .304Advice22Entering and importing data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .30823Combining datasets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .317i

iiContents24Working with strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .31925Working with dates and times . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .32326Working with categorical data and factor variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .33227Overview of Stata estimation commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .35028Commands everyone should know . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .38329Using the Internet to keep up to date . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .385Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .392Subject and author index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .397

Stata basics1Read this—it will help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .22A brief description of Stata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .93Resources for learning and using Stata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .134Stata’s help and search facilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .245Flavors of Stata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .316Managing memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .347–more– conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .368Error messages and return codes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .379The Break key . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4010Keyboard use . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .421

1Read this—it will helpContents1.11.21.31.4Getting Started with Stata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .The User’s Guide and the Reference manuals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1.2.1PDF manuals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1.2.1.1Video example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1.2.2Example datasets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1.2.2.1Video example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1.2.3Cross-referencing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1.2.4The index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1.2.5The subject table of contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1.2.6Typography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1.2.7Vignette . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .What’s new . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .24445566667788

[ U ] 1 Read this—it will helpThe Stata Documentation consists of the following [PSS][P][RPT][SP][SEM][SVY][ST][TS][TE][I]Getting Started with Stata for MacGetting Started with Stata for UnixGetting Started with Stata for WindowsStata User’s GuideStata Base Reference ManualStata Bayesian Analysis Reference ManualStata Choice Models Reference ManualStata Data Management Reference ManualStata Dynamic Stochastic General Equilibrium Models Reference ManualStata Extended Regression Models Reference ManualStata Finite Mixture Models Reference ManualStata Functions Reference ManualStata Graphics Reference ManualStata Item Response Theory Reference ManualStata Lasso Reference ManualStata Longitudinal-Data/Panel-Data Reference ManualStata Meta-Analysis Reference ManualStata Multilevel Mixed-Effects Reference ManualStata Multiple-Imputation Reference ManualStata Multivariate Statistics Reference ManualStata Power, Precision, and Sample-Size Reference ManualStata Programming Reference ManualStata Reporting Reference ManualStata Spatial Autoregressive Models Reference ManualStata Structural Equation Modeling Reference ManualStata Survey Data Reference ManualStata Survival Analysis Reference ManualStata Time-Series Reference ManualStata Treatment-Effects Reference Manual:Potential Outcomes/Counterfactual OutcomesStata Glossary and Index[M]Mata Reference ManualIn addition, installation instructions may be found in the Installation Guide.3

[ U ] 1 Read this—it will help1.2.1.15Video examplePDF documentation in Stata1.2.2Example datasetsVarious examples in this manual use what is referred to as the automobile dataset, auto.dta. Wehave created a dataset on the prices, mileages, weights, and other characteristics of 74 automobilesand have saved it in a file called auto.dta. (These data originally came from the April 1979 issueof Consumer Reports and from the United States Government EPA statistics on fuel consumption;they were compiled and published by Chambers et al. [1983].)In our examples, you will often see us type. use https://www.stata-press.com/data/r16/autoWe include the auto.dta file with Stata. If you want to use it from your own computer rather thanvia the Internet, you can type. sysuse autoSee [D] sysuse.You can also access auto.dta by selecting File Example datasets., clicking on Exampledatasets installed with Stata, and clicking on use beside the auto.dta filename.There are many other example datasets that ship with Stata or are available over the web. Here isa partial list of the example datasets included with eexp.dtauslifeexp2.dtavoter.dtaxtline1.dta1978 Automobile Data1978 Automobile DataSubset of 1978 Automobile Datafictional blood pressure datafictional blood pressure dataPatient Survival in Drug Trial1980 Census data by stateCity Temperature DataCity Temperature DataEducation and GDPU.S. GNP, 1967–2002Life expectancy, 1998fictional network diagram datafictional network diagram dataU.S. National Longitudinal Study of Young Women (NLSW, 1988 extract)U.S. National Longitudinal Study of Young Women (NLSW, 1988 extract)U.S. Census, 2000, extractSubsea elevation of Lamont sandstone in an area of OhioS&P 500NOAA Sea Surface Temperaturesimulated time-series datafictional data on calories consumedU.S. life expectancy, 1900–1999U.S. life expectancy, 1900–19401992 presidential voter datafictional data on calories consumed

[ U ] 1 Read this—it will help1.2.67TypographyWe mix the ordinary typeface that you are reading now with a typewriter-style typeface that lookslike this. When something is printed in the typewriter-style typeface, it means that something is acommand or an option — it is something that Stata understands and something that you might actuallytype into your computer. Differences in typeface are important. If a sentence reads, “You could listthe result . . . ”, it is just an English sentence — you could list the result, but the sentence providesno clue as to how you might actually do that. On the other hand, if the sentence reads, “You couldlist the result . . . ”, it is telling you much more — you could list the result, and you could do thatby using the list command.We will occasionally lapse into periods of inordinate cuteness and write, “We described the dataand then listed the data.” You get the idea. describe and list are Stata commands. We purposelybegan the previous sentence with a lowercase letter. Because describe is a Stata command, it mustbe typed in lowercase letters. The ordinary rules of capitalization are temporarily suspended in favorof preciseness.We also mix in words printed in italic type, such as “To perform the rank-sum test, type ranksumvarname, by(groupvar)”. Italicized words are not supposed to be typed; instead, you are to substituteanother word for them.We would also like users to note our rule for punctuation of quotes. We follow a rule that is oftenused in mathematics books and British literature. The punctuation mark at the end of the quote isincluded in the quote only if it is a part of the quote. For instance, the pleased Stata user said shethought that Stata was a “very powerful program”. Another user simply said, “I love Stata.”In this manual, however, there is little dialogue,

The Getting Started manual, the User’s Guide, and the Reference manuals cross-reference each other. [R] regress [D] reshape [XT] xtreg The ﬁrst is a reference to the regressentry in the Base Reference Manual, the second is a reference to the reshapeentry in the Data Management Reference Manual, and the third is a reference to the

Related Documents:

Stata is available in several versions: Stata/IC (the standard version), Stata/SE (an extended version) and Stata/MP (for multiprocessing). The major difference between the versions is the number of variables allowed in memory, which is limited to 2,047 in standard Stata/IC, but can be much larger in Stata/SE or Stata/MP. The number of

Categorical Data Analysis Getting Started Using Stata Scott Long and Shawna Rohrman cda12 StataGettingStarted 2012‐05‐11.docx Getting Started Using Stata – May 2012 – Page 2 Getting Started in Stata Opening Stata When you open Stata, the screen has seven key parts (This is Stata 12. Some of the later screen shots .

To open STATA on the host computer, click on the “Start” Menu. Then, when you look through “All Programs”, open the “Statistics” folder you should see a folder that says “STATA”. Click on the folde r and it will open up three STATA programs (STATA 10, STATA 11, and STATA 12). These are all the

There are several versions of STATA 14, such as STATA/IC, STATA/SE, and STATA/MP. The difference is basically in terms of the number of variables STATA can handle and the speed at which information is processed. Most users will probably work with the “Intercooled” (IC) version. STATA runs on the Windows, Mac, and Unix computers platform.

Stata/MP, Stata/SE, Stata/IC, or Small Stata. Stata for Windows installation 1. Insert the installation media. 2. If you have Auto-insert Notiﬁcation enabled, the installer will start auto-matically. Otherwise, you will want to navigate to your installation media and double-click on Setup.exe to start the installer. 3.

Stata/IC and Stata/SE use only one core. Stata/MP supports multiple cores, but only commands are speeded up. . I am using Stata 14 and not Stata 15) Setting up the seed using dataset lename. type can be F create creates a dataset with empty seeds for each variation. If option fill is used, then seeds are random numbers.

STATA/IC, STATA/SE, and STATA/MP. The difference is basically in terms of the number of variables STATA can handle and the speed at which information is processed. Most users will probably work with the “Intercooled” (IC) version. STATA runs on the Windows (2000, 2003, XP, Vista, Server 2008, or Windows 7), Mac, and Unix computers platform.

Open Stata and click the “Browse Data with Edits Icon” Click on the upper-left most cell Paste the data (ctrl-v) When prompted, tell Stata to treat the first row as variable names Save your data as a dta file There are two more options. First, for users of Stata 12, Excel files can be opened directly into Stata.

Teaching\stata\stata version 14\stata version 14 – SPRING 2016\Stata for Categorical Data Analysis.docx Page 8of 29 Note. You might see tables that are “flipped” - The layout of tables here is the following.

Stata handout Spring 2020 Page Data Visualization w Stata.docx 3of 17 1. Introduction to Stata for Graphs a. Choose Your Scheme The Stata command scheme sets the overall appearance of your

Stata Version 13 - Spring 2015 Illustration: Simple and Multiple Linear Regression \1. Teaching\stata\stata version 13 - SPRING 2015\stata v 13 first session.docx Page 12 of 27 II - Simple Linear Regression 1. A General Approach for Model Development There are no rules nor single best strategy. In fact, different study designs and .

Cross-referencing the documentation When reading this manual, you will ﬁnd references to other Stata manuals, for example, [U] 27 Overview of Stata estimation commands;[R] regress; and[D] reshape.The ﬁrst ex-ample is a reference to chapter 27, Overview of Stata estimation commands, in the User's Guide;

Stata 12: Data Analysis 3 The Division of Statistics Scientific Computation, The University of Texas at Austin Section 1: Introduction 1.1 About this Document This document is an introduction to using Stata 12 for data analysis. Stata is a software package popular in the social sciences for manipulating and summarizing data and

Longitudinal Data Analysis: Stata Tutorial Part A: Overview of Stata I. Reading Data: use Read data that have been saved in Stata format. infile Read raw data and “dictionary” files. insheet Read spreadsheets saved as “CSV” files from a package such as Excel. II. Do Files What is a do file?

DATA subdirectory in Stata, and converted to a *.dct file with the epi2dct.exe program. Thereafter the *.dct file was read into Stata with the infile using command and saved as a *.dta file. Once in Stata, the means of the binomial variables DEAD and RAZOR were analyzed as if the d

Stata has very conveniently implemented the bootstrap for cross-section data. Bootstrap sampling and summarizing the results is automatically done by Stata. The Stata commands are shown for the example of a univariate regression of a variable yon x. Case 1: Bootstrap standard errors are implemented as option in the stata command

users should see Getting Started with Stata for Mac; Stata for Unix R users should see Getting Started with Stata for Unix. This manual is intended both for people who are completely new to Stata

Standard Stata does not contain any commands for estimating and modelling relative survival so we must extend Stata using commands written by users. Download and installation is done within Stata. It is recommended that you change the Stata working directory to the course directory

1 Introducing Stata—sample session Introducing Stata This chapter will run through a sample work session, introducing you to a few of the basic tasks that can be done in Stata, such as opening a dataset, investigating the contents of the dataset, using

2 The Stata user interface The windows This chapter introduces the core of Stata’s interface: its main windows, its toolbar, its menus, and its dialogs. The ﬁve main windows are the History, Results,