Project organisation in Stata Adrian Spoerri and Marcel Zwahlen Department of Social and Preventive Medicine University of Berne, Switzerland Research.

Slides:



Advertisements
Similar presentations
Module Introduction and Getting Started with Stata
Advertisements

Housekeeping: Variable labels, value labels, calculations and recoding
File management GAP Toolkit 5 Training in basic drug abuse data management and analysis Training session 2.
DOS & Windows O/s Prof. Sujata Rao Less 5.
Do files, log files, and workflow in Stata Biostatistics 212 Lecture 2.
The INFILE Statement Reading files into SAS from an outside source: A Very Useful Tool!
Operating System Type of Operating System
Stata and logit recap. Topics Introduction to Stata – Files / directories – Stata syntax – Useful commands / functions Logistic regression analysis with.
Generating new variables and manipulating data with STATA Biostatistics 212 Lecture 3.
I NTRO TO S TATA James Ng Center for Digital Scholarship Hesburgh Libraries.
File Management and Storage Devices. Floppy Disk Drive ► A floppy drive (normally designated as the "A" drive). ► A floppy drive (normally designated.
Computing for Research I Spring 2011 Primary Instructor: Elizabeth Garrett-Mayer Stata Programming February 28.
Computing for Research I Spring 2013 Primary Instructor: Elizabeth Garrett-Mayer Stata Programming February 21.
1 NewSouth HR Reporting Running the Mailing Labels Report.
Activity One Use the Windows Explorer program to create a new folder. Name the folder by your first name. Click on the windows explorer icon then highlight.
Stata Introduction Sociology 229A, Class 2 Copyright © 2008 by Evan Schofer Do not copy or distribute without permission.
Getting Started with your data
SPSS Statistical Package for the Social Sciences is a statistical analysis and data management software package. SPSS can take data from almost any type.
Command Prompt Chapter 7 Using ATTRIB, SUBST, XCOPY, DOSKEY, and the MS-DOS Text Editor Richard Goldman ©January 31, 2000.
STATA User Group September 2007 Shuk-Li Man and Hannah Evans.
MATLAB File Management. MATLAB User File Management Matlab provides a group of commands to manage user files. For more information, type help iofun. pwd.
Stata Workshop #1 Chiu-Hsieh (Paul) Hsu Associate Professor College of Public Health
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.
®® Microsoft Windows 7 for Power Users Tutorial 13 Using the Command-Line Environment.
A Brief Introduction to Stata(1). 1. Getting Started.
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.
Introduction to Engineering MATLAB – 6 Script Files - 1 Agenda Script files.
File Management Presented to The Glades Computer Club January 4, 2001.
Organizing a project, making a table Biostatistics 212 Lecture 7.
Organizing a project, making a table Biostatistics 212 Session 5.
Example SPSS Basic Medical Statistics Course October 2010 Wilma Heemsbergen.
Generating new variables and manipulating data with STATA Biostatistics 212 Lecture 3.
Page 1 Non-Payroll Cost Transfer Enhancements Last update January 24, 2008 What are the some of the new enhancements of the Non-Payroll Cost Transfer?
Getting Started With Stata Session 1 Jim Anthony John Troost Department of Epidemiology Michigan State University.
1 EPIB 698E Lecture 1 Notes Instructor: Raul Cruz 7/9/13.
Slide No. 1 Slide No. 1 HTML and Web Publishing Continued CS 104 CS 104.
Chapter 1 – Matlab Overview EGR1302. Desktop Command window Current Directory window Command History window Tabs to toggle between Current Directory &
1 Getting Started with C++. 2 Objective You will be able to create, compile, and run a very simple C++ program on Windows, using Visual Studio 2008.
1 PL\SQL Dev Templates. 2 TEMPLATE DEFINITION Whenever you create a new program unit, its initial contents are based upon a template which contains pre-defined.
Basics of Biostatistics for Health Research Session 1 – February 7 th, 2013 Dr. Scott Patten, Professor of Epidemiology Department of Community Health.
Comparison of different output options from Stata
How to Setup and Score a Tournament May Let’s Get Organized The setup and organization outlined in this clinic are suggested steps however can be.
MySQL Getting Started BCIS 3680 Enterprise Programming.
Today Introduction to Stata – Files / directories – Stata syntax – Useful commands / functions Logistic regression analysis with Stata – Estimation – GOF.
1 Getting Started with C++ Part 1 Windows. 2 Objective You will be able to create, compile, and run a very simple C++ program on Windows, using Microsoft.
ENG College of Engineering Engineering Education Innovation Center 1 Functions 1 in MATLAB Topics Covered: 1.Uses of Functions Organizational Tool.
Topics Introduction to Stata – Files / directories – Stata syntax – Useful commands / functions Logistic regression analysis with Stata – Estimation –
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)?”
COMM 3050 – Online Project Update. Project Roles  Organizer Responsible for creating Zoom account technical aspects and posting recorded meeting to S:
MySQL Getting Started BCIS 3680 Enterprise Programming.
Topics Introduction to Stata – Files / directories – Stata syntax – Useful commands / functions Logistic regression analysis with Stata – Estimation –
Using a set-up file to read ASCII data into Stata
Command Line Basics.
A Short DOS Presentation
Using a set-up file to read ASCII data into SPSS
QS101 – Introduction to Quantitative Methods in Social Science Week 2: Introduction to Stata and Preparation of Field Work Florian Reiche Teaching Fellow.
GNS 312 (DIGITAL SKILL ACQUISITION)
Econometrics 704 Emilio Cuilty
ECONOMETRICS ii – spring 2018
Instructor: Raul Cruz-Cano
STATA User Group September 2007
Stata Basic Course Lab 4.
CSCI N317 Computation for Scientific Applications Unit 1 – 1 MATLAB
Stata Basic Course Lab 2.
Scripts In Matlab.
Instructor: Raul Cruz 9/4/13
Instructions for Data Base
Evaluation of Public Policy
Presentation transcript:

Project organisation in Stata Adrian Spoerri and Marcel Zwahlen Department of Social and Preventive Medicine University of Berne, Switzerland Research seminar, 15th January 2007

Project organisation in Stata Organisation of Stata-folders Do-files –profile.do –00_run_first.do Global macros Do-file templates Redirection of output

Stata folders System folders often: c:/stata9 or c:/programme/stata9 updates and adofiles: c:/stata9/ado => never save anything in these folders yourself! other system folders: see sysdir (updates, ado-files)

Project folders e.g.d:/projects/bag/std/stata.. or d:/data/snc/stata.. good practice to seperate programs and data

General folders general Stata folder: e.g. d:/projects/stata (for copy of profile.do, lic file) d:/projects/temp

Jumping around directories Most common commands –cd or pwd: shows current path –dir: lists files and folders in current path –cd: changes directory, eg. cd stata/do

Hint Forward or back slash? Windows systems: \ Mac: / and Stata? –both are possible –in do-files: always use: /

Pathways absoulte path: c:/seminar070115/stata/data relative path –relative to what? check pwd or cd –change directory to project, e.g. cd c:/seminar –then use relative path: cd stata/data

Is there a third way? Use shortcuts! Why? –define path to project only once –valid for all do-files of same project –makes collaboration of several persons on the same project easy –compatible with ISPM standard

Project folders c:/seminar /origdata /stata /data /do /graphres /orig /log /textres non-Stata files, e.g. mdb, dbf, xls, txt

Project folders c:/newproject /origdata /stata /data /do /graphres /orig /log /textres

Do-files most simple: list of Stata commands a bit more sophisticated: complex files with loops, programs and subroutine-calls „Basic do-file“: c:/stata9/profile.do => general settings runs each time Stata is starting

Profile.do set scrollbufsize /* enlarge results window buffer */ set memory 100M/* sets memory to 100 megabyte */ set varlabelpos 20/* sets position of label in variable window */ * hard drive in use global dr="d"

Macros global macro: –is a substitute valid during the whole stata session –global dd = "gender" –regress bp $dd –regress bp gender local macro: different syntax

Macros (2) local macro: –is a substitute valid within a do-file –local thismacro = "gender" –regress bp `thismacro‘ –regress bp gender mind the quotes: –leading left single quote and trailing right single quote

Profile.do (2) set scrollbufsize /* enlarge results window buffer */ set memory 100M/* sets memory to 100 megabyte */ set varlabelpos 20/* sets position of label in variable window */ * hard drive in use global dr = "c" *or *global dr = "d"

00_run_first.do first do-file in each project sets project-specific directories start it with double click in the explorer or start it using a shortcut (a global macro again)

qui{ *define name of project global np="Testproject for research seminar" *define path to new project, here without drive letter global pp="/seminar070115" *general project path settings global dd="$dr:$pp/stata/data" global dod="$dr:$pp/stata/do" global gd="$dr:$pp/stata/graphres" global ld="$dr:$pp/stata/log" global od="$dr:$pp/stata/orig" global td="$dr:$pp/stata/textres" } display "settings ready for: $np" cd $dr:$pp/stata 00_run_first.do (2)

global dd="$dr:$pp/stata/data" global dd="d:$pp/stata/data" global dd="d:/seminar070115/stata/data" in analysis: use $dd/example_1.dta 00_run_first.do (3)

qui{ *define name of project global np="Testproject for research seminar" *define path to new project, here without drive letter global pp="/seminar070115" *general project path settings global dd="$dr:$pp/stata/data" global dod="$dr:$pp/stata/do" global gd="$dr:$pp/stata/graphres" global ld="$dr:$pp/stata/log" global od="$dr:$pp/stata/orig" global td="$dr:$pp/stata/textres" } display "settings ready for: $np" cd $dr:$pp/stata 00_run_first.do (4)

How to start new project 1.Prepare Stata subdirecories (e.g. data, do, etc) 2.adapt 00_run_first.do for new project (define name, define project path) 3.execute 00_run_first.do 4.open template do-file, start writing commands in do-file => preparation of new project: <5 minutes

do-file template capture log close global logfile="$ld/cr_name_01.log" log using "$logfile",replace /* - template of do-file - describe here the main purpose of the do-file authors:a.spoerri / m.zwahlen date: */ use $od/dataset.dta, clear *further commands save $dd/dataset_prep.dta, replace log close exit

Example of do-file capture log close global logfile="$ld/cr_exp_01.log" log using "$logfile",replace /* example of do-file using global macros authors:a.spoerri / m.zwahlen date: */ clear

Example of do-file (2) *load data use $od/example_1.dta, clear *generate variable gen index=(sex==1 & agegrp==50) tab agegrp index *save new file save $dd/example_2, replace log close exit

Master do-file generally: seperate do-files where you create a new dataset (cr's) and do-files, which just analyse an existing dataset (an's) for each project create a master do-file e.g. master_seminar do: do "$dod/cr_sem01.do" /* creates cleaned data file*/ do "$dod/an_sem01.do"/* descriptive analyses */

Redirecting Stata to Word create a text file with your results in Stata link this file to a Word document update text file (e.g. if data change) update Word doc

Profile.do tr_on * redirect part of the output to textres capture program drop tr_on program define tr_on version 8 set logtype text set linesize 120 quietly capture log close local name="$td"+"/"+"`1'"+".txt" quietly capture log using "`name'", replace end

Profile.do tr_off * cancel redirection capture program drop tr_off program define tr_off version 8 quietly capture log close quietly capture log using "$logfile", append set linesize 175 end

Example of an_seminar_01.do *description of diagnoses forvalues z= 0/1 { use "$dd/example_2.dta", clear keep if sex==`z' tr_on example_demogr_`z' tab age educ, row tr_off }

Update Stata output in Word useful for technical reports output looks like Stata result output is logged in folder.../textres create link in Word file: INCLUDETEXT "C:\\seminar070115\\Stata\\textres\\example_demogr _0.txt" \c AnsiText

Organisation of do-files cr‘s: e.g. cr_sem01.do: do-file, where *.dta are created, normally after different data management steps includes: generating and dropping of vars, labeling, grouping... saves processed data file, ready for analyses

Organisation of do-files (2) an‘s: e.g. an_sem01.do: do-file, where analyses are performed attention: in an-do-files datasets are never changed! exception: temporary changes

Stata on the intranet Shortly, the following files will be available: –ppt of our presentation –template of profile.do –template of standard do-file –template of 00_run_first.do –standard folder structure for new projects