Professional Documents
Culture Documents
September 2013
Eva Poen
BEE3055 - Topic 1
Outline
1 2
Introduction Overview of the module Aim of the module Why Stata? Format of the course The Project Course outline for term 1 (approx.) Materials and Reading Reading Stata Resources ELE Introduction to Stata What is Stata? Getting started in Stata Empirical research in four easy steps! Stata basics Eva Poen BEE3055 - Topic 1 Changing the data
Eva Poen
BEE3055 - Topic 1
Aim of the module Why Stata? Format of the course The Project Course outline for term 1 (approx.)
Aim of the module Why Stata? Format of the course The Project Course outline for term 1 (approx.)
Eva Poen
BEE3055 - Topic 1
Aim of the module Why Stata? Format of the course The Project Course outline for term 1 (approx.)
Aim of the module Why Stata? Format of the course The Project Course outline for term 1 (approx.)
Software skills
Data analysis skills: Importing data into the software and organizing your work. Data types, display formats and precision. Working with dates and times / high frequency data. Advanced data manipulation. Graphics. Working with loops/other ways of repeating commands. Exporting data, results, graphs and tables to other software. Stata programming (writing procedures for Stata). ...
Eva Poen BEE3055 - Topic 1 8
Aim of the module Why Stata? Format of the course The Project Course outline for term 1 (approx.)
Eva Poen
BEE3055 - Topic 1
Aim of the module Why Stata? Format of the course The Project Course outline for term 1 (approx.)
Eva Poen
BEE3055 - Topic 1
10
Aim of the module Why Stata? Format of the course The Project Course outline for term 1 (approx.)
Eva Poen
BEE3055 - Topic 1
11
Aim of the module Why Stata? Format of the course The Project Course outline for term 1 (approx.)
Aim of the module Why Stata? Format of the course The Project Course outline for term 1 (approx.)
Previous examples
Well-being and the Comparison Income Effect (Economics of Happiness) Demographics and democracy: long term trends and their implications (voting behaviour) CO2 emissions and economic growth Does afnity increase the commitment towards a cause?
Eva Poen
BEE3055 - Topic 1
13
Aim of the module Why Stata? Format of the course The Project Course outline for term 1 (approx.)
What to read
Reading will be announced for every topic. However, much attention will be paid to practical skills. The two main textbooks that we will use are Microeconometrics Using Stata by Cameron and Trivedi, and Using Stata for Principles of Econometrics by Adkins and Hill. All relevant material for the practical exam will be presented in the lectures and tutorials. 60 % of the credits for this module will come from an individual, independent piece of work (project). Further reading for the project will depend on your chosen topic.
Eva Poen BEE3055 - Topic 1 15
Documentation Stata v13 comes with a complete set of manuals in pdf format Books on Stata Visit the Stata Bookstore at http://www.stata.com/bookstore/ for books on Stata. Several of them are available in the library. On the web Many academics use Stata for their teaching and research. A simple web search will come up with lots of information.
Eva Poen
BEE3055 - Topic 1
16
Ofcial Stata web site: www.stata.com Stata FAQs are at http://www.stata.com/support/faqs/. Current issue of the Stata Journal: http://www.stata-journal.com/current.html Discussion list server: http://www.stata.com/statalist/ Browse the ofcial Stata web site for more (SSC software archive, UCLA Stata site, etc.).
Eva Poen BEE3055 - Topic 1 17
Materials on ELE
Lecture notes, handouts and additional exercises. Data les. Please use the data les from this course only for the purpose of the course. You may not distribute data unless it is explicitly stated that you are allowed to do so. You may not use the data for commercial purposes, or attempt to sell the data. Stata code (in the form of do-les and ado-les). (The copyright of any Stata code distributed in class lies with the authors.) Discussion board: feel free to discuss issues like general data analysis questions, Stata problems etc. More information regarding the practical exam and project to follow soon.
Eva Poen BEE3055 - Topic 1 18
What is Stata? Getting started in Stata Empirical research in four easy steps! Stata basics Changing the data Bits and pieces
Features
Fully-featured statistical software package. Strong data manipulation techniques. Many built-in statistics, including time series applications, cross sections, panel models and survey analysis. Very good graphics capabilities (publication quality graphics). Stata is extensible: users can add their own routines, and publish them on the web. Plugins written in C can be attached to the executable. Since version 9, Stata comes with a matrix programming language called Mata, which is comparable to e. g. Matlab.
Eva Poen BEE3055 - Topic 1 19
What is Stata? Getting started in Stata Empirical research in four easy steps! Stata basics Changing the data Bits and pieces
Basics
Please start the software via the Start menu. Command window To execute a command, type it into the command window and press [Return]. By hitting the [Page Up] key, you can recover and edit commands you have previously entered. Result window All results or messages will appear in the result window. Review window Previously issued commands show up in the review window. A single click brings a command back to the command window. A double click on a command executes it.
Eva Poen BEE3055 - Topic 1 20
What is Stata? Getting started in Stata Empirical research in four easy steps! Stata basics Changing the data Bits and pieces
Basics (cont.)
Variables window Lists all variables in the dataset, alongside their labels. Try left, right click and selection. Properties window This window displays information about the dataset (number of observations, number of variables, size), and information about a variable that has been selected in the Variables window. It also allows you to edit certain properties of a variable such as labels.
Eva Poen
BEE3055 - Topic 1
21
What is Stata? Getting started in Stata Empirical research in four easy steps! Stata basics Changing the data Bits and pieces
Step 1 Formulate research question. Step 2 Find appropriate data to help answer research question. First type clear , then type sysuse nlsw88 Step 3 Conduct analysis. regress wage collgrad Step 4 Interpret ndings and report. The college premium is estimated to be 3.62 US Dollars.
Eva Poen
BEE3055 - Topic 1
22
What is Stata? Getting started in Stata Empirical research in four easy steps! Stata basics Changing the data Bits and pieces
Results
. regress wage collgrad Source | SS df MS ---------+----------------------------Model | 5307.01034 1 5307.01034 Residual | 69060.9571 2244 30.7758276 ---------+----------------------------Total | 74367.9674 2245 33.1260434 Number of obs F( 1, 2244) Prob > F R-squared Adj R-squared Root MSE = = = = = = 2246 172.44 0.0000 0.0714 0.0709 5.5476
---------------------------------------------------------------------wage | Coef. Std. Err. t P>|t| [95% Conf. Interval] ---------+-----------------------------------------------------------collgrad | 3.615502 .2753268 13.13 0.000 3.07558 4.155424 _cons | 6.910561 .1339984 51.57 0.000 6.647788 7.173335 ----------------------------------------------------------------------
Eva Poen
BEE3055 - Topic 1
23
What is Stata? Getting started in Stata Empirical research in four easy steps! Stata basics Changing the data Bits and pieces
On notation
Notation In all lecture notes and exercise sheets, Stata commands are typeset like this: about . To issue the command, you need to type about at the command window and press [Return]. All commands are also accessible via the menus, but we will focus on typing commands and writing simple programs. File names and paths Some commands only work with the specied le names or directory names. If you choose different names, you will need to adjust the command accordingly. Sometimes, only the command name is given, not the complete syntax, e. g. regress .
Eva Poen BEE3055 - Topic 1 24
What is Stata? Getting started in Stata Empirical research in four easy steps! Stata basics Changing the data Bits and pieces
What is Stata? Getting started in Stata Empirical research in four easy steps! Stata basics Changing the data Bits and pieces
What is Stata? Getting started in Stata Empirical research in four easy steps! Stata basics Changing the data Bits and pieces
What is Stata? Getting started in Stata Empirical research in four easy steps! Stata basics Changing the data Bits and pieces
What is Stata? Getting started in Stata Empirical research in four easy steps! Stata basics Changing the data Bits and pieces
Basic syntax
The syntax of list : list [varlist] [if] [in] [,options] All components in square brackets are optional (as we saw before, list on its own works ne). varlist Restricts the execution of the command to one or more variables. Examples for varlist: lnw id pencil city exp-civil
Eva Poen BEE3055 - Topic 1 29
What is Stata? Getting started in Stata Empirical research in four easy steps! Stata basics Changing the data Bits and pieces
30
What is Stata? Getting started in Stata Empirical research in four easy steps! Stata basics Changing the data Bits and pieces
Eva Poen
BEE3055 - Topic 1
31
What is Stata? Getting started in Stata Empirical research in four easy steps! Stata basics Changing the data Bits and pieces
What is Stata? Getting started in Stata Empirical research in four easy steps! Stata basics Changing the data Bits and pieces
What is Stata? Getting started in Stata Empirical research in four easy steps! Stata basics Changing the data Bits and pieces
Operators in Stata
Logical operators Stata knows about the logical operators & (AND), | (OR), != (NOT equal). A synonym for ! is . Relational operators Relational operators (>,<,>=,<=) work as expected, apart from equality: == Arithmetic operators Arithmetic operators also work as expected: + - * /. The symbol for power is , e.g. 52 is typed in as 52. Calculator The Stata function display can be used as a calculator: display log(137)*_pi2 .
Eva Poen
BEE3055 - Topic 1
34
What is Stata? Getting started in Stata Empirical research in four easy steps! Stata basics Changing the data Bits and pieces
What is Stata? Getting started in Stata Empirical research in four easy steps! Stata basics Changing the data Bits and pieces
Extending generate
The generate command works on a row-by-row basis. To see this, use the example data: clear and use example generate sumx = sum(x) list Advantage: You can exploit this feature, to create AR processes and the like. Disadvantage: What if you want to create a constant, equal to the sum of x? Use egen for this: drop sumx egen sumx = sum(x)
Eva Poen BEE3055 - Topic 1 36
What is Stata? Getting started in Stata Empirical research in four easy steps! Stata basics Changing the data Bits and pieces
Explicit subscripting
Stata allows you to refer to a specic observation (row): generate a = x[5] which will copy the value of x in observation no. 5 into every row of a new variable called a. The current observation number can be referred to as [_n]. The total number of observations can be referred to as [_N]. This allows to create lags and leads: generate xl1 = x[_n-1] generate xf1 = x[_n+1] Generate a unique ID in your data set: generate id = _n
Eva Poen BEE3055 - Topic 1 37
What is Stata? Getting started in Stata Empirical research in four easy steps! Stata basics Changing the data Bits and pieces
Sort order
In many situations it is important that your data is sorted in a certain order, i. e. when using explicit subscripting. Try the following using the pen01aL3 data: sort female sorts your data in ascending order by female (so, males rst). sort female ptime sorts the data by female, and within female, by ptime. We can specify more variables if necessary. If the sorting criteria do not uniquely identify each observation, the data are sorted randomly within the remaining subgroups. Example: female sort female list id in 1 sort ptime Repeat.
Eva Poen BEE3055 - Topic 1 38
What is Stata? Getting started in Stata Empirical research in four easy steps! Stata basics Changing the data Bits and pieces
Note that the data have to be sorted by female for this to work. If they are not, we can either issue a sort female prior to the command, or we can modify our command to include the sorting: bysort female: summarize lnw
Combining the by: prex with explicit subscripting is a powerful tool for dealing with panel data. Example of usage in cross section: bysort female (lnw): generate wagerank = _n browse id female lnw wagerank
Eva Poen BEE3055 - Topic 1 39
What is Stata? Getting started in Stata Empirical research in four easy steps! Stata basics Changing the data Bits and pieces
What is Stata? Getting started in Stata Empirical research in four easy steps! Stata basics Changing the data Bits and pieces
What is Stata? Getting started in Stata Empirical research in four easy steps! Stata basics Changing the data Bits and pieces
Memory
The size of the data you can have in Stata is limited by the amount of memory that is allocated to Stata, which is limited by the amount of RAM in your computer. Type help memory to nd out about memory usage.
Eva Poen
BEE3055 - Topic 1
42