Sacha Kapoor - Masters Metrics

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

Dr. Barbara Morgan Quantitative Methods

A quick introduction to STATA

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

A Short Introduction to STATA

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

A quick introduction to STATA:

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

Revision of Stata basics in STATA 11:

Getting started with Stata 2017: Cheat-sheet

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

STATA Tutorial. Introduction to Econometrics. by James H. Stock and Mark W. Watson. to Accompany

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

Empirical Asset Pricing

A Short Guide to Stata 10 for Windows

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

Basic Stata Tutorial

Introduction to Stata - Session 2

A Quick Guide to Stata 8 for Windows

A quick introduction to STATA:

An Introduction to Stata Part II: Data Analysis

Introduction to STATA

Top 10 Things to Know about WRDS

Workshop for empirical trade analysis. December 2015 Bangkok, Thailand

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

Introduction to STATA

Empirical trade analysis

BASIC STEPS TO DO A SIMPLE PANEL DATA ANALYSIS IN STATA

Banking in QuickBooks Online

STATA TUTORIAL B. Rabin with modifications by T. Marsh

Intermediate Stata Workshop. Hsueh-Sheng Wu CFDR Workshop Series Spring 2009

Introduction to Stata: An In-class Tutorial

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

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

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

Introduction to Stata Session 3

What is Stata? A programming language to do sta;s;cs Strongly influenced by economists Open source, sort of. An acceptable way to manage data

A Short Guide to Stata 14

ECO375 Tutorial 1 Introduction to Stata

Econometric Tools 1: Non-Parametric Methods

First, go to and click on the Register button.

A First Tutorial in Stata

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

BIOSTATISTICS LABORATORY PART 1: INTRODUCTION TO DATA ANALYIS WITH STATA: EXPLORING AND SUMMARIZING DATA

Table of Contents CLIENT INTERNET ACCESS...4. Mobile Devices...4. Browser Compatibility...4 SYSTEM NAVIGATION Header Links...

A Brief Overview of Using STATA on the HPC Windows Terminal Server

Using. Research Wizard. Version 4.0. Copyright 2001, Zacks Investment Research, Inc.,

An Introductory Guide to Stata

ECONOMICS 452* -- Stata 12 Tutorial 1. Stata 12 Tutorial 1. TOPIC: Getting Started with Stata: An Introduction or Review

Data Analyst Nanodegree Syllabus

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

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

Table of Contents CLIENT INTERNET ACCESS...4. Mobile Devices...4. Browser Compatibility...4 SYSTEM NAVIGATION Header Links...

Data Analyst Nanodegree Syllabus

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

Introduc)on to Stata. Training Workshop on the Commitment to Equity Methodology CEQ Ins;tute and The Ministry of Finance Accra February 7-10, 2017

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

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

Important Things to Know about Stata

Business Analytics Nanodegree Syllabus

set mem 10m we can also decide to have the more separation line on the screen or not when the software displays results: set more on set more off

Introduction to Stata - Session 1

Intro to Stata for Political Scientists

ECON Stata course, 3rd session

Principles of Biostatistics and Data Analysis PHP 2510 Lab2

Week 10: Heteroskedasticity II

Statistical Good Practice Guidelines. 1. Introduction. Contents. SSC home Using Excel for Statistics - Tips and Warnings

Seminar Corporate Governance: Topics on Data Analysis with STATA

Event study Deals Stock Prices Additional Financials

Brief Guide on Using SPSS 10.0

0.1 Stata Program 50 /********-*********-*********-*********-*********-*********-*********/ 31 /* Obtain Data - Populate Source Folder */

WELCOME TO OUR MARKETCONNECT WEBSITE

NetAdvantage. User s Guide

API-202 Empirical Methods II Spring 2004 A SHORT INTRODUCTION TO STATA 8.0

SOCY7706: Longitudinal Data Analysis Instructor: Natasha Sarkisian. Panel Data Analysis: Fixed Effects Models

Introduction to Stata. Written by Yi-Chi Chen

