Computing for Research I Spring 2011 Primary Instructor: Elizabeth Garrett-Mayer Stata Programming February 28.

Slides:



Advertisements
Similar presentations
XP New Perspectives on Introducing Microsoft Office 2003 Tutorial 1 1 Using Common Features of Microsoft Office 2003 Tutorial 1.
Advertisements

ITEC 1001 Tutorial 1 Using Common Features of Microsoft Office 2003.
1. Overview Basic commands for writing do-files
Apr-15H.S.1 Stata: Linear Regression Stata 3, linear regression Hein Stigum Presentation, data and programs at: courses.
Intermediate Code Generation
Statistical Methods Lynne Stokes Department of Statistical Science Lecture 7: Introduction to SAS Programming Language.
Computing for Research I Spring 2013 Primary Instructor: Elizabeth Garrett-Mayer Regression Using Stata February 19.
Stata and logit recap. Topics Introduction to Stata – Files / directories – Stata syntax – Useful commands / functions Logistic regression analysis with.
Introduction to the gedit editor. gedit: the Gnome editor Gnome: Gnome is a freely available (i.e., no cost) desktop environment for the UNIX system The.
 Statistics package  Graphics package  Programming language  Can be used to share/reproduce analyses  Many new packages being created - can be downloaded.
Information & Library Services Australian Education Index, British Education Index and ERIC Sally Giffen August 2006.
Taking the pain out of looping and storing Patrick Royston Nordic and Baltic Stata Users’ meeting, Stockholm, 11 November 2011.
Computing for Research I Spring 2013 Primary Instructor: Elizabeth Garrett-Mayer Stata Programming February 21.
By Hrishikesh Gadre Session II Department of Mechanical Engineering Louisiana State University Engineering Equation Solver Tutorials.
Stata Introduction Sociology 229A, Class 2 Copyright © 2008 by Evan Schofer Do not copy or distribute without permission.
XP 1 Using Common Features of Microsoft Office 2003 Rod Rodrigues.
Introduction to MATLAB MECH 300H Spring Starting of MATLAB.
XP Using Common Features of Microsoft Office Tutorial 1.
Introduction to SPSS Short Courses Last created (Feb, 2008) Kentaka Aruga.
Other Features Index and table of contents Macros and VBA.
EPSII 59:006 Spring Topics Using TextPad If Statements Relational Operators Nested If Statements Else and Elseif Clauses Logical Functions For Loops.
STATA User Group September 2007 Shuk-Li Man and Hannah Evans.
L1: INTRODUCTION Getting started with Stata Angela Ambroz May 2015.
Econometric Analysis Using Stata
Stata Workshop #1 Chiu-Hsieh (Paul) Hsu Associate Professor College of Public Health
TERMS TO KNOW. Desktop This does not mean a computer desktop vs. a laptop. You probably keep a number of commonly used items on your desk at home such.
Project organisation in Stata Adrian Spoerri and Marcel Zwahlen Department of Social and Preventive Medicine University of Berne, Switzerland Research.
XP New Perspectives on Browser and Basics Tutorial 1 1 Browser and Basics Tutorial 1.
Objectives Understand what MATLAB is and why it is widely used in engineering and science Start the MATLAB program and solve simple problems in the command.
Scottish Social Survey Network: Master Class 1 Data Analysis with Stata Dr Vernon Gayle and Dr Paul Lambert 23 rd January 2008, University of Stirling.
1 CSC 221: Introduction to Programming Fall 2012 Functions & Modules  standard modules: math, random  Python documentation, help  user-defined functions,
API-208: Stata Review Session Daniel Yew Mao Lim Harvard University Spring 2013.
Key Data Management Tasks in Stata
Tricks in Stata Anke Huss Generating „automatic“ tables in a do-file.
STATA Mini Course Fall 2015 Jane Leber Herr Littauer 113 1Stata Mini Course – Spring 2015.
L3: BIG STATA CONCEPTS Getting started with Stata Angela Ambroz May 2015.
Microsoft Word ITE115 Trisha Cummings. MsWord - Word Processing Program Allows you to create Letters, Envelopes, Mailing Labels, Memo’s , Fax’s.
CSC 3210 Computer Organization and Programming Chapter 1 THE COMPUTER D.M. Rasanjalee Himali.
MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright.
Regression. Population Covariance and Correlation.
Advanced Stata Workshop FHSS Research Support Center.
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
Microsoft Office XP Illustrated Introductory, Enhanced Started with Windows 2000 Getting.
Introduction to SAS Macros Center for Statistical Consulting Short Course April 15, 2004.
Multiple regression. Example: Brain and body size predictive of intelligence? Sample of n = 38 college students Response (Y): intelligence based on the.
I Power Higher Computing Software Development Development Languages and Environments.
March 23 & 28, Csci 2111: Data and File Structures Week 10, Lectures 1 & 2 Hashing.
March 23 & 28, Hashing. 2 What is Hashing? A Hash function is a function h(K) which transforms a key K into an address. Hashing is like indexing.
Getting Started with Stata 2/11/2010 Tom Tomberlin Nealia Khan Learning Technologies Center Harvard Graduate School of Education.
Dec-15H.S.1 Stata 8, Programing Hein Stigum Presentation, data and programs at:
Comparison of different output options from Stata
Excel 2007 Part (3) Dr. Susan Al Naqshbandi
1 Econometrics (NA1031) Lecture 1 Introduction. 2 ”How much” type questions oBy how much a unit change in income affects consumption? oBy how much should.
Today Introduction to Stata – Files / directories – Stata syntax – Useful commands / functions Logistic regression analysis with Stata – Estimation – GOF.
5-1 MGMG 522 : Session #5 Multicollinearity (Ch. 8)
CS190/295 Programming in Python for Life Sciences: Lecture 6 Instructor: Xiaohui Xie University of California, Irvine.
Stata Review Session Economics 1018 Abby Williamson and Hongyi Li November 17, 2006.
Topics Introduction to Stata – Files / directories – Stata syntax – Useful commands / functions Logistic regression analysis with Stata – Estimation –
Dr. Abdullah Almutairi Spring PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used,
Stata – be the master Stata. “After I have run my standard commands, what can I do to make my model better (and understand better what is going on)?”
Additional Regression techniques Scott Harris October 2009.
Topics Introduction to Stata – Files / directories – Stata syntax – Useful commands / functions Logistic regression analysis with Stata – Estimation –
Econ 326 Prof. Mariana Carrera Lab Session X [DATE]
Release Numbers MATLAB is updated regularly
Econometrics 704 Emilio Cuilty
ECONOMETRICS ii – spring 2018
Migration and the Labour Market
CSCI N317 Computation for Scientific Applications Unit 1 – 1 MATLAB
Stata Basic Course Lab 2.
Ordinary Least Square estimator using STATA
Presentation transcript:

Computing for Research I Spring 2011 Primary Instructor: Elizabeth Garrett-Mayer Stata Programming February 28

Some simple programming Once again, princeton’s site has some great easy info: We will discuss a few things: – ‘macros’ – looping – writing commands We will not discuss ‘mata’: powerful matrix programming language

macros macro = a name associated with some text. macros can be local or global in scope. Example of use: shorthand for repeated phrase – graphics title – set of ‘adjustment’ covariates syntax: local name content

Example: covariates * use SCBC data use "I:\Classes\StatComputingI\SCBC2004.dta", clear * make tumor numeric and transform gen sizen=real(tumor) gen logsize = log(sizen) replace logsize =. if sizen==999 regress logsize age black graden *define local macro local adjusters age black graden regress logsize `adjusters' regress logsize `adjusters' i.ercat regress logsize `adjusters' i.prcat regress logsize `adjusters' i.ercat i.prcat NOTE: must use accent (`) in upper left of keyboard as beginning quote and apostrophe (‘) (next to enter key) for end quote.

More examples local erprknown ercat<9 & prcat<9 regress logsize `adjusters' i.ercat i.prcat if `erprknown'

Example: titles * another example infile str14 country setting effort change /// using clear graph twoway (lfitci change setting) /// (scatter change setting) ///, title("Fertility Decline by Social Setting") /// ytitle("Fertility Decline") /// legend(ring(0) pos(5) order(2 "linear fit" 1 "95% CI")) local gtitles title("Fertility Decline by Social Setting") ytitle("Fertility Decline") * with macro graph twoway (lfitci change setting) /// (scatter change setting) ///, `gtitles' legend(ring(0) pos(5) order(2 "linear fit" 1 "95% CI")) * without macro graph twoway (lfitci change setting) /// (scatter change setting) ///, legend(ring(0) pos(5) order(2 "linear fit" 1 "95% CI"))

Storing results Stata commands (and new commands that you and others write) can be classified as follows: – r-class: General commands such as summarize. Results are returned in r() and generally must be used before executing more commands. – e-class: Estimation commands such as regress, logistic etc., that fit statistical models. Results are returned in e() and remain there until the next model is estimated.

(continued) – s-class: Programming commands that assist in parsing. These commands are relatively rare. Results are returned in s(). – n-class: Commands that do not save results at all, such as generate and replace. – c-class: Values of system parameters and settings and certain constants, such as the value of π, which are contained in c().

Accessing returned values return list, ereturn list, sreturn list and creturn list return all the values contained in the r(), e(), s() and c() vectors, respectively. For example, after using summarize, r() will contain r(N), r(mean), r(sd), r(sum) etc. Elements of each of the vectors can be used when creating new variables. They can also be saved as macros.

Using regression results Although coefficients and standard errors from the most recent model are saved in e(), it is quicker to refer to them by using _b[ varname ] and _se[ varname ], respectively. regress change setting effort gen fitvals = setting*_b[setting] + effort*_b[effort] + _cons*_b[_cons] predict fit

Storing results * run regression and store r-squared value regress change setting local rsq = e(r2) display rsq * run new regression regress change setting effort display e(r2) see old saved r-squared display rsq * still there!

Global macros Global macros have names of up to 32 characters and, as the name indicates, have global scope. You define a global macro using global name [=] text and evaluate it using $name. (You may need to use ${name} to clarify where the name ends.) “I suggest you avoid global macros because of the potential for name conflicts.” A useful application, however, is to map the function keys on your keyboard. If you work on a shared network folder with a long name try something like this

More on macros Macros can also be used to obtain and store information about the system or the variables in your dataset using extended macro functions. For example you can retrieve variable and value labels, a feature that can come handy in programming. There are also commands to manage your collection of macros, including macro list and macro drop. Type help macro to learn more.

Looping foreach: loops over a set of variables forvalues: loops over a set of values (index) Also: – while loops – if and else sets of commands

Programming ‘ado’ files create commands in ado file and put them in the appropriate directory for Stata to find Can also create them in do files for local use See – – –

Ado files An ado-file (“automatic do-file”) is a do-file that defines a Stata command. It has the file extension.ado. Not all Stata commands are defined by ado-files: some are built-in commands. The difference between a do-file and an ado-file is that when the name of the latter is typed as a Stata command, Stata will search for and run that file. For example, the program mysum could be saved in mysum.ado and used in future sessions

Ado files Ado-files often have help (.hlp) files associated with them. There are three main sources of ado-files: – Official updates from StataCorp. – User-written additions (e.g. from the Stata Journal). – Ado-files that you have written yourself. Stata stores these in different locations, which can be reviewed by typing sysdir.

Ado files Official updates are saved in the folder associated with UPDATES. User-written additions are saved in the folder associated with PLUS. Ado-files written by yourself should be saved in the folder associated with PERSONAL. If you have an Internet connection, official updates and user-written ado-files can be installed easily. To install official updates, type: update from