Introduction to Stata - PowerPoint PPT Presentation

1 / 24
About This Presentation
Title:

Introduction to Stata

Description:

Stata can also read tab-delimited ASCII text files. Most other software (e.g., Excel) can write tab-delimited ASCII text files. Let's get data from Excel... – PowerPoint PPT presentation

Number of Views:3007
Avg rating:3.0/5.0
Slides: 25
Provided by: vonhi
Category:

less

Transcript and Presenter's Notes

Title: Introduction to Stata


1
Introduction to Stata
Paul von Hippel, Ph.D. Statistician Department of
Sociology Ohio State University
  • with thanks to Stacy Woodard, Ph.D.
  • Center for Biostatistics
  • Ohio State University

2
Where you are
  • Sociology Instruction Lab (SIL), 70 Derby Hall
  • used for computer courses
  • not the Sociology Research Lab (SRL), in Bricker
  • used for computer research

3
Logging in to the SIL
  • Turn on computer
  • Enter your user name
  • If your OSU email is buendia.100_at_osu.edu
  • then your SIL user name is buendia.100
  • not the same as in SRL
  • Enter your password
  • your first initial last 4 digits of your SS
    your last initial
  • e.g., Jose Arcadio Buendia, SS 100-10-0100
  • password j0100b
  • again not the same as in SRL

4
Opening Stata (in the SIL)
  • Lower left corner, click Start
  • Choose
  • All programs
  • Analysis
  • Stata 9

5
Logging commands
  • Save your commands to a file
  • You may want to re-use them later!
  • (Press return)
  • called a command log
  • or Do-file

6
Opening Stata data files
  • Stata has its own format for data files
  • extension .dta
  • Choose File?Open
  • Go to S\stata_intro\nmihs100.dta
  • S in the SIL is not the same as S in the SRL
  • 100 records from
  • National Maternal and Infant Health Survey
    (NMIHS)
  • in Stata format

7
Results window Output and past commands
Review window Past commands. Click to paste in
Command window
Variables window List of variables in open data
set. Click to paste in Command window.
Command window Current command
8
Importing data
  • Stata can also read tab-delimited ASCII text
    files
  • Most other software (e.g., Excel)can write
    tab-delimited ASCII text files
  • Lets get data from Excel.
  • From Windows Start button
  • choose All Programs?Office Productivity?Microsoft
    Office?Excel
  • In Excel
  • choose File?Open
  • find S\stata_intro\example1.xls
  • choose File?Save As?Save as type Text (tab
    delimited)
  • Save as X\example1.txt
  • In Stata
  • In command window, type cleargets current
    data out of memory
  • Choose File?Import?ASCII data created by a
    spreadsheet
  • Find X\example1.txt

9
Examining data
Moveselected column to the end
Hide selected column
Deleteselectedcolumns or rows
Undo changes since last save
Close editor
Sort by selected column
Save
Change selected value
10
Exercise
  • Move
  • smoke
  • and bwt
  • to the first two columns
  • Save your changes
  • Close the editor

11
Saving data
  • Preserve saves only a temporary copy of the
    data file.
  • The original data file is unaffected.
  • To save a permanent data file,
  • Choose File?Save As
  • Navigate to your X drive
  • X is where you should save things
  • X in the SIL is not the same as X in the SRL
  • Save as my_example1.dta

12
Labeling variables
  • To add a descriptive label to a variable
  • Data?Labels?Label variable
  • Add these labels to these variables
  • bwt Birth weight, in grams
  • smoke Did mother smoke during pregnancy?

13
Labeling values
  • Many variables are dummy variables
  • two values 0 and 1
  • e.g., Did the mother smoke? Yes (1) or no (0).
  • To add labels to dummy values
  • Data?Labels?Label Values?Define or Modify Value
    Labels
  • Define label name dummy
  • Add values
  • 1 means yes
  • 0 means no
  • Now tell Stata that smoke is a dummy variable
  • Data?Labels?Label Values?Assign value label to
    variable
  • Look at smoke in the Data Editor
  • and double-click it

14
Creating a new variable
  • According to the National Institutes of Health,
  • low birth weight (LBW)
  • lt 2500 grams (5.5 pounds)
  • Lets create a dummy variable for LBW
  • Data?Create or change variable?Create a new
    variable

15
Exercise
  • Create dummy variables for
  • very low birth weight (VLBW)
  • lt2000 grams (4.4 pounds)
  • extremely low birth weight (ELBW)
  • lt1500 grams (3.3 pounds)
  • Look at the new variables in the Data Editor
  • Give the new variables appropriate labels
  • e.g., LBW Did the baby have low birth weight?
  • NB. Stata is case-sensitive
  • ELBW is not the same as elbw

16
Analyzing data
  • Are smokers more likely to have LBW babies?
  • Statistics?Summaries, tables, and
    tests?Tables?Two-way tables

17
Analyzing data
  • Are smokers babies lighter, on average?
  • Statistics?Summaries?Summary statistics?Summary
    statistics

18
(No Transcript)
19
Formatting output
  • In Stata
  • Highlight results
  • Edit?Copy table
  • Open Excel
  • Edit?Paste
  • Tidy things up
  • Later move to Word processor

20
Leaving Stata
  • File?Exit

21
Resuming Stata
  • Launch Stata
  • Old commands are in the do-file. To see it,
  • In do-file editor
  • File?Open
  • Find X\intro.do

22
Running a Do-file
  • To run your old commands,
  • File?Do
  • Find X\intro.do
  • It probably wont run all the way through.
  • Some commands dont make sense any more
  • e.g., creating a file or variable that already
    exists
  • Other commands may pause and wait for action from
    you
  • e.g., edit waits for you to close the Data
    Editor

23
Exercise
  • Edit the do-file until it runs all the way
    through
  • This will also familiarize you with the typed
    versions of some commands.

24
To learn more
  • http//www.princeton.edu/erp/stata/main.html
  • Help menu (or help command)
  • e.g., in Command window type help cmdlog
  • Tutorial command
  • tutorial ttest
  • tutorial graphics
  • Manuals (in SRL)
  • Getting Started
  • Users Guide
  • Reference Manuals (several volumes)
  • Stata Graphics Manual
  • www.stata.com
Write a Comment
User Comments (0)
About PowerShow.com