Stock & Indices Release Notes May 2009 Monthly Update

Table of Contents (As covered from textbook)

Advanced Regression Analysis Autumn Stata 6.0 For Dummies

Economics 561: Economics of Labour (Industrial Relations) Empirical Assignment #2 Due Date: March 7th

Source:

STM103 Spring 2008 INTRODUCTION TO STATA 8.0

An Introduction to Stata Part I: Data Management

Title stata.com import haver Syntax

How to use FSBForecast Excel add-in for regression analysis (July 2012 version)

Week 1: Introduction to Stata

Migration and the Labour Market: Data and Intro to STATA

OVERVIEW OF WINDOWS IN STATA

range: [1,20] units: 1 unique values: 20 missing.: 0/20 percentiles: 10% 25% 50% 75% 90%

MFx Macroeconomic Forecasting

Sage Pastel Accounting. Year End Procedures Sage Pastel Partner V

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

Applied Regression Modeling: A Business Approach

Macola Enterprise Suite Release Notes: Macola ES

Economics 145 Fall 2009 Howell Getting Started with Stata

HP StorageWorks Command View TL TapeAssure Analysis Template White Paper

Section 2.3: Simple Linear Regression: Predictions and Inference

Introduction to R Programming

Stata tip: generation of string matrices using local macros

Learning Microsoft Excel Module 1 Contents. Chapter 1: Introduction to Microsoft Excel

Transcription:

Sacha Kapoor - Masters Metrics 091610 1 Address: Max Gluskin House, 150 St.George, Rm 329 Email: sacha.kapoor@utoronto.ca Web: http://individual.utoronto.ca/sacha$_$kapoor 1 Basics Here are some data resources available to University of Toronto Students: CHASS: http://datacentre.chass.utoronto.ca/ Data Library, 5th Floor Robarts Rotman Finance Lab There are also many data sets online. You just need to do a bit more searching. There are many different types of data: Financial markets data: CRSP Database - access NYSE/AMEX/Nasdaq daily and monthly security prices and other historical data related to over 20,000 companies Canadian Financial Markets Research Centre Toronto stock exchange trading info about specific securities Fundata Mutual Fund Database Companies financial data: Financial Post Corporate Database COMPUSTAT Database - Income Statement, Balance Sheet, Flow of Funds, and supplemental data items on more than 10,000 active and 9,400 inactive companies National income statistics: What is Stata? OECD National Accounts Database World Bank databases Penn World Tables A high level general purpose statistical software package (built on a C environment), with lots of built in functions. Caveat: Functions are not substitutes for understanding. 3 versions: Stata SE (for large datasets, found on arbor.economics.utoronto.ca, can be accessed remotely). Intercooled Stata (for medium sized datasets, can be purchased through Robarts Library). Small Stata (for small data sets). 3 ways to use Stata:

Sacha Kapoor - Masters Metrics 091610 2 Interactively, through the command prompt (enter the commands one by one). Batch files, by collecting commands and running them all at once. Point and Click. How to collect commands? Use a do file. doedit To track results/output you should use a log file: cd../../../../documents/ta/2010-2011/masters_metrics log using "tutorial_091610.log", replace where the first command changes the working directory to the data location and the second command opens the log file. To examine the current working directory: dir To import comma delimited data (.csv) use the insheet command: insheet using "S&P_data.csv" To examine attributes of the data: des Another way to obtain the same information and more: edit Note that in Stata 11, as opposed to previous versions, you can run commands and have the editor open at the same time. Before proceeding label the data and variables: label data "S&P (01-31-80 to 12-31-99)" label variable eps "Earnings per share" label variable price "Price per share" label variable weather "Weather" To convert the data into Stata format: save sacha_s&p.dta, replace To import data already in Stata format use the use command: use sacha_s&p.dta To destring the date variable, let s try:

Sacha Kapoor - Masters Metrics 091610 3 destring date, replace date in 1/10 destring date, force replace date in 1/10 Two issues: 1. missing data; 2. proper command for destringing dates. To deal with the first problem take the necessary precautions in your preamble: use "sacha_s&p.dta" preserve destring date, force replace date in 1/10 edit restore date in 1/10 To deal with the second problem: generate date2 = date(date,"mdy") date2 in 1/10 Now let s tell Stata that this is a time series: tsset date2, monthly To extract more detailed date information: generate year = year(date2) generate month = month(date2) generate day = day(date2) label variable year "Year" label variable month "Month" label variable day "Day" in 1/10 To drop variables: preserve drop day To keep variables: keep year To drop observations 5 through 15.

Sacha Kapoor - Masters Metrics 091610 4 drop in 5/15 Let s restore the data: restore Still on the topic of time series data, to generate a trend: generate x = _n x in 1/10 To generate lags (for x): generate x_1 = x[_n-1] replace x_1=0 if x_1==. Let s take a closer look at the weather variable. des weather edit weather One way to turn this into a dummy variable: generate weather2 = 0 replace weather2=1 if weather =="yes" replace weather2=0 if weather =="no" weather2 in 1/10 Notice how the replace command conditions on a logical expression. For future reference conditional statements can involve any one of the following: <, less than >, greater than <=, less than or equal to >=, greater than or equal to ==, equal to in a logical expression =, not equal to in a logical expression 2 Some Basic (Mostly) Statistical Commands To check the current memory allocation: help memory To set a new allocation: set memory 100

Sacha Kapoor - Masters Metrics 091610 5 Note that the set command can be used to change many basic defaults in Stata. I always begin investigations with the following command: tabulate weather Why is it nonsensical to tabulate price? tabulate price To present continuous data: histogram price An even better way: histogram price, kdensity Compare this with: histogram eps, kdensity Coarser evidence is obtained with the following command: summarize price eps To include a summary of a categorical variable we can use the xi environment: xi: summarize price eps i.weather To calculate means for price and eps under good and bad weather: by weather, sort: summarize price eps To summarize a subset of values: summarize price if price <=150 To collapse the data and create a new dataset: preserve collapse(mean) price, by (weather) save "price.dta", replace restore des To test the hypothesis that price=150, with 95 percent confidence: ttest price=150, level(95) To test the equality of means: gen price_g = price if weather2==1 gen price_b = price if weather2==0 ttest price_g = price_b, unequal unpaired

Sacha Kapoor - Masters Metrics 091610 6 3 Regression Suppose our interest is in the relationship between price and eps: twoway(scatter price eps) twoway(scatter price eps) lfit price eps Fitting a line through these points is equivalent to: regress price eps Controls are easy to add: regress price eps x The xi environment works here as well: xi: regress price eps x i.weather One way to deal with persistence in the dependent variable: generate price_1 = price[_n-1] xi: regress price eps x i.weather price_1 4 Merging Data Sets Let s access online data from Stata.com webuse odd webuse even1 Merges can be one-to-one merge using http://www.stata-press.com/data/r10/odd or can match observations across datasets webuse even1, merge number using http://www.stata-press.com/data/r10/odd, sort

Sacha Kapoor - Masters Metrics 091610 7 5 Loops Let s generate data: set obs 100 To create a variable with draws from a uniform distribution: generate y = runiform() y in 1/10 To generate many variables with draws from the uniform distribution: forvalues i = 1(1)100{ generate x i = runiform() } Note: (1) gives the increment, the loop generates 100 uniform random variables over (0,1). To check for consistency of an estimator: webuse census2, generate x = rnormal(1000,100) generate e = rnormal() x e in 1/10 generate y = 100+1*x + e regress y x 6 Panel Data use "MATHPNL.DTA" des Tell Stata you have a panel: xtset distid year To run regressions using panel data: xtreg math4 y93 y94 y95 y95 y96 y97 y98 lrexpp lenrol lunch, fe xtreg math4 y93 y94 y95 y95 y96 y97 y98 lrexpp lenrol lunch, fe robust To obtain predictions for the dependent variable and residuals, respectively: predict yhat predict resid To compare predictions with actual values: edit yhat math4 To close the log file: log close