Sunteți pe pagina 1din 21

Introduction to Stata

Econometrics 351-0570-00
March 18, 2010

Outline

Outline

1 Getting Started

2 Basic Commands

3 Further Resources

Outline

Outline

1 Getting Started

2 Basic Commands

3 Further Resources

Getting Started

About Stata

p p p p p p p

Integrated statistical package Cross-plattform compatible Excellent documentation and transparent source code Strong in regression analysis Widely used by economists Large community that contributes Stata modules Available in HG E 26.1

Getting Started

How to Work With Stata

Modes of working with the software Point-and-click menus Command prompt Do-le editor Point-and-click approach generates code that is printed in the review window Working with .do les is most ecient and allows reproducing results

p p

Interface: Menu, results window, review window, variables window, command window

p p p

Getting Started

Do-Files and Log Files

p p p Logging p log shows status of logging p log using filename starts logging results, log close closes the log le p view filename.smcl shows the log le

.do les Type doedit or click on button New Do File Editor Tools Execute (do) or crtl+d submits the code line by line to the command prompt; output is shown in the results window; to only submit part of the code, highlight the parts you want to submit Tools Execute quietly (run) executes the code with no output being shown in the results window Break button or crtl+z interrupts computation

p p

Getting Started

Help Files

help contents allows to browse the help les Highly useful for learning the software

p p p

help keyword looks up keyword findit keyword searches online resources findit rc errorcode looks up error code

Outline

Outline

1 Getting Started

2 Basic Commands

3 Further Resources

Basic Commands

Open and Save Data

p p p p p p

clear clears memory set memory 100m allocates 100MB for data cd c:\directory sets active path insheet using filename [, options] imports data from tab-separated text les use filename.dta opens Stata data le save filename.dta [, replace] saves Stata data le

Basic Commands

Handling Variables

p p p p p p

edit opens data editor label variable variablename label adds label to a variable generate newvariable = exp creates a new variable help operator shows a list of operators

replace existingvariable = exp keep if exp, drop if exp . denotes missing value

overwrites an existing variable

Basic Commands

Summary Statistics

p p p p p p p p

Language syntax [by varlist:] command [varlist] [=exp] [if exp] [in range] [weight] [using filename] [, options]

sum variable shows summary statistics sum variable, detail by varlist: sum variable (requires sort varlist ) sum variable if exp

p p p

count counts observations correlate varlist computes a correlation matrix histogram variable plots a histogram line varlist plots a simple line graph scatter varlist plots a simple scatter plot graph matrix varlist generates matrix of scatter plots

Basic Commands

If Expressions

p p p

Examples sum wage if educ >9 sum wage if (educ > 5)&(educ <=9)

p p

Relational operators: <, >, <=, >=, ==, ! = Logical operators: & (and), | (or), ! (not)

Basic Commands

Linear Regression

regress depvar [indepvars] [if] [in] [weight] [, options] Estimates the linear regression model yi = 0 + 1 x1,i + 2 x2,i + ... + k xk,i + ui with ordinary least squares (OLS). Subscript i = 1, ..., N denotes the observations in the sample and ui is the error term. option noconstant estimates a model without constant 0 option robust estimates a model with heteroskedasticity-robust standard errors

p p

Basic Commands

Linear Regression

Goodness of t Total SS (SST, Wooldridge p.38) = N (yi yi )2 1 Model SS (SSE) = N (yi yi )2 1 Residual SS (SSR) = N (ui )2 1 R-squared = SSE/SST = 1- SSR/SST Root Mean Squared Error (Standard Error of the Regression, Wooldridge p. 102)

p p p p p

p p

1 Nk1

N 1 (yi

yi )2 =

1 SSR Nk1

F-test of the null hypothesis 1 = 2 = ... = k = 0 (F statistic for overall signicance of a regression, Wooldridge p. 152) Adjusted R-squared (Wooldridge p. 200)

Basic Commands

Linear Regression

Parameter estimates Estimated parameters: constant term 0 and slope coecients 1 , ..., k Standard errors t-statistics and corresponding p-values 95% condence intervals

p p p p

Basic Commands

Post-Estimation Commands

p p p Computing residuals u p u =y y p predict variablename, residual p Graph with sample regression line p twoway (scatter dependent explanatory) (line
i i i i

Computing predicted values yi 0 + 1 x1,i + ... + k xk,i yi = predict variablename, xb

fittedvalues explanatory)

Basic Commands

Do-File Example

Outline

Outline

1 Getting Started

2 Basic Commands

3 Further Resources

Further Resources

Relevant Resources for This Course

p p p

Tutorials Stata help menu and help command Datasets used by Wooldridge (2009): http://www.msu.edu/ec/faculty/wooldridge/wooldridge.html

Further Resources

Further Resources

p p p p p p p p

Getting Started With Stata, Stata Press. Baum, C.F. (2006): An Introduction to Modern Econometrics Using Stata, Stata Press. Cameron, A.C. and P.K. Trivedi (2009): Microeconometrics Using Stata, Stata Press. Stata reference manuals, in particular Stata Base Reference Manual. Stata Journal and Stata Press. Links to online resources at http://www.stata.com/links/resources1.html Help SJ and User Written Programs oers direct access to user-written programs (ado-les). Archive of ado-les hosted by Department of Economics at Boston College

Introduction to Stata

Econometrics 351-0570-00
March 18, 2010

S-ar putea să vă placă și