; stata
Learning Center
Plans & pricing Sign in
Sign Out
Your Federal Quarterly Tax Payments are due April 15th Get Help Now >>



  • pg 1
									    Introduction to Stata
       Paul von Hippel, Ph.D.
      Department of Sociology
       Ohio State University

with thanks to Stacy Woodard, Ph.D.
       Center for Biostatistics
        Ohio State University
                  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
        Logging in to the SIL
• Turn on computer
• Enter your user name
  – If your OSU email is buendia.100@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
     Opening Stata (in the SIL)
• Lower left corner, click Start
• Choose
  – All programs
  – Analysis
  – Stata 9
            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‖
        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
   – in Stata format
Review window:                          Results window:
Past commands.                          Output and past commands
Click to paste in Command window

  Variables window:
                                        Command window:
  List of variables in open data set.
                                        Current command
  Click to paste in Command window.
                 Importing data
• 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….
   – 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 ―clear‖
        —gets current data out of memory
      • Choose FileImportASCII data created by a spreadsheet
          – Find X:\example1.txt
                    Examining data

                             selected   Hide   Delete
   Undo changes Sort by       column selected selected
                            to the end column columns         Close
  since last ―save‖selected                                   editor
―Save‖                                        or rows
• Move
  – smoke
  – and bwt
• to the first two columns
• Save your changes
• Close the editor
                     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‖
               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?‖
                           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
           Creating a new variable
• According to the National Institutes of Health,
  – low birth weight (LBW)
     • < 2500 grams (5.5 pounds)
• Let’s create a dummy variable for LBW
• Data
  Create or change variable
  Create a new variable
• Create dummy variables for
  – very low birth weight (VLBW)
     • <2000 grams (4.4 pounds)
  – extremely low birth weight (ELBW)
     • <1500 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
               Analyzing data
• Are smokers more likely to have LBW babies?
• Statistics
  Summaries, tables, and tests
  Two-way tables
             Analyzing data
• Are smokers’ babies lighter, on average?
• StatisticsSummaries…
  Summary statistics
  Summary statistics
             Formatting output
• In Stata
  – Highlight results
  – EditCopy table
• Open Excel
  – EditPaste
  – Tidy things up
  – Later move to Word processor
              Leaving Stata
• FileExit
               Resuming Stata
• Launch Stata:
• Old commands are in the do-file. To see it,

   – In do-file editor
      • FileOpen
      • Find X:\intro.do
                   Running a Do-file
• To run your old commands,
  – FileDo…
  – Find ―X:\intro.do‖
• It probably won’t run all the way through.
• Some commands don’t 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
• Edit the do-file until it runs all the way
• This will also familiarize you with the typed
  versions of some commands.
                  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
   –   User’s Guide
   –   Reference Manuals (several volumes)
   –   Stata Graphics Manual
• www.stata.com

To top