Intermediate Stata. Jeremy Craig Green. 1 March /29/2011 1

Similar documents
Revision of Stata basics in STATA 11:

STATA 13 INTRODUCTION

A quick introduction to STATA:

Intro to Stata for Political Scientists

Introduction to Stata - Session 1

Week 1: Introduction to Stata

Workshop for empirical trade analysis. December 2015 Bangkok, Thailand

Introduction to Stata: An In-class Tutorial

Introduction to STATA

Data analysis using Stata , AMSE Master (M1), Spring semester

Introduction to STATA

Introduction to Stata. Getting Started. This is the simple command syntax in Stata and more conditions can be added as shown in the examples.

ECO375 Tutorial 1 Introduction to Stata

A quick introduction to STATA:

StatLab Workshops 2008

Dr. Barbara Morgan Quantitative Methods

An Introduction to Stata Part II: Data Analysis

Community Resource: Egenmore, by command, return lists, and system variables. Beksahn Jang Feb 22 nd, 2016 SOC561

Preparing Data for Analysis in Stata

Introduction to SAS. I. Understanding the basics In this section, we introduce a few basic but very helpful commands.

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

Data Management 2. 1 Introduction. 2 Do-files. 2.1 Ado-files and Do-files

Getting started with Stata 2017: Cheat-sheet

An Introduction to Stata Part I: Data Management

Ninth ARTNeT Capacity Building Workshop for Trade Research "Trade Flows and Trade Policy Analysis"

GETTING DATA INTO THE PROGRAM

After opening Stata for the first time: set scheme s1mono, permanently

A quick introduction to STATA

You will learn: The structure of the Stata interface How to open files in Stata How to modify variable and value labels How to manipulate variables

STATA Tutorial. Elena Capatina Office hours: Mondays 10am-12, SS5017

Introduction to Stata. Written by Yi-Chi Chen

Getting Our Feet Wet with Stata SESSION TWO Fall, 2018

A Short Guide to Stata 10 for Windows

Department of Economics Spring 2016 University of California Economics 154 Professor Martha Olney Stata Lesson Wednesday February 17, 2016

A Short Introduction to STATA

Subject index. ASCII data, reading comma-separated fixed column multiple lines per observation

STATA TUTORIAL B. Rabin with modifications by T. Marsh

IBMSPSSSTATL1P: IBM SPSS Statistics Level 1

Introduction to Statistical Analyses in SAS

Stata Session 2. Tarjei Havnes. University of Oslo. Statistics Norway. ECON 4136, UiO, 2012

Empirical trade analysis

Applied Regression Modeling: A Business Approach

Stata: A Brief Introduction Biostatistics

A Short Guide to Stata 14

BASIC STEPS TO DO A SIMPLE PANEL DATA ANALYSIS IN STATA

Department of Economics Spring 2018 University of California Economics 154 Professor Martha Olney Stata Lesson Thursday February 15, 2018

Introduction to Stata Toy Program #1 Basic Descriptives

Introduction to SAS and Stata: Data Construction. Hsueh-Sheng Wu CFDR Workshop Series February 2, 2015

INTRODUCTION TO USING STATA FOR ECONOMETRICS

Lab 1: Basics of Stata Short Course on Poverty & Development for Nordic Ph.D. Students University of Copenhagen June 13-23, 2000

SAS Training Spring 2006

STATA Version 9 10/05/2012 1

I Launching and Exiting Stata. Stata will ask you if you would like to check for updates. Update now or later, your choice.

5. Exercise 5 Produce publication-quality tables of summary statistics and regression results

Stata version 14 Also works for versions 13 & 12. Lab Session 1 February Preliminary: How to Screen Capture..

Results Based Financing for Health Impact Evaluation Workshop Tunis, Tunisia October Stata 2. Willa Friedman

A Quick Guide to Stata 8 for Windows

INTRODUCTION to. Program in Statistics and Methodology (PRISM) Daniel Blake & Benjamin Jones January 15, 2010

Empirical Asset Pricing

The Stata Bible 2.0. Table of Contents. by Dawn L. Teele 1

Basic Stata Tutorial

Instructions for Using ABCalc James Alan Fox Northeastern University Updated: August 2009

Scatterplots. This handout focuses mainly on the Stata menu approach to obtaining scatterplots, but display equivalent command-line language.

Introduction to Stata

Introduction to R. Andy Grogan-Kaylor October 22, Contents

Use data on individual respondents from the first 17 waves of the British Household

Lecture 2: Advanced data manipulation

1. Basic Steps for Data Analysis Data Editor. 2.4.To create a new SPSS file

ST Lab 1 - The basics of SAS

Economics 145 Fall 2009 Howell Getting Started with Stata

Stata Training. AGRODEP Technical Note 08. April Manuel Barron and Pia Basurto

Stata version 13. First Session. January I- Launching and Exiting Stata Launching Stata Exiting Stata..

Intro to STATA Lecture Notes Stuart Soroka Department of Political Science, McGill University January 2010 *

Introduction to Stata - Session 2

/23/2004 TA : Jiyoon Kim. Recitation Note 1

Appendix II: STATA Preliminary

Advanced Regression Analysis Autumn Stata 6.0 For Dummies

GETTING STARTED WITH STATA. Sébastien Fontenay ECON - IRES

Introduction to SAS. Cristina Murray-Krezan Research Assistant Professor of Internal Medicine Biostatistician, CTSC

Introduction to data analysis using STATA. Miguel Niño-Zarazúa World Institute for Development Economics Research United Nations University

An Introduction To Stata and Matlab. Liugang Sheng ECN 240A UC Davis

A Step by Step Guide to Learning SAS

Applied Regression Modeling: A Business Approach

Sustainability of Public Policy Lecture 1 Introduc6on STATA. Rossella Iraci Capuccinello

1 Introducing Stata sample session

Using Stata for Survey Data Analysis. Nicholas Minot International Food Policy Research Institute Washington, DC, USA

OVERVIEW OF WINDOWS IN STATA

Migration and the Labour Market: Data and Intro to STATA

Applied Regression Modeling: A Business Approach

Introduction to gretl

Epidemiology Principles of Biostatistics Chapter 3. Introduction to SAS. John Koval

A Comparison of Modeling Scales in Flexible Parametric Models. Noori Akhtar-Danesh, PhD McMaster University

Introduction to STATA 6.0 ECONOMICS 626

GAUSS T U T O R I A L

Intro to Stata. University of Virginia Library data.library.virginia.edu. September 16, 2014

Sacha Kapoor - Masters Metrics

Lecture 4: Programming

Event study Deals Stock Prices Additional Financials

Introduction to Mplus

Polymath 6. Overview

Transcription:

Intermediate Stata Jeremy Craig Green 1 March 2011 3/29/2011 1

Advantages of Stata Ubiquitous in economics and political science Gaining popularity in health sciences Large library of add-on modules Version 11 markedly improves variables manager,.do file editor, factors, and merges I know that Stata does 2SLS right, I don't know if I trust the yahoo that coded it up for R. http://www.yale.edu/statlab 2

Disadvantages of Stata Proprietary (not open source) Expensive (especially for MP versions) Weaker graphics (compared to R) Command-line focused (has GUI, but difficult) Stata is great because its just like DOS. http://www.yale.edu/statlab 3

Getting Help help command in Stata http://statlab.stat.yale.edu/help/ http://www.ats.ucla.edu/stat/stata/ http://data.princeton.edu/stata/ http://www.stata.com/statalist/ 0. Introduction 4

1. Data management 2..do and.log files 3. Data inspection 4. Variable creation 5. Merging data 6. Reshaping data 7. Graphics 8. Regression analysis Today s Workshop 0. Introduction 5

Data Management Use StatTransfer software to convert Excel, SAS, SPSS, into Stata. Use compress command to make your dataset as small as possible and use less memory. Some very large datasets won t open in Stata due to memory limitations. In this case, it is recommended that you open a subset of the dataset: use varlist using filename 2. Data Management 6

.do files.do files allow you to run a whole program interactively; you can run it all at once or select portions of the program. AVOID making changes to your original data interactively using the STATA command window. Use DO files instead. To open.do file, use FILE menu or DO-file button. 1. Programming/Project Management Tips 7

.log files Syntax Begin log file log using filename.txt, text replace End log file log close 1. Programming/Project Management Tips 8

Data Inspection cd C:\Documents and Settings\Jeremy\My Documents\stata files\ clear set mem 80m log using mylog.txt, text replace sysuse census des sum varlist bro varlist 2. Data Management 9

Variable Creation g agesq = medage^2 /* creates variable equal to medage squared */ sum pop /* shows summary stats for pop */ scalar popmean = r(mean) /* saves mean of pop to scalar popmean */ /* create variable equal to 1 when pop > popmean and 0 otherwise */ g dummy = 0 replace dummy = 1 if pop > popmean /* how many states have population higher than average? */ count if dummy == 1 /* how many states NOT IN THE SOUTH have pop > popmean? */ count if dummy == 1 & region!= 3 2. Data Management 10

Variable Creation (con t) To create four dummies, we need to type those two commands four times. More importantly, the previous method generates 0s even when we have missing values. tab region, g(d) This second method tabulates the variable region, showing a list of the four regions, and correctly creates 4 separate dummies, accounting for missing values. 2. Data Management 11

Merging Data sysuse census, clear keep state-popurban sort state /* both master and using data must be sorted */ save census1, replace sysuse census, clear keep state medage-divorce /* note state is kept in both */ sort state save census2, replace use census1, clear merge 1:1: state using census2 /* remember: both files must be sorted */ tab _merge /* _merge keeps track of how good merge was */ 2. Data Management 12

sysuse bplong, clear br Reshaping Data Suppose we want to take difference in bp before and after treatment. Difficult to calculate difference if data is organized in long format. Need to convert to wide format. reshape wide bp, i(patient sex agegrp) j(when) br g bpdiff = bp2 bp1 2. Data Management 13

Draw a histogram: sysuse auto, clear histogram price Create a scatter plot: scatter price mpg Graphics Draw line of best fit (linear regression): twoway lfit price mpg Put two graphs together: twoway scatter price mpg lfit price mpg 3. Analyzing Data 14

Regression Analysis cor var1 var2 computes correlation btw two vars: cor price mpg regress var1 var2 estimates effect of var2 on var1: reg price mpg More complex models (i.e. discrete choice, IV, HLM) 3. Analyzing Data 15

Additional References http://www.yale.edu/statlab 16

Questions? 